0

I want to read an input stream twice but after the first usage, the stream gets closed and I am not able to use it again. CloseShieldInputStream also doesn't seem to help. Can someone please help me with this?

Sujit Agarwal
  • 12,348
  • 11
  • 48
  • 79
Prabhat
  • 11
  • 4
  • Which language are you working in? What have you tried till now? Show us the code. – Sujit Agarwal Aug 06 '18 at 13:50
  • It's java. basically I am detecting the mime type and length of the input stream and then I am supposed to pass it to the output stream. The signature of the method is something like this : public void execute(InputStream input, OutputStream output) – Prabhat Aug 07 '18 at 09:19
  • After detecting the MIME type and length, do you want to process the _remainder_ of the stream? Or do you want to start reading it from the very beginning again? – DodgyCodeException Aug 08 '18 at 09:46
  • 1
    Have a look at this question: https://stackoverflow.com/questions/924990/how-to-cache-inputstream-for-multiple-use – Herr Derb Aug 08 '18 at 10:04

1 Answers1

0

Save input stream into byte[] and then read it as many as you want.

Oleg Cherednik
  • 17,377
  • 4
  • 21
  • 35