This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

OutputStream -> InputStream

 
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
 
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
 
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();
 
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
 
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
 
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.
 
Sheriff
Posts: 22024
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic