I am using NIO in my program. On Receiver side i am getting multiple messages in same buffer and want to read all using ByteArrayInput Stream and ObjectInputStream . It is working for fixed size.
SerializedData is my data class.
while( offset < limit)
bStream = new ByteArrayInputStream(byteArray,<offset>,limit);
ObjectInputStream iStream = new ObjectInputStream( bStream );
serializeData = (SerializedData) iStream.readObject();
System.out.println("Msg: " + serializeData.getData());
This logic is working for fixed size message as in that case i know the <received_msg_size>.
here my logic is to use get the number of bytes read from byte equals to offset for next msg.
My Query is that how should i know the number of bytes reads from bStream. iStream.available() methos always returns zero.
What are the alternatives? My understading is that as i am able to retrieve the first message then i should be able to calculate the length read ( in bytes ) also.