This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line!
See this thread for details.
Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

How to read closed inputStream

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic