Вопрос

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