ObjectInputStream/OutputStream buffering?

K

Knute Johnson

Are ObjectInputStream and ObjectOutputStream buffered? Normally if you
use a BufferedInputStream it is the last stream class in the list. Can
you put a BufferedInputStream between the InputStream and
ObjectInputStream and realize any performance improvement?

Thanks,
 
P

petersprc

These are not buffered, so using a BufferedStream may be useful if
doing a large amount of I/O.

(Note, when creating an ObjectOutputStream:
"callers may wish to flush the stream immediately to ensure that
constructors for receiving ObjectInputStreams will not block when
reading the header.")

(In certain edge cases, you may want to flush the ObjectOutputStream,
see
 
K

Knute Johnson

petersprc said:
These are not buffered, so using a BufferedStream may be useful if
doing a large amount of I/O.

(Note, when creating an ObjectOutputStream:
"callers may wish to flush the stream immediately to ensure that
constructors for receiving ObjectInputStreams will not block when
reading the header.")

(In certain edge cases, you may want to flush the ObjectOutputStream,
see

Are ObjectInputStream and ObjectOutputStream buffered? Normally if you
use a BufferedInputStream it is the last stream class in the list. Can
you put a BufferedInputStream between the InputStream and
ObjectInputStream and realize any performance improvement?

Thanks,

I tried it with a file and it does improve the I/O considerable but
where I really wanted to use it was with some network I/O. When the
input side was buffered it didn't read all of the data and hung. That
turns out not to be where my problem was anyway so I put it back to
unbuffered. Thanks for the post.
 
E

Esmond Pitt

Knute said:
I tried it with a file and it does improve the I/O considerable but
where I really wanted to use it was with some network I/O. When the
input side was buffered it didn't read all of the data and hung. That
turns out not to be where my problem was anyway so I put it back to
unbuffered.

Buffering on a network is still a good idea. The problem you had was
that the other end wasn't flushing at the appropriate times.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top