How can I open a PDF that I'm streaming over the network?

Q:

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];
int n;
while ((n = is.read(buffer)) > 0)
{

}

A:

You should be able to subclass InputStream, using the code you quoted above as a starting point:
http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html

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:
https://www.pdftron.com/pdfnet/docs/PDFNetJava/pdftron/PDF/PDFDoc.html#PDFDoc(java.io.InputStream)