docs: @Override
  	public int append(ReadableByteChannel channel) throws IOException {
  		assert invariant(true);
  
  		int totalRead = 0;
  
  		try {
  
  			boolean done;
  
  			// precondition: the channel has data
  
  			do {
  				ByteBuffer dest = writableBuf();
  
  				int space = dest.remaining();
  				assert space > 0;
  
  				int read = channel.read(dest);
  				if (read >= 0) {
  					totalRead += read;
  				} else {
  					// end of stream (e.g. the other end closed the connection)
  					removeLastBufferIfEmpty();
  					sizeChanged();
  
  					assert invariant(true);
  					return -1;
  				}
  
  				// if buffer wasn't filled -> no data is available in channel
  				done = read < space;
  			} while (!done);
  
  		} finally {
  			removeLastBufferIfEmpty();
  			sizeChanged();
  			assert invariant(true);
  		}
  
  		return totalRead;
  	}