aspose file tools*
The moose likes Distributed Java and the fly likes Streams, Streams, Streams Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Streams, Streams, Streams" Watch "Streams, Streams, Streams" New topic
Author

Streams, Streams, Streams

Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
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


Normal is in the eye of the beholder
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

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.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
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

Joined: Mar 22, 2000
Posts: 12789
    
    5
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

Joined: May 22, 2002
Posts: 336
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

Joined: May 22, 2002
Posts: 336
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,
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Streams, Streams, Streams