public void sendTo(DataOutput out) throws IOException {
    finishWriting();
    if (chunks != null) {
      for (ByteBuffer bb : chunks) {
        int bytesToWrite = bb.remaining();
        if (bytesToWrite > 0) {
          if (bb.hasArray()) {
            out.write(bb.array(), bb.arrayOffset() + bb.position(), bytesToWrite);
            bb.position(bb.limit());
          } else {
            byte[] bytes = new byte[bytesToWrite];
            bb.get(bytes);
            out.write(bytes);
          }
          size -= bytesToWrite;
        }
      }
    }
    {
      ByteBuffer bb = buffer;
      int bytesToWrite = bb.remaining();
      if (bytesToWrite > 0) {
        if (bb.hasArray()) {
          out.write(bb.array(), bb.arrayOffset() + bb.position(), bytesToWrite);
          bb.position(bb.limit());
        } else {
          byte[] bytes = new byte[bytesToWrite];
          bb.get(bytes);
          out.write(bytes);
        }
        size -= bytesToWrite;
      }
    }
  }
Write the contents of this stream to the specified stream.
<p>
Note this implementation is exactly the same as writeTo(OutputStream) but they do not both
implement a common interface.
geode-core/src/main/java/org/apache/geode/internal/HeapDataOutputStream.java