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 that matters that much or not in this case)
I am doing this by reading the file data (bytes), wrapping it in an object that contains some other details (user id, etc..) and sending this object over ObjectOutputStream
to the server.
It seems everything works fine until the byte array of the file is over a certain size (not sure what this strange threshold is yet but it seems 645KB is already too much). Then, the server throws a StreamCorruptedException
when trying to read the object from the ObjectInputStream
and closes the socket.
The code of the object message containing the file bytes:
public class MessageUploadFile extends MessageToServer {
private static final long serialVersionUID = 2356276507283427913L;
private String _destId;
private TransferDetails _td;
private byte[] _fileData;
public MessageUploadFile(String srcId, TransferDetails td, byte[] fileData){
super(srcId);
_destId = td.getDestinationId();
_td = td;
_fileData = fileData;
}
The client side socket and streams initialization:
clientSocket= new Socket(host, port);
output = new ObjectOutputStream(clientSocket.getOutputStream());
input = new ObjectInputStream(clientSocket.getInputStream());
Sending the message using:
output.writeObject(msg);
These are the streams initialization on the server side:
input = new ObjectInputStream(clientSocket.getInputStream());
output = new ObjectOutputStream(clientSocket.getOutputStream());
Reading the message using:
msg = input.readObject();