1

I'm using an API (Jasper Reports) to generate PDFs and I'd like to do most of it in memory. I'm already able to get the generated file as an OutputStream, now I'm just looking for an implementor to use to keep things in memory which implements InputStream as well.

What class can I use which functions as both an OutputStream and an InputStream on in-memory data?

Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
  • 2
    Similar to this question, resolved with `PipedInputStream`: http://stackoverflow.com/questions/1225909/most-efficient-way-to-create-inputstream-from-outputstream – Michael Brewer-Davis Dec 20 '11 at 20:11

2 Answers2

10

ByteArrayInputStream and ByteArrayOutputStream to the rescue.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
0

This Passage would be suitable more here, focusing on the dual implementation on both of Input and Output.

http://blog.ostermiller.org/convert-a-java-writer-to-a-reader/

As metioned in the article, the PipedReader and PipedWriter would be a awesome solution, and the Circular Buffer provided from Ostermiller.util as well if you are allowed to import another dependency.

千木郷
  • 1,595
  • 2
  • 19
  • 30