We are trying to stream files from FTP to a PDFDoc. Is there any way to directly get the file buffer data into PDFDoc object without creating any file on local file system, and without putting the entire document into a memory buffer? Here’s our code:
InputStream is = ftp.retrieveFileStream(remote_file);
byte buffer = new byte[nBufferSize];
while ((n = is.read(buffer)) > 0)
You should be able to subclass InputStream, using the code you quoted above as a starting point:
Simply implement the InputStream methods (i.e., InputStream.read). You would need to populate your byte buffer from the network (as in your code sample, using is.read) when the buffer is empty. Then return the requested bytes to the InputStream’s consumer (i.e., the code that called InputStream.read), keeping track of where you are in the buffer. When no more bytes are available, repopulate the buffer from the network.
You can then instantiate a PDFDoc from the InputStream: