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