public void sendTo(SocketChannel chan, ByteBuffer out) throws IOException {
    finishWriting();
    if (size() == 0) {
      return;
    }
    out.clear();
    if (chunks != null) {
      for (ByteBuffer bb : chunks) {
        sendChunkTo(bb, chan, out);
      }
    }
    sendChunkTo(buffer, chan, out);
    flushBuffer(chan, out);
  }
Write this stream to the specified channel. Call multiple times until size returns zero to make
sure all bytes in the stream have been written.

@return the number of bytes written, possibly zero.
@throws IOException if channel is closed, not yet connected, or some other I/O error occurs.
geode-core/src/main/java/org/apache/geode/internal/HeapDataOutputStream.java