public void writeTo(OutputStream out, ByteBuffer buf) throws IOException {
    if (getLength() > 0) {
      if (part instanceof byte[]) {
        byte[] bytes = (byte[]) part;
        out.write(bytes, 0, bytes.length);
      } else if (part instanceof StoredObject) {
        StoredObject so = (StoredObject) part;
        ByteBuffer sobb = so.createDirectByteBuffer();
        if (sobb != null) {
          HeapDataOutputStream.writeByteBufferToStream(out, buf, sobb);
        } else {
          int bytesToSend = so.getDataSize();
          long addr = so.getAddressForReadingData(0, bytesToSend);
          while (bytesToSend > 0) {
            if (buf.remaining() == 0) {
              HeapDataOutputStream.flushStream(out, buf);
            }
            buf.put(AddressableMemoryManager.readByte(addr));
            addr++;
            bytesToSend--;
          }
        }
      } else {
        HeapDataOutputStream hdos = (HeapDataOutputStream) part;
        try {
          hdos.sendTo(out, buf);
        } finally {
          hdos.rewind();
        }
      }
    }
  }
Write the contents of this part to the specified output stream. This is only called for parts
that will not fit into the commBuffer so they need to be written directly to the stream. A
stream is used because the client is configured for old IO (instead of nio).

@param buf the buffer to use if any data needs to be copied to one
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/Part.java