java - InputStream.read() is either missing or adding a value in my buffer - How come? -
i've created following procedure in run() method of connectedthread taken bluetoothchat sample.
// read inputstream byte[] buffer = new byte[16]; int offset = 0; while(buffer.length-offset != 0) { int bytesread += mminstream.read(buffer, offset, buffer.length-offset); offset += bytesread; } // stuff contents of buffer
the buffer loaded in 16 bytes gradually expected reason @ 10th byte in array 0 inserted , shifts remaining part of package(and such corrupting entire package)
here example of happening
the following sent other client :
[-11, 126, -16, -30, -92, 110, -26, 13, 22, 91, -31, 32, 54, -125, -112, 45]
this receive :
[-11, 126, -16, -30, -92, 110, -26, 13, 22, 91, 0, -31, 32, 54, -125, -112]
as can see, 0 pushed in 10th byte , rest of package shifted right(cutting off last byte)
as part of debugging process tried having breakpoint @ bytesread += mminstream.read(buffer, offset, buffer.length-offset)
, our surprise entire original message received. gives?
how "break" in reads correct issue? doing wrong or not understanding?
probably meant
bytesread = mminstream.read(buffer, offset, buffer.length-offset); offset += bytesread;
instead of
bytesread += ...
Comments
Post a Comment