Win a copy of Murach's Python Programming this week in the Jython/Python forum!
    Bookmark Topic Watch Topic
  • New Topic

OutputStream -> InputStream  RSS feed

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Report post to moderator
Untested code:

[ January 04, 2002: Message edited by: David Weitzman ]
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Laudney Ren
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Report post to moderator
HaHa, the problem is a little tricky, change the last few lines into the following:

Shape myshape = convert(pin); // Accepts JPEG InputStream
pout.flush();
pin.close();
pout.close();
 
smayur smayur
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

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..

Thanks in advance
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Report post to moderator
I recently wrote an article that explains how to convert an outputstream to an inputstream using any one of three methods: byte arrays, piped streams, or circular buffers.

http://ostermiller.org/convert_java_outputstream_inputstream.html
 
Davide Simonetti
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi!
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...



Davide.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thank you for sharing this, but haven't you noticed this thread was over 3 years old? http://faq.javaranch.com/java/DontWakeTheZombies
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!