code: public byte[] readBytes() throws IOException {
      int toRead = readInt();
      byte[] bytes = new byte[toRead];
      while (toRead > 0) {
        int byteRead = input.read(bytes, bytes.length - toRead, toRead);
        if (byteRead == -1) {
          throw new EOFException();
        }
        toRead -= byteRead;
      }
      return bytes;
    }
docs: Read a byte sequence. First read an int to indicate how many bytes to read, then that many bytes.
  @return the read bytes as a byte array
  @throws java.io.IOException If there is IO error.
  @throws java.io.EOFException If end of file reached.