code: @Override
      public int write(ByteBuffer src)
              throws IOException
      {
          if (closed) {
              throw new ClosedChannelException();
          }
  
          if (buffer.remaining() <= 0) {
              flushBuffer();
          }
  
          final int srcLength = src.remaining();
  
          // easy case: enough free space in buffer for entire input
          if (buffer.remaining() >= src.remaining()) {
              buffer.put(src);
              return srcLength;
          }
  
          // store current limit
          final int srcEnd = src.position() + src.remaining();
  
          while ((src.position() + buffer.remaining()) <= srcEnd) {
              // fill partial buffer as much as possible and flush
              src.limit(src.position() + buffer.remaining());
              buffer.put(src);
              flushBuffer();
          }
  
          // reset original limit
          src.limit(srcEnd);
  
          // copy remaining partial block into now-empty buffer
          buffer.put(src);
  
          return srcLength;
      }
docs: {@inheritDoc}