long write(GatheringByteChannel channel) throws IOException {
    if (!hasRemaining()) {
      return 0;
    }
    long written = 0;
    for (ByteBuffer bb : this.buffers) {
      if (bb.hasRemaining()) {
        final int pos = bb.position();
        final int result = channel.write(bb);
        if (result <= 0) {
          // Write error. Return how much we were able to write until now.
          return written;
        }
        // Adjust the position of buffers already written so we don't write out
        // duplicate data upon retry of incomplete write with the same buffer chain.
        bb.position(pos + result);
        remaining -= result;
        written += result;
      }
    }
    return written;
  }
Expensive. Makes a new buffer to hold a copy of what is in contained ByteBuffers. This call
drains this instance; it cannot be used subsequent to the call.
@return A new byte buffer with the content of all contained ByteBuffers.
hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BufferChain.java