code: private void flushBuffer(ByteBuffer buffer, WritableByteChannel output) throws IOException {
      buffer.flip();
      output.write(buffer);
      buffer.flip();
      buffer.limit(buffer.capacity());
    }
docs: Flush the current write buffer to disk.
  
  @param buffer Buffer to write
  @param output Output channel
  @throws IOException on IO errors