code: private void ensureAvailable(final int bytes) throws IOException {
          while (buffer.remaining() < bytes) {
              buffer.compact();
              if (channel.read(buffer) < 0) {
                  throw new EOFException();
              }
              buffer.flip();
          }
      }
docs: Ensures that a certain amount of bytes are in the buffer, ready
  to be read.
  @param bytes Minimal number of unread bytes required in the buffer.
  @see ByteBuffer#remaining()
  @throws IOException if reading sufficient more data into the buffer
  fails.