Reputation: 6649
I need to pass an InputStream to an object which reads data which I previously stored into a File. I'm assessing a more efficient approach than storing eveything into a File and then passing the FileInputStream. I'd like to do it on the fly.
May someone appoint me the correct approach to do that?
The idea would be passing a Custom InputStream which innerly calls every line I was going to store in the file. I guess I need buffering. I discard storing everything in a String and then build an InputStream on it, as we are in the same situation, waiting to output all the lines before rereading them again.
Upvotes: 1
Views: 1416
Reputation: 73568
There already is a stream for this. It's the PipedInputStream. You'll need to have one thread write to the PipedOutputStream
, and pass the PipedInputStream
to the object that will be reading in another thread.
Upvotes: 2