I am currently working on a solution for streaming huge files from EMC Documentum and to the client through Jersey. The API for Documentum allows either to get the file as a ByteArrayInputStream or to save it down to a disk area. Using the ByteArrayInputStream is out of question as it stores the whole file in memory, which is not acceptable for 20 gigabyte files.
Therefore the only solution is to save the file to a disk area (use of internal classes and functions is also out of question). In order to make it faster I want to let Documentum to write the data to a file and at the same time read data from this file and stream it to the client through Jersey (by returning an InputStream in Jersey).
The problem is that if the reading thread is faster than the writing thread it will reach the end of the stream and get -1 back, meaning there is no more data in the stream. When this happens Jersey will probably stop streaming the file as it thinks it is done.
Are there any best practices or libraries for this kind of problem? I have been looking on the internet and have some workarounds in mind, but it feels like this should be a common problem and there maybe already exists a solution in the Jersey API which I missed or some other library. Does there exist a class in Jersey which you can return and explicitly set when the end of the stream is reached?