Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Streams, Streams, Streams

 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
When obtaining my input and output streams from a Socket as in:

Can you layer different streams on the originals, For exampls, is there any problem with:

Then I wish to get to either the data input/output or the object input/output. As I am writing I realize that for my case I could get away with only the Object(In|Out)putStream(s). I just seek clarification from a streaming point of view -- that is will the above work?
Thanks
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I usually see this referred to as 'chaining' pipes together, but it is in fact roughly analagous to the STREAMS concept that evolved from SVR3 Unix.
You should be able to chain these together without a hitch, although once you've got past 3 chained I/O Readers/Writers you're probably taking an unnecessary step or two, as you discovered.
Typically, you'd need no more than: a) descriptor access (file, socket); b) a buffer; and c) a filter.
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But in practice, I have some problems
Originally, when I first wrote my application, I did not use the buffered streams for simplicity. Now, I am trying to insert the BufferedStream layer and my Client application is hanging.
Here's the code how I set up my streams:

Can it be a difference how or in what order the streams are set up?
I am thinking that I may have to use bos.flush() but then again I must also use oos.flush() and what should be the proper order of flushing
Bottom line, if I pass bis/bos to oos/ois the client side hangs
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would certainly only flush() the stream that is furthest from the real output stream (I hope that makes sense.) You absolutely must flush() if using a buffered output stream and it is a good idea in general.
If you look at the source you will see that all of the output stream variants call their attached output stream flush automatically.
That code looks reasonable to me, the order of creating should not make a difference.
Bill
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I can get it to work, my app just hangs
Here is the client side:

And here is the server side:

Somewhere else in the client side:

In the server side I simply read it back in:

The server then sends back a Result Object that contains status and/or any Exceptions.
I want to use buffering to gain performance, but if I uncomment the above where I set up my streams and use the Buffers my app hangs
Please help,
Leslie
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I figured it out!
Just added a call to oos.flush() in my init() method. I guess since I put in the buffering layer, I need the call to flush() even if I didn't actually send any data. A clearer explanation is appreciated.
Furthermore, I am wondering if there would be any performance gain if I were to use the Zip streams. Also, are there any special methods that I would have to call on the Zip objects. As you would see in the above snippet I did not use the Zip stream.
Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic