I tried to come up with a good title, but seem to have failed. Here's my problem:
I'm reading data in from a socket. The data contained in the buffer is a serialized object. Once the data is completely read, I can then create an ObjectInputStream and use readObject to read in the data.
My problem is, since my socket class is reading in the bytes... how do I know when I have received the full object? There does not seem to be an end of object indicator, and I've tried looking for a breakout of the serialized bytecode to see if I can find length fields, but the serialization bytecode is not well explained anywhere I can find with Google.
The objects I'm receiving are hash maps (java.util.Map) if that makes a difference.
Here is part of the code I'm using:
long start = System.currentTimeMillis();
long end = start + (getTimeout() * 1000);
m_Ipports.send(dataToSend);
m_Waiting = true;
while (m_Waiting) {
// Data is read in a separate thread, and stored into the byte buffer m_DataIn
if (System.currentTimeMillis() > end) {
//throw new Exception("Timeout waiting for response.");
m_Waiting = false; // hack to get it to work. Times out every time.
}
m_Ipports.doEvents();
}
ByteArrayInputStream bis = new ByteArrayInputStream(m_DataIn.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
Object o = ois.readObject();
Map m = (Map)o;
So, my question is, when I'm reading m_DataIn, how do I determine I've reached the end of the object?
NOTE: I cannot in any way modify the server that I am receiving these objects from. It's not my code.
Thanks.
Charles.