ObjectInputStream/OutputStream buffering?

Discussion in 'Java' started by Knute Johnson, Feb 18, 2007.

  1. 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,

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Feb 18, 2007
    #1
    1. Advertising

  2. Knute Johnson

    petersprc Guest

    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

    On Feb 18, 5:02 pm, Knute Johnson <>
    wrote:
    > 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,
    >
    > --
    >
    > Knute Johnson
    > email s/nospam/knute/
     
    petersprc, Feb 18, 2007
    #2
    1. Advertising

  3. petersprc wrote:
    > 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
    >
    > On Feb 18, 5:02 pm, Knute Johnson <>
    > wrote:
    >> 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,
    >>
    >> --
    >>
    >> Knute Johnson
    >> email s/nospam/knute/

    >
    >


    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.

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Feb 18, 2007
    #3
  4. Knute Johnson

    Esmond Pitt Guest

    Knute Johnson wrote:
    > 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.
     
    Esmond Pitt, Feb 19, 2007
    #4
  5. Knute Johnson

    petersprc Guest

    Yeah, as Esmond says, the issue seems to be the case considered in
    this report:

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4337145

    Flushing after creating the ObjectOutputStream might do the trick.

    On Feb 18, 7:47 pm, Esmond Pitt <>
    wrote:
    > Knute Johnson wrote:
    > > 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.
     
    petersprc, Feb 19, 2007
    #5
  6. petersprc wrote:
    > Yeah, as Esmond says, the issue seems to be the case considered in
    > this report:
    >
    > http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4337145
    >
    > Flushing after creating the ObjectOutputStream might do the trick.
    >
    > On Feb 18, 7:47 pm, Esmond Pitt <>
    > wrote:
    >> Knute Johnson wrote:
    >>> 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.

    >
    >


    That could have been the problem, I'll have to play with is some more.

    Thanks,

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Feb 19, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Serial # 19781010
    Replies:
    1
    Views:
    718
    Roedy Green
    Jul 15, 2003
  2. Roedy Green
    Replies:
    2
    Views:
    331
    Roedy Green
    Aug 5, 2003
  3. Lothar Kimmeringer

    Re: creating ObjectInputStream takes forever

    Lothar Kimmeringer, Jul 31, 2003, in forum: Java
    Replies:
    3
    Views:
    610
    Blah Blah
    Aug 1, 2003
  4. Ahmed Moustafa
    Replies:
    5
    Views:
    12,729
    Gordon Beaton
    Nov 16, 2003
  5. Replies:
    2
    Views:
    3,606
Loading...

Share This Page