@Override
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    boolean hasBuffer = in.readBoolean();
    if (hasBuffer) {
      int capacity = in.readInt();
      int limit = in.readInt();
      int position = in.readInt();
      byte[] bytes = new byte[capacity];
      int bytesRead = in.read(bytes);
      if (bytesRead != capacity) {
        throw new IOException(
            "Expected to read " + capacity + " bytes but only read " + bytesRead + " bytes.");
      }
      setBuffer(ByteBuffer.wrap(bytes, position, limit - position));
    } else {
      buffer = null;
    }
  }
See the InputStream read method for javadocs. Note that if an attempt to read past the end of
the wrapped ByteBuffer is done this method throws BufferUnderflowException
geode-core/src/main/java/org/apache/geode/internal/tcp/ByteBufferInputStream.java