code: @Override
    public synchronized int write(ByteBuffer buffer) throws IOException {
      checkState(isInitialized, "initialize() must be invoked before use.");
      if (!isOpen()) {
        throw new ClosedChannelException();
      }
  
      // No point in writing further if upload failed on another thread.
      if (uploadOperation.isDone()) {
        waitForCompletionAndThrowIfUploadFailed();
      }
  
      return pipeSinkChannel.write(buffer);
    }
docs: Writes contents of the given buffer to this channel.
  
  <p>Note: The data that one writes gets written to a pipe which must not block if the pipe has
  sufficient buffer space. A success code returned from this method does not mean that the
  specific data was successfully written to the underlying storage. It simply means that there is
  no error at present. The data upload may encounter an error on a separate thread. Such error is
  not ignored; it shows up as an exception during a subsequent call to write() or close(). The
  only way to be sure of successful upload is when the close() method returns successfully.
  
  @param buffer buffer to write
  @throws IOException on IO error