DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Tim Guest

    Help with Object Streams and object array...

    Thanks for looking.

    I am, as the group suggests, getting.started in java.

    I trying to read & write an array of objects via the ObjectStream, and have
    had problems with multiple items. My coding has been based on these
    assumtions:

    #1: Writing each element of the object array sequentially to the
    outputstream will work.

    #2: I can read objects back from an inputstream until the streams
    ..available() returns something less than 1.


    Are these right? Anything in particular I should know about the behavior of
    the ObjectXXXStream and reading or writing objects?


    Thanks in advance,
    Tim





  2. #2
    Kyle Gabhart Guest

    Re: Help with Object Streams and object array...


    "Tim" <TC225@cornwell.edu> wrote:
    >Thanks for looking.
    >
    >I am, as the group suggests, getting.started in java.
    >
    >I trying to read & write an array of objects via the ObjectStream, and have
    >had problems with multiple items. My coding has been based on these
    >assumtions:
    >
    >#1: Writing each element of the object array sequentially to the
    >outputstream will work.
    >
    >#2: I can read objects back from an inputstream until the streams
    >..available() returns something less than 1.
    >
    >
    >Are these right? Anything in particular I should know about the behavior

    of
    >the ObjectXXXStream and reading or writing objects?
    >
    >
    >Thanks in advance,
    >Tim


    Tim,

    You have to flush the ObjectOutputStream everytime after you send it.

    os.writeObject(obj);
    os.flush();

    If that doesn't do the trick, try resetting the stream before writing another
    object:

    os.writeObject(obj);
    os.flush();
    os.reset();

    Cordially,

    Kyle Gabhart
    DevX Java Pro
    -------------
    http://www.gabhart.com




  3. #3
    Tim Guest

    Re: Help with Object Streams and object array...

    Thanks for the reply.

    I managed to overcome most of the trouble I had, but I still have a
    question...

    When reading from an ObjectInputStream, how does one tell when the stream
    ends/closes?

    I get an EOFException, but is there another/better way?

    TIA,
    Tim C.



    "Kyle Gabhart" <kyle@gabhart.com> wrote in message
    news:3cbe3cd1@10.1.10.29...
    >
    > "Tim" <TC225@cornwell.edu> wrote:
    > >Thanks for looking.
    > >
    > >I am, as the group suggests, getting.started in java.
    > >
    > >I trying to read & write an array of objects via the ObjectStream, and

    have
    > >had problems with multiple items. My coding has been based on these
    > >assumtions:
    > >
    > >#1: Writing each element of the object array sequentially to the
    > >outputstream will work.
    > >
    > >#2: I can read objects back from an inputstream until the streams
    > >..available() returns something less than 1.
    > >
    > >
    > >Are these right? Anything in particular I should know about the behavior

    > of
    > >the ObjectXXXStream and reading or writing objects?
    > >
    > >
    > >Thanks in advance,
    > >Tim

    >
    > Tim,
    >
    > You have to flush the ObjectOutputStream everytime after you send it.
    >
    > os.writeObject(obj);
    > os.flush();
    >
    > If that doesn't do the trick, try resetting the stream before writing

    another
    > object:
    >
    > os.writeObject(obj);
    > os.flush();
    > os.reset();
    >
    > Cordially,
    >
    > Kyle Gabhart
    > DevX Java Pro
    > -------------
    > http://www.gabhart.com
    >
    >
    >




  4. #4
    Soft Solution System Limited Guest

    Re: Help with Object Streams and object array...

    you add a counter in the beginning of the file to control the number of
    object behind to be read.


    "Tim" <TC225@cornwell.edu> ¼¶¼g©ó¶l¥ó news:3cbeca1f$1@10.1.10.29...
    > Thanks for the reply.
    >
    > I managed to overcome most of the trouble I had, but I still have a
    > question...
    >
    > When reading from an ObjectInputStream, how does one tell when the stream
    > ends/closes?
    >
    > I get an EOFException, but is there another/better way?
    >
    > TIA,
    > Tim C.
    >
    >
    >
    > "Kyle Gabhart" <kyle@gabhart.com> wrote in message
    > news:3cbe3cd1@10.1.10.29...
    > >
    > > "Tim" <TC225@cornwell.edu> wrote:
    > > >Thanks for looking.
    > > >
    > > >I am, as the group suggests, getting.started in java.
    > > >
    > > >I trying to read & write an array of objects via the ObjectStream, and

    > have
    > > >had problems with multiple items. My coding has been based on these
    > > >assumtions:
    > > >
    > > >#1: Writing each element of the object array sequentially to the
    > > >outputstream will work.
    > > >
    > > >#2: I can read objects back from an inputstream until the streams
    > > >..available() returns something less than 1.
    > > >
    > > >
    > > >Are these right? Anything in particular I should know about the

    behavior
    > > of
    > > >the ObjectXXXStream and reading or writing objects?
    > > >
    > > >
    > > >Thanks in advance,
    > > >Tim

    > >
    > > Tim,
    > >
    > > You have to flush the ObjectOutputStream everytime after you send it.
    > >
    > > os.writeObject(obj);
    > > os.flush();
    > >
    > > If that doesn't do the trick, try resetting the stream before writing

    > another
    > > object:
    > >
    > > os.writeObject(obj);
    > > os.flush();
    > > os.reset();
    > >
    > > Cordially,
    > >
    > > Kyle Gabhart
    > > DevX Java Pro
    > > -------------
    > > http://www.gabhart.com
    > >
    > >
    > >

    >
    >




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links