Win a copy of Penetration Testing Basics this week in the Security forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing to OutputStream having capacity restriction

Al Bal
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an outputstream, to which the client A(process) is writing , I need to forward it in byte chuncks to client B(process).
I'd like to connect the output stream of client A with the output stream of client B. (I don't need to fork/clone I rather need to take some of the data from stream A and move it to stream B(i.e the data don't stay in stream A))
I thought about implementing an ByteArrayOutputStream with capacity restriction. My main limitation is an amount of available memory. So having such stream os
1.When I write more than say 1MB to the output stream I need to "stop". I prefer not throw exception but write the complete contents of os output stream to the specified other output stream argument.
OutputStream out;

2.And after that continue the writings to os from its beginning
In order to prevent the situation described at 1. , I prefer to drain os, as frequently as possible. I mean copy the data from it to out in chuncks of 512KB Is it feasible? If yes Any advices how can it be done? Or may be there is a built in class which answers my requirements

Note: The amount of bytes written to out is also limited. I can write there up to 1GB. If I have more, I need to create other output stream in order to drain from os there. The proccess of writing to os. can be like that. 500MB was written there - I transfer it immidiately to out. After several seconds 700MB were written there - I need to drain only 500MB to out and other 200MB to other outputstream(out2), which I`ll need to create upon such situation
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic