• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

writing to OutputStream having capacity restriction

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
os.writeTo(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
 
reply
    Bookmark Topic Watch Topic
  • New Topic