Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

InputStream duplication, how to ?

 
Srinu Nanduri
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Ess
Bartender
Pie
Posts: 9265
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic