@Override
  public void writeExternal(ObjectOutput out) throws IOException {
    out.writeBoolean(buffer != null);
    if (buffer != null) {
      out.writeInt(buffer.capacity());
      out.writeInt(buffer.limit());
      out.writeInt(buffer.position());
      for (int i = 0; i < buffer.capacity(); i++) {
        out.write(buffer.get(i));
      }
    }
  }
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