• Post Reply Bookmark Topic Watch Topic
  • New Topic

InputStream -> OutputStream

 
mathew Jackson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I need to do. Inside a servlet I have an InputStream that is the result of calling getInputStream on a Process. This is stdout from a C program that I call. I also have an OutputStream. This comes from Response.getOutputStream. What I need to do is pipe the stream from the InputStream through the OutputStream.
Any ideas?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a loop to read bytes from the input stream, and write those bytes to the output stream:

For improved efficiency, modify the loop to use read(byte[]) and write(byte[]) instead. It may well also be useful to put this method in a separate thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!