static RawPacket nextPacket ( final InputStream is ) throws IOException { byte [ ] lengthBuffer = readLengthSeq ( is ) ; int length = ( lengthBuffer [ 0 ] & 0xff ) + ( ( lengthBuffer [ 1 ] & 0xff ) << 8 ) + ( ( lengthBuffer [ 2 ] & 0xff ) << 16 ) ; if ( length == - 1 ) { return null ; } if ( length < 0 ) { throw new IOException ( "Got negative packet size: " + length ) ; } final int packetSeq = lengthBuffer [ 3 ] ; final byte [ ] rawBytes = new byte [ length ] ; final int nr = ReadUtil . safeRead ( is , rawBytes ) ; if ( nr != length ) { throw new IOException ( "EOF. Expected " + length + ", got " + nr ) ; } return new RawPacket ( ByteBuffer . wrap ( rawBytes ) . order ( ByteOrder . LITTLE_ENDIAN ) , packetSeq ) ; }
Get the next packet from the stream