public void writeTo(ByteBuffer buf) {
    if (getLength() > 0) {
      if (part instanceof byte[]) {
        buf.put((byte[]) part);
      } else if (part instanceof StoredObject) {
        StoredObject c = (StoredObject) part;
        ByteBuffer bb = c.createDirectByteBuffer();
        if (bb != null) {
          buf.put(bb);
        } else {
          int bytesToSend = c.getDataSize();
          long addr = c.getAddressForReadingData(0, bytesToSend);
          while (bytesToSend > 0) {
            buf.put(AddressableMemoryManager.readByte(addr));
            addr++;
            bytesToSend--;
          }
        }
      } else {
        HeapDataOutputStream hdos = (HeapDataOutputStream) part;
        try {
          hdos.sendTo(buf);
        } finally {
          hdos.rewind();
        }
      }
    }
  }
Write the contents of this part to the specified byte buffer. Precondition: caller has already
checked the length of this part and it will fit into "buf".
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/Part.java