문제

I'm sending JPEGs as byte arrays over a Socket, the 4 first bytes is the length of the JPEG. I have to read these in order to figure out how many bytes i should read to get the actual image. I can't seem to figure out how to do this.

Just reading like this is not guaranteed to give me my 4 bytes:

byte[] JPEGlength = new byte[4];
inputStream.read(lengthBuffer);

I have been thinking over this a lot and I cant seem to figure out how to do this. Help would be very appreciated!

도움이 되었습니까?

해결책

Use DataInputStream.readFully(), but in this case what you really need is DataInputStream.readInt().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top