how to write serialized object to disc

C

coltrane

Well my problem has one added item, the serialized object is read from
a network stream.

so....

I have a server that reads a serialized object from a network stream
and I need to write that serialized object to disk without
deserializing it. The serialized object comes over the wire as a blob
and there is no info such as size. Am I suppose to determine the
number of bytes and write it out as a byte array? This doesn't seem
like the right answer.

any help would be appreciated

john
 
P

Pavel Minaev

I have a server that reads a serialized object from a network stream
and I need to write that serialized object to disk without
deserializing it. The serialized object comes over the wire as a blob
and there is no info such as size. Am I suppose to determine the
number of bytes and write it out as a byte array? This doesn't seem
like the right answer.

Why isn't it the right answer? It seems to do precisely what you want
to do - receive a serialized object, and store it without
deserializing.

Generally, unless this is a part of some larger communication, you
don't need to know the size - you just assume that all bytes you get
until the connection is closed belong to that object. If anything else
is there after the object, then it's meaningless, since without size
(or some marker value), how would you know when one thing ends and
another begins?
 
C

Coltrane

Why isn't it the right answer? It seems to do precisely what you want
to do - receive a serialized object, and store it without
deserializing.

Generally, unless this is a part of some larger communication, you
don't need to know the size - you just assume that all bytes you get
until the connection is closed belong to that object. If anything else
is there after the object, then it's meaningless, since without size
(or some marker value), how would you know when one thing ends and
another begins?

thanks, I found my problem. I was first iterating over the network
clientstream to count the bytes on the stream and then I tried to read
again to put the bytes in a buffer.
the second read won't work, I had to get the bytes on the first
iteration. live and learn
 

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

Top