Skip to content Skip to sidebar Skip to footer

Java Streamcorruptedexception When Sending Object Containing Byte Data Over A Certain Size

I have a Java client-server (using ocsf if anyone here knows it) infrastructure I am using to upload files from client to server. The client is actually an Android app (not sure if

Solution 1:

StreamCorruptedException

A Java StreamCorruptedException can be thrown while deserialising data. It essentially occurs in one of two main cases:

you try to open an ObjectInputStream around some data that wasn't actually written using an  ObjectOutputStream

OR

During a  readObject() operation, the stream gets in the "wrong place".

From java docs:

Thrown when control information that was read from an object stream violates internal consistency checks.

But I got this exception with large message and moved to byte array solution.

Have a look at this article:http://www.javamex.com/tutorials/io/StreamCorruptedException.shtml

In summary, convert Object to and from byte array and re-create it.

Solution 2:

What I did eventually is initially send an object indicating the upload details (fileSize, sender id, etc..) and then on the server side grabbed the underlining inputStream that was in the ObjectInputStream and transferred just the bytes of the files separately. Once finished the client and server continue to communicate via objects. It works fine for now.

Hope this helps someone.

Post a Comment for "Java Streamcorruptedexception When Sending Object Containing Byte Data Over A Certain Size"