I want to pass an OutputStream to an InputStream in memory without creating a file on the hard disk. Can anyone provide a code snippet that shows how to do this? Let me know if I need to provide more details. Thanks! Drew
[ January 04, 2002: Message edited by: David Weitzman ]
posted 18 years ago
Thanks for the reply. It appears that the PipedOutputStream is what I need to use. However, let me be a little more specific about what I am tring to accomplish. I want to pass the output stream of the Sun Jpeg encoder to a method which accepts a JPEG InputStream. Unfortunately, I can't seem to get this to work. Here's what I'm thinking: PipedInputStream pin = new PipedInputStream(); PipedOutputStream pout = new PipedOutputStream(pin); JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(pout); JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(myBufferedImage); param.setQuality(0.6F, true); encoder.encode(myBufferedImage, param); pout.close(); Shape myshape = convert(pin); // Accepts JPEG InputStream pin.close(); Unfortunately, this doesn't seem to work. Although I don't get any errors. Any suggestions? Thanks! Drew
I am trying to convert Outputstream to InputStream I have PDF file data in outputstream, now need to send the same pdf as an mail attachment without creating File object... Can anyone tell me how to do it..
I recently developed a set of utilities to ease the use of PipedInputStream and PipedOutputStream. Data must be written and read in two different threads or you will cause a lock.
The previous article at ostermiller.org give you a good overview of the problem. If you still prefer pipes over other techniques you can have a look here: http://io-tools.googlecode.com Here is how the previous code will be...