content: package okio;
  
  import java.io.EOFException;
  import java.io.IOException;
  import java.util.zip.DataFormatException;
  import java.util.zip.Inflater;
  import kotlin.Metadata;
  import kotlin.jvm.internal.Intrinsics;
  
  @Metadata(bv = {1, 0, 3}, d1 = {"\u0000@\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0000\u0018\u00002\u00020\u0001B\u0017\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0001\u0012\u0006\u0010\u0003\u001a\u00020\u0004¢\u0006\u0002\u0010\u0005B\u0017\b\u0000\u0012\u0006\u0010\u0002\u001a\u00020\u0006\u0012\u0006\u0010\u0003\u001a\u00020\u0004¢\u0006\u0002\u0010\u0007J\b\u0010\f\u001a\u00020\rH\u0016J\u0018\u0010\u000e\u001a\u00020\u000f2\u0006\u0010\u0010\u001a\u00020\u00112\u0006\u0010\u0012\u001a\u00020\u000fH\u0016J\u0016\u0010\u0013\u001a\u00020\u000f2\u0006\u0010\u0010\u001a\u00020\u00112\u0006\u0010\u0012\u001a\u00020\u000fJ\u0006\u0010\u0014\u001a\u00020\u000bJ\b\u0010\u0015\u001a\u00020\rH\u0002J\b\u0010\u0016\u001a\u00020\u0017H\u0016R\u000e\u0010\b\u001a\u00020\tX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\u000bX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0003\u001a\u00020\u0004X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0006X\u0004¢\u0006\u0002\n\u0000¨\u0006\u0018"}, d2 = {"Lokio/InflaterSource;", "Lokio/Source;", "source", "inflater", "Ljava/util/zip/Inflater;", "(Lokio/Source;Ljava/util/zip/Inflater;)V", "Lokio/BufferedSource;", "(Lokio/BufferedSource;Ljava/util/zip/Inflater;)V", "bufferBytesHeldByInflater", "", "closed", "", "close", "", "read", "", "sink", "Lokio/Buffer;", "byteCount", "readOrInflate", "refill", "releaseBytesAfterInflate", "timeout", "Lokio/Timeout;", "okio"}, k = 1, mv = {1, 4, 0})
  /* compiled from: InflaterSource.kt */
  public final class InflaterSource implements Source {
      private int bufferBytesHeldByInflater;
      private boolean closed;
      private final Inflater inflater;
      private final BufferedSource source;
  
      public InflaterSource(BufferedSource source2, Inflater inflater2) {
          Intrinsics.checkNotNullParameter(source2, "source");
          Intrinsics.checkNotNullParameter(inflater2, "inflater");
          this.source = source2;
          this.inflater = inflater2;
      }
  
      /* JADX INFO: this call moved to the top of the method (can break code semantics) */
      public InflaterSource(Source source2, Inflater inflater2) {
          this(Okio.buffer(source2), inflater2);
          Intrinsics.checkNotNullParameter(source2, "source");
          Intrinsics.checkNotNullParameter(inflater2, "inflater");
      }
  
      private final void releaseBytesAfterInflate() {
          int i = this.bufferBytesHeldByInflater;
          if (i != 0) {
              int remaining = i - this.inflater.getRemaining();
              this.bufferBytesHeldByInflater -= remaining;
              this.source.skip((long) remaining);
          }
      }
  
      public void close() throws IOException {
          if (!this.closed) {
              this.inflater.end();
              this.closed = true;
              this.source.close();
          }
      }
  
      public long read(Buffer sink, long byteCount) throws IOException {
          Intrinsics.checkNotNullParameter(sink, "sink");
          do {
              long readOrInflate = readOrInflate(sink, byteCount);
              if (readOrInflate > 0) {
                  return readOrInflate;
              }
              if (this.inflater.finished() || this.inflater.needsDictionary()) {
                  return -1;
              }
          } while (!this.source.exhausted());
          throw new EOFException("source exhausted prematurely");
      }
  
      public final long readOrInflate(Buffer sink, long byteCount) throws IOException {
          Intrinsics.checkNotNullParameter(sink, "sink");
          if (!(byteCount >= 0)) {
              throw new IllegalArgumentException(("byteCount < 0: " + byteCount).toString());
          } else if (!(!this.closed)) {
              throw new IllegalStateException("closed".toString());
          } else if (byteCount == 0) {
              return 0;
          } else {
              try {
                  Segment writableSegment$okio = sink.writableSegment$okio(1);
                  int min = (int) Math.min(byteCount, (long) (8192 - writableSegment$okio.limit));
                  refill();
                  int inflate = this.inflater.inflate(writableSegment$okio.data, writableSegment$okio.limit, min);
                  releaseBytesAfterInflate();
                  if (inflate > 0) {
                      writableSegment$okio.limit += inflate;
                      sink.setSize$okio(sink.size() + ((long) inflate));
                      return (long) inflate;
                  }
                  if (writableSegment$okio.pos == writableSegment$okio.limit) {
                      sink.head = writableSegment$okio.pop();
                      SegmentPool.recycle(writableSegment$okio);
                  }
                  return 0;
              } catch (DataFormatException e) {
                  throw new IOException(e);
              }
          }
      }
  
      public final boolean refill() throws IOException {
          if (!this.inflater.needsInput()) {
              return false;
          }
          if (this.source.exhausted()) {
              return true;
          }
          Segment segment = this.source.getBuffer().head;
          Intrinsics.checkNotNull(segment);
          this.bufferBytesHeldByInflater = segment.limit - segment.pos;
          this.inflater.setInput(segment.data, segment.pos, this.bufferBytesHeldByInflater);
          return false;
      }
  
      public Timeout timeout() {
          return this.source.timeout();
      }
  }
  