larksuite-oapi/src/main/java/com/larksuite/oapi/okio1_17/Pipe.java
public void fold(Sink sink) throws IOException {
    while (true) {
      Buffer sinkBuffer;
      synchronized (buffer) {
        if (foldedSink != null) throw new IllegalStateException("sink already folded");

        if (buffer.exhausted()) {
          sourceClosed = true;
          foldedSink = sink;
          return;
        }

        sinkBuffer = new Buffer();
        sinkBuffer.write(buffer, buffer.size);
        buffer.notifyAll(); // Notify the sink that it can resume writing.
      }

      boolean success = false;
      try {
        sink.write(sinkBuffer, sinkBuffer.size);
        sink.flush();
        success = true;
      } finally {
        if (!success) {
          synchronized (buffer) {
            sourceClosed = true;
            buffer.notifyAll(); // Notify the sink that it can resume writing.
          }
        }
      }
    }
  }
/**
   * Writes any buffered contents of this pipe to {@code sink}, then replace this pipe's source
   * with {@code sink}. This pipe's source is closed and attempts to read it will throw an
   * {@link IllegalStateException}.
   *
   * This method must not be called while concurrently accessing this pipe's source. It is safe,
   * however, to call this while concurrently writing this pipe's sink.
   */
Writes any buffered contents of this pipe to  sink, then replace this pipe's source
with  sink. This pipe's source is closed and attempts to read it will throw an
IllegalStateException.

This method must not be called while concurrently accessing this pipe's source. It is safe,
however, to call this while concurrently writing this pipe's sink.
Writes any buffered contents of this pipe to sink then replace this pipe ' s source with sink . This pipe ' s source is closed and attempts to read it will throw an IllegalStateException . This method must not be called while concurrently accessing this pipe ' s source . It is safe however to call this while concurrently writing this pipe ' s sink .
public void fold(Sink sink) throws IOException {
    while (true) {
      Buffer sinkBuffer;
      synchronized (buffer) {
        if (foldedSink != null) throw new IllegalStateException("sink already folded");
        if (buffer.exhausted()) {
          sourceClosed = true;
          foldedSink = sink;
          return;
        }
        sinkBuffer = new Buffer();
        sinkBuffer.write(buffer, buffer.size);
        buffer.notifyAll(); 
      }
      boolean success = false;
      try {
        sink.write(sinkBuffer, sinkBuffer.size);
        sink.flush();
        success = true;
      } finally {
        if (!success) {
          synchronized (buffer) {
            sourceClosed = true;
            buffer.notifyAll(); 
          }
        }
      }
    }
  }
public void fold ( Sink sink ) throws IOException { while ( true ) { Buffer sinkBuffer ; synchronized ( buffer ) { if ( foldedSink != null ) throw new IllegalStateException ( "sink already folded" ) ; if ( buffer . exhausted ( ) ) { sourceClosed = true ; foldedSink = sink ; return ; } sinkBuffer = new Buffer ( ) ; sinkBuffer . write ( buffer , buffer . size ) ; buffer . notifyAll ( ) ; } boolean success = false ; try { sink . write ( sinkBuffer , sinkBuffer . size ) ; sink . flush ( ) ; success = true ; } finally { if ( ! success ) { synchronized ( buffer ) { sourceClosed = true ; buffer . notifyAll ( ) ; } } } } }
Writes any buffered contents of this pipe to {@code sink}, then replace this pipe's source
 with {@code sink}.
Writes any buffered contents of this pipe to { @code sink } then replace this pipe ' s source with { @code sink } .
// Notify the sink that it can resume writing. // Notify the sink that it can resume writing.