aspose file tools*
The moose likes I/O and Streams and the fly likes How to read closed inputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to read closed inputStream" Watch "How to read closed inputStream" New topic
Author

How to read closed inputStream

Rohit Kumar
Ranch Hand

Joined: Sep 20, 2007
Posts: 53
How to read closed inputStream?

I just want to see the content of the input stream before the input stream processes, so even if any way to write the input stream to file before sent for process it.

Thanks
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Originally posted by Rohit Kumar:
How to read closed inputStream?

I just want to see the content of the input stream before the input stream processes, so even if any way to write the input stream to file before sent for process it.

Thanks


I think the description of your problem actually contradicts the subject.
You basically want to read the input stream twice and not read a closed input stream. There is a subtle difference between both of them. You can not never read a closed input stream but you can give a picture that the stream can be read twice! Following are not full proof solutions but may work: (All assume that you can change the instance of the input stream i.e. you change the instance and make the reader use the new instance rather the old one.)

- Wrap your inputstream with a PushbackInputStream, read the stream completely and then unread(i.e. push it back.). The problem here is that once you unread, you can not continue reading from where you left. So, essentially, you have to create one big byte array for the entire content of the stream which may not always be feasible.
- If you wish to write to a file, then do that and change the InputStream to point to the file!
- Wrap it with your own implementation of FilterInputStream and in the read methods, before returning, write it to a file also.


apigee, a better way to API!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to read closed inputStream
 
Similar Threads
Jsp retrieve Image
How InputStreamReader.read(char[] cbuf) determine the end of the stream
Handling Oracle Blob with Hibernate
Parsing with DOM "hangs": inputstream problem
DOM non validation parsing