content: package okio;
  
  import androidx.constraintlayout.core.motion.utils.TypedValues;
  import java.io.EOFException;
  import java.io.OutputStream;
  import java.nio.ByteBuffer;
  import java.nio.charset.Charset;
  import kotlin.Metadata;
  import kotlin.jvm.internal.Intrinsics;
  
  @Metadata(bv = {1, 0, 3}, d1 = {"\u0000f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0012\n\u0002\b\u0002\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0011\n\u0002\u0018\u0002\n\u0002\b\u0006\b\u0000\u0018\u00002\u00020\u0001B\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\b\u0010\u0005\u001a\u00020\u0006H\u0016J\b\u0010\u000e\u001a\u00020\u000fH\u0016J\b\u0010\u0010\u001a\u00020\u0001H\u0016J\b\u0010\u0011\u001a\u00020\u0001H\u0016J\b\u0010\u0012\u001a\u00020\u000fH\u0016J\b\u0010\u0013\u001a\u00020\rH\u0016J\b\u0010\u0014\u001a\u00020\u0015H\u0016J\b\u0010\u0016\u001a\u00020\u0017H\u0016J\b\u0010\u0018\u001a\u00020\u0019H\u0016J\u0010\u0010\u001a\u001a\u00020\u001b2\u0006\u0010\u001c\u001a\u00020\u001dH\u0016J\u0010\u0010\u001a\u001a\u00020\u00012\u0006\u0010\u001c\u001a\u00020\u001eH\u0016J \u0010\u001a\u001a\u00020\u00012\u0006\u0010\u001c\u001a\u00020\u001e2\u0006\u0010\u001f\u001a\u00020\u001b2\u0006\u0010 \u001a\u00020\u001bH\u0016J\u0018\u0010\u001a\u001a\u00020\u000f2\u0006\u0010\u001c\u001a\u00020\u00062\u0006\u0010 \u001a\u00020!H\u0016J\u0010\u0010\u001a\u001a\u00020\u00012\u0006\u0010\"\u001a\u00020#H\u0016J \u0010\u001a\u001a\u00020\u00012\u0006\u0010\"\u001a\u00020#2\u0006\u0010\u001f\u001a\u00020\u001b2\u0006\u0010 \u001a\u00020\u001bH\u0016J\u0018\u0010\u001a\u001a\u00020\u00012\u0006\u0010\u001c\u001a\u00020$2\u0006\u0010 \u001a\u00020!H\u0016J\u0010\u0010%\u001a\u00020!2\u0006\u0010\u001c\u001a\u00020$H\u0016J\u0010\u0010&\u001a\u00020\u00012\u0006\u0010'\u001a\u00020\u001bH\u0016J\u0010\u0010(\u001a\u00020\u00012\u0006\u0010)\u001a\u00020!H\u0016J\u0010\u0010*\u001a\u00020\u00012\u0006\u0010)\u001a\u00020!H\u0016J\u0010\u0010+\u001a\u00020\u00012\u0006\u0010,\u001a\u00020\u001bH\u0016J\u0010\u0010-\u001a\u00020\u00012\u0006\u0010,\u001a\u00020\u001bH\u0016J\u0010\u0010.\u001a\u00020\u00012\u0006\u0010)\u001a\u00020!H\u0016J\u0010\u0010/\u001a\u00020\u00012\u0006\u0010)\u001a\u00020!H\u0016J\u0010\u00100\u001a\u00020\u00012\u0006\u00101\u001a\u00020\u001bH\u0016J\u0010\u00102\u001a\u00020\u00012\u0006\u00101\u001a\u00020\u001bH\u0016J\u0018\u00103\u001a\u00020\u00012\u0006\u00104\u001a\u00020\u00192\u0006\u00105\u001a\u000206H\u0016J(\u00103\u001a\u00020\u00012\u0006\u00104\u001a\u00020\u00192\u0006\u00107\u001a\u00020\u001b2\u0006\u00108\u001a\u00020\u001b2\u0006\u00105\u001a\u000206H\u0016J\u0010\u00109\u001a\u00020\u00012\u0006\u00104\u001a\u00020\u0019H\u0016J \u00109\u001a\u00020\u00012\u0006\u00104\u001a\u00020\u00192\u0006\u00107\u001a\u00020\u001b2\u0006\u00108\u001a\u00020\u001bH\u0016J\u0010\u0010:\u001a\u00020\u00012\u0006\u0010;\u001a\u00020\u001bH\u0016R\u001b\u0010\u0005\u001a\u00020\u00068Ö\u0002X\u0004¢\u0006\f\u0012\u0004\b\u0007\u0010\b\u001a\u0004\b\t\u0010\nR\u0010\u0010\u000b\u001a\u00020\u00068\u0006X\u0004¢\u0006\u0002\n\u0000R\u0012\u0010\f\u001a\u00020\r8\u0006@\u0006X\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0002\u001a\u00020\u00038\u0006X\u0004¢\u0006\u0002\n\u0000¨\u0006<"}, d2 = {"Lokio/RealBufferedSink;", "Lokio/BufferedSink;", "sink", "Lokio/Sink;", "(Lokio/Sink;)V", "buffer", "Lokio/Buffer;", "getBuffer$annotations", "()V", "getBuffer", "()Lokio/Buffer;", "bufferField", "closed", "", "close", "", "emit", "emitCompleteSegments", "flush", "isOpen", "outputStream", "Ljava/io/OutputStream;", "timeout", "Lokio/Timeout;", "toString", "", "write", "", "source", "Ljava/nio/ByteBuffer;", "", "offset", "byteCount", "", "byteString", "Lokio/ByteString;", "Lokio/Source;", "writeAll", "writeByte", "b", "writeDecimalLong", "v", "writeHexadecimalUnsignedLong", "writeInt", "i", "writeIntLe", "writeLong", "writeLongLe", "writeShort", "s", "writeShortLe", "writeString", "string", "charset", "Ljava/nio/charset/Charset;", "beginIndex", "endIndex", "writeUtf8", "writeUtf8CodePoint", "codePoint", "okio"}, k = 1, mv = {1, 4, 0})
  /* compiled from: RealBufferedSink.kt */
  public final class RealBufferedSink implements BufferedSink {
      public final Buffer bufferField = new Buffer();
      public boolean closed;
      public final Sink sink;
  
      public RealBufferedSink(Sink sink2) {
          Intrinsics.checkNotNullParameter(sink2, "sink");
          this.sink = sink2;
      }
  
      public static /* synthetic */ void getBuffer$annotations() {
      }
  
      public Buffer buffer() {
          return this.bufferField;
      }
  
      public void close() {
          if (!this.closed) {
              Throwable th = null;
              try {
                  if (this.bufferField.size() > 0) {
                      this.sink.write(this.bufferField, this.bufferField.size());
                  }
              } catch (Throwable th2) {
                  th = th2;
              }
              try {
                  this.sink.close();
              } catch (Throwable th3) {
                  if (th == null) {
                      th = th3;
                  }
              }
              this.closed = true;
              if (th != null) {
                  throw th;
              }
          }
      }
  
      public BufferedSink emit() {
          if (!this.closed) {
              long size = this.bufferField.size();
              if (size > 0) {
                  this.sink.write(this.bufferField, size);
              }
              return this;
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink emitCompleteSegments() {
          if (!this.closed) {
              long completeSegmentByteCount = this.bufferField.completeSegmentByteCount();
              if (completeSegmentByteCount > 0) {
                  this.sink.write(this.bufferField, completeSegmentByteCount);
              }
              return this;
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public void flush() {
          if (!this.closed) {
              if (this.bufferField.size() > 0) {
                  this.sink.write(this.bufferField, this.bufferField.size());
              }
              this.sink.flush();
              return;
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public Buffer getBuffer() {
          return this.bufferField;
      }
  
      public boolean isOpen() {
          return !this.closed;
      }
  
      public OutputStream outputStream() {
          return new RealBufferedSink$outputStream$1(this);
      }
  
      public Timeout timeout() {
          return this.sink.timeout();
      }
  
      public String toString() {
          return "buffer(" + this.sink + ')';
      }
  
      public int write(ByteBuffer source) {
          Intrinsics.checkNotNullParameter(source, "source");
          if (!this.closed) {
              int write = this.bufferField.write(source);
              emitCompleteSegments();
              return write;
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink write(ByteString byteString) {
          Intrinsics.checkNotNullParameter(byteString, "byteString");
          if (!this.closed) {
              this.bufferField.write(byteString);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink write(ByteString byteString, int offset, int byteCount) {
          Intrinsics.checkNotNullParameter(byteString, "byteString");
          if (!this.closed) {
              this.bufferField.write(byteString, offset, byteCount);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink write(Source source, long byteCount) {
          Intrinsics.checkNotNullParameter(source, "source");
          long j = byteCount;
          while (j > 0) {
              long read = source.read(this.bufferField, j);
              if (read != -1) {
                  j -= read;
                  emitCompleteSegments();
              } else {
                  throw new EOFException();
              }
          }
          return this;
      }
  
      public BufferedSink write(byte[] source) {
          Intrinsics.checkNotNullParameter(source, "source");
          if (!this.closed) {
              this.bufferField.write(source);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink write(byte[] source, int offset, int byteCount) {
          Intrinsics.checkNotNullParameter(source, "source");
          if (!this.closed) {
              this.bufferField.write(source, offset, byteCount);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public void write(Buffer source, long byteCount) {
          Intrinsics.checkNotNullParameter(source, "source");
          if (!this.closed) {
              this.bufferField.write(source, byteCount);
              emitCompleteSegments();
              return;
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public long writeAll(Source source) {
          Intrinsics.checkNotNullParameter(source, "source");
          long j = 0;
          while (true) {
              long read = source.read(this.bufferField, (long) 8192);
              if (read == -1) {
                  return j;
              }
              j += read;
              emitCompleteSegments();
          }
      }
  
      public BufferedSink writeByte(int b) {
          if (!this.closed) {
              this.bufferField.writeByte(b);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeDecimalLong(long v) {
          if (!this.closed) {
              this.bufferField.writeDecimalLong(v);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeHexadecimalUnsignedLong(long v) {
          if (!this.closed) {
              this.bufferField.writeHexadecimalUnsignedLong(v);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeInt(int i) {
          if (!this.closed) {
              this.bufferField.writeInt(i);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeIntLe(int i) {
          if (!this.closed) {
              this.bufferField.writeIntLe(i);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeLong(long v) {
          if (!this.closed) {
              this.bufferField.writeLong(v);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeLongLe(long v) {
          if (!this.closed) {
              this.bufferField.writeLongLe(v);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeShort(int s) {
          if (!this.closed) {
              this.bufferField.writeShort(s);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeShortLe(int s) {
          if (!this.closed) {
              this.bufferField.writeShortLe(s);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeString(String string, int beginIndex, int endIndex, Charset charset) {
          Intrinsics.checkNotNullParameter(string, TypedValues.Custom.S_STRING);
          Intrinsics.checkNotNullParameter(charset, "charset");
          if (!this.closed) {
              this.bufferField.writeString(string, beginIndex, endIndex, charset);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeString(String string, Charset charset) {
          Intrinsics.checkNotNullParameter(string, TypedValues.Custom.S_STRING);
          Intrinsics.checkNotNullParameter(charset, "charset");
          if (!this.closed) {
              this.bufferField.writeString(string, charset);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeUtf8(String string) {
          Intrinsics.checkNotNullParameter(string, TypedValues.Custom.S_STRING);
          if (!this.closed) {
              this.bufferField.writeUtf8(string);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeUtf8(String string, int beginIndex, int endIndex) {
          Intrinsics.checkNotNullParameter(string, TypedValues.Custom.S_STRING);
          if (!this.closed) {
              this.bufferField.writeUtf8(string, beginIndex, endIndex);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  
      public BufferedSink writeUtf8CodePoint(int codePoint) {
          if (!this.closed) {
              this.bufferField.writeUtf8CodePoint(codePoint);
              return emitCompleteSegments();
          }
          throw new IllegalStateException("closed".toString());
      }
  }
  