code: 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);
      }
docs: Get the next packet from the stream
  
  @param is the input stream to read the next packet from
  @return The next packet from the stream, or NULL if the stream is closed
  @throws java.io.IOException if an error occurs while reading data