*
The moose likes Java in General and the fly likes InputStream duplication, how to ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "InputStream duplication, how to ?" Watch "InputStream duplication, how to ?" New topic
Author

InputStream duplication, how to ?

Srinu Nanduri
Ranch Hand

Joined: Mar 20, 2006
Posts: 42
Hi

I have a problem with InputStream (FilterInputStream) in my application.

I would like to start with reminding the point that "Once an input stream is read, we cannot read it again". Any comments ?

Now, my question is, Is there any possibility to duplicate the input stream i have such that i can use the original / duplicate and pass the other one as it is further to my application.

I will be very thankful if some one can help me with this.

Thanks & Regards,
Srinivasan.


SCJP, SCWCD
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

InputStream and Reader both have a reset() method which can be used to rewind a stream to a point identified with a call to mark(). These method are not supported with all streams/readers and care must be used in setting the size of data preserved with the mark() call.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
You could read the InputStream completely to a byte[] and construct any number of streams from that source with ByteArrayInputStream. (Assuming the total is reasonable to keep in memory)
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: InputStream duplication, how to ?
 
Similar Threads
Problem with using getResourceAsStream
writing to Text file.
InputStream duplication, how to ?
How to read closed inputStream
need to reuse input stream