-
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
-
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
-
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
>
>
>
-
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
> >
> >
> >
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks