content: package okhttp3.internal.connection;
  
  import androidx.core.app.NotificationCompat;
  import java.io.IOException;
  import java.net.ProtocolException;
  import java.net.SocketException;
  import kotlin.Metadata;
  import kotlin.jvm.internal.Intrinsics;
  import mt.Log1F380D;
  import okhttp3.EventListener;
  import okhttp3.Headers;
  import okhttp3.Request;
  import okhttp3.RequestBody;
  import okhttp3.Response;
  import okhttp3.ResponseBody;
  import okhttp3.internal.http.ExchangeCodec;
  import okhttp3.internal.http.RealResponseBody;
  import okhttp3.internal.ws.RealWebSocket;
  import okio.Buffer;
  import okio.ForwardingSink;
  import okio.ForwardingSource;
  import okio.Okio;
  import okio.Sink;
  import okio.Source;
  
  @Metadata(bv = {1, 0, 3}, d1 = {"\u0000z\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0010\u000b\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0005\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0005\u0018\u00002\u00020\u0001:\u0002ABB%\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\u0006\u0010\b\u001a\u00020\t¢\u0006\u0002\u0010\nJ7\u0010\u001c\u001a\u0002H\u001d\"\n\b\u0000\u0010\u001d*\u0004\u0018\u00010\u001e2\u0006\u0010\u001f\u001a\u00020 2\u0006\u0010!\u001a\u00020\u00162\u0006\u0010\"\u001a\u00020\u00162\u0006\u0010#\u001a\u0002H\u001d¢\u0006\u0002\u0010$J\u0006\u0010%\u001a\u00020&J\u0016\u0010'\u001a\u00020(2\u0006\u0010)\u001a\u00020*2\u0006\u0010+\u001a\u00020\u0016J\u0006\u0010,\u001a\u00020&J\u0006\u0010-\u001a\u00020&J\u0006\u0010.\u001a\u00020&J\u0006\u0010/\u001a\u000200J\u0006\u00101\u001a\u00020&J\u0006\u00102\u001a\u00020&J\u000e\u00103\u001a\u0002042\u0006\u00105\u001a\u000206J\u0010\u00107\u001a\u0004\u0018\u0001082\u0006\u00109\u001a\u00020\u0016J\u000e\u0010:\u001a\u00020&2\u0006\u00105\u001a\u000206J\u0006\u0010;\u001a\u00020&J\u0010\u0010<\u001a\u00020&2\u0006\u0010#\u001a\u00020\u001eH\u0002J\u0006\u0010=\u001a\u00020>J\u0006\u0010?\u001a\u00020&J\u000e\u0010@\u001a\u00020&2\u0006\u0010)\u001a\u00020*R\u0014\u0010\u0002\u001a\u00020\u0003X\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\fR\u000e\u0010\b\u001a\u00020\tX\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\r\u001a\u00020\u000eX\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u000f\u0010\u0010R\u0014\u0010\u0004\u001a\u00020\u0005X\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0011\u0010\u0012R\u0014\u0010\u0006\u001a\u00020\u0007X\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0013\u0010\u0014R\u0014\u0010\u0015\u001a\u00020\u00168@X\u0004¢\u0006\u0006\u001a\u0004\b\u0017\u0010\u0018R\u001e\u0010\u001a\u001a\u00020\u00162\u0006\u0010\u0019\u001a\u00020\u0016@BX\u000e¢\u0006\b\n\u0000\u001a\u0004\b\u001b\u0010\u0018¨\u0006C"}, d2 = {"Lokhttp3/internal/connection/Exchange;", "", "call", "Lokhttp3/internal/connection/RealCall;", "eventListener", "Lokhttp3/EventListener;", "finder", "Lokhttp3/internal/connection/ExchangeFinder;", "codec", "Lokhttp3/internal/http/ExchangeCodec;", "(Lokhttp3/internal/connection/RealCall;Lokhttp3/EventListener;Lokhttp3/internal/connection/ExchangeFinder;Lokhttp3/internal/http/ExchangeCodec;)V", "getCall$okhttp", "()Lokhttp3/internal/connection/RealCall;", "connection", "Lokhttp3/internal/connection/RealConnection;", "getConnection$okhttp", "()Lokhttp3/internal/connection/RealConnection;", "getEventListener$okhttp", "()Lokhttp3/EventListener;", "getFinder$okhttp", "()Lokhttp3/internal/connection/ExchangeFinder;", "isCoalescedConnection", "", "isCoalescedConnection$okhttp", "()Z", "<set-?>", "isDuplex", "isDuplex$okhttp", "bodyComplete", "E", "Ljava/io/IOException;", "bytesRead", "", "responseDone", "requestDone", "e", "(JZZLjava/io/IOException;)Ljava/io/IOException;", "cancel", "", "createRequestBody", "Lokio/Sink;", "request", "Lokhttp3/Request;", "duplex", "detachWithViolence", "finishRequest", "flushRequest", "newWebSocketStreams", "Lokhttp3/internal/ws/RealWebSocket$Streams;", "noNewExchangesOnConnection", "noRequestBody", "openResponseBody", "Lokhttp3/ResponseBody;", "response", "Lokhttp3/Response;", "readResponseHeaders", "Lokhttp3/Response$Builder;", "expectContinue", "responseHeadersEnd", "responseHeadersStart", "trackFailure", "trailers", "Lokhttp3/Headers;", "webSocketUpgradeFailed", "writeRequestHeaders", "RequestBodySink", "ResponseBodySource", "okhttp"}, k = 1, mv = {1, 4, 0})
  /* compiled from: 01CB */
  public final class Exchange {
      private final RealCall call;
      private final ExchangeCodec codec;
      private final RealConnection connection;
      private final EventListener eventListener;
      private final ExchangeFinder finder;
      private boolean isDuplex;
  
      @Metadata(bv = {1, 0, 3}, d1 = {"\u00008\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0004\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006J\b\u0010\u000b\u001a\u00020\fH\u0016J!\u0010\r\u001a\u0002H\u000e\"\n\b\u0000\u0010\u000e*\u0004\u0018\u00010\u000f2\u0006\u0010\u0010\u001a\u0002H\u000eH\u0002¢\u0006\u0002\u0010\u0011J\b\u0010\u0012\u001a\u00020\fH\u0016J\u0018\u0010\u0013\u001a\u00020\f2\u0006\u0010\u0014\u001a\u00020\u00152\u0006\u0010\u0016\u001a\u00020\u0005H\u0016R\u000e\u0010\u0007\u001a\u00020\u0005X\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\tX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0004\u001a\u00020\u0005X\u0004¢\u0006\u0002\n\u0000¨\u0006\u0017"}, d2 = {"Lokhttp3/internal/connection/Exchange$RequestBodySink;", "Lokio/ForwardingSink;", "delegate", "Lokio/Sink;", "contentLength", "", "(Lokhttp3/internal/connection/Exchange;Lokio/Sink;J)V", "bytesReceived", "closed", "", "completed", "close", "", "complete", "E", "Ljava/io/IOException;", "e", "(Ljava/io/IOException;)Ljava/io/IOException;", "flush", "write", "source", "Lokio/Buffer;", "byteCount", "okhttp"}, k = 1, mv = {1, 4, 0})
      /* compiled from: Exchange.kt */
      private final class RequestBodySink extends ForwardingSink {
          private long bytesReceived;
          private boolean closed;
          private boolean completed;
          private final long contentLength;
          final /* synthetic */ Exchange this$0;
  
          /* JADX INFO: super call moved to the top of the method (can break code semantics) */
          public RequestBodySink(Exchange this$02, Sink delegate, long contentLength2) {
              super(delegate);
              Intrinsics.checkNotNullParameter(delegate, "delegate");
              this.this$0 = this$02;
              this.contentLength = contentLength2;
          }
  
          private final <E extends IOException> E complete(E e) {
              if (this.completed) {
                  return e;
              }
              this.completed = true;
              return this.this$0.bodyComplete(this.bytesReceived, false, true, e);
          }
  
          public void close() throws IOException {
              if (!this.closed) {
                  this.closed = true;
                  long j = this.contentLength;
                  if (j == -1 || this.bytesReceived == j) {
                      try {
                          super.close();
                          complete((IOException) null);
                      } catch (IOException e) {
                          throw complete(e);
                      }
                  } else {
                      throw new ProtocolException("unexpected end of stream");
                  }
              }
          }
  
          public void flush() throws IOException {
              try {
                  super.flush();
              } catch (IOException e) {
                  throw complete(e);
              }
          }
  
          public void write(Buffer source, long byteCount) throws IOException {
              Intrinsics.checkNotNullParameter(source, "source");
              if (!this.closed) {
                  long j = this.contentLength;
                  if (j == -1 || this.bytesReceived + byteCount <= j) {
                      try {
                          super.write(source, byteCount);
                          this.bytesReceived += byteCount;
                      } catch (IOException e) {
                          throw complete(e);
                      }
                  } else {
                      throw new ProtocolException("expected " + this.contentLength + " bytes but received " + (this.bytesReceived + byteCount));
                  }
              } else {
                  throw new IllegalStateException("closed".toString());
              }
          }
      }
  
      @Metadata(bv = {1, 0, 3}, d1 = {"\u00008\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0004\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006J\b\u0010\f\u001a\u00020\rH\u0016J\u001f\u0010\u000e\u001a\u0002H\u000f\"\n\b\u0000\u0010\u000f*\u0004\u0018\u00010\u00102\u0006\u0010\u0011\u001a\u0002H\u000f¢\u0006\u0002\u0010\u0012J\u0018\u0010\u0013\u001a\u00020\u00052\u0006\u0010\u0014\u001a\u00020\u00152\u0006\u0010\u0016\u001a\u00020\u0005H\u0016R\u000e\u0010\u0007\u001a\u00020\u0005X\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\tX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0004\u001a\u00020\u0005X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u000b\u001a\u00020\tX\u000e¢\u0006\u0002\n\u0000¨\u0006\u0017"}, d2 = {"Lokhttp3/internal/connection/Exchange$ResponseBodySource;", "Lokio/ForwardingSource;", "delegate", "Lokio/Source;", "contentLength", "", "(Lokhttp3/internal/connection/Exchange;Lokio/Source;J)V", "bytesReceived", "closed", "", "completed", "invokeStartEvent", "close", "", "complete", "E", "Ljava/io/IOException;", "e", "(Ljava/io/IOException;)Ljava/io/IOException;", "read", "sink", "Lokio/Buffer;", "byteCount", "okhttp"}, k = 1, mv = {1, 4, 0})
      /* compiled from: Exchange.kt */
      public final class ResponseBodySource extends ForwardingSource {
          private long bytesReceived;
          private boolean closed;
          private boolean completed;
          private final long contentLength;
          private boolean invokeStartEvent = true;
          final /* synthetic */ Exchange this$0;
  
          /* JADX INFO: super call moved to the top of the method (can break code semantics) */
          public ResponseBodySource(Exchange this$02, Source delegate, long contentLength2) {
              super(delegate);
              Intrinsics.checkNotNullParameter(delegate, "delegate");
              this.this$0 = this$02;
              this.contentLength = contentLength2;
              if (contentLength2 == 0) {
                  complete((IOException) null);
              }
          }
  
          public void close() throws IOException {
              if (!this.closed) {
                  this.closed = true;
                  try {
                      super.close();
                      complete((IOException) null);
                  } catch (IOException e) {
                      throw complete(e);
                  }
              }
          }
  
          public final <E extends IOException> E complete(E e) {
              if (this.completed) {
                  return e;
              }
              this.completed = true;
              if (e == null && this.invokeStartEvent) {
                  this.invokeStartEvent = false;
                  this.this$0.getEventListener$okhttp().responseBodyStart(this.this$0.getCall$okhttp());
              }
              return this.this$0.bodyComplete(this.bytesReceived, true, false, e);
          }
  
          public long read(Buffer sink, long byteCount) throws IOException {
              Intrinsics.checkNotNullParameter(sink, "sink");
              if (!this.closed) {
                  try {
                      long read = delegate().read(sink, byteCount);
                      if (this.invokeStartEvent) {
                          this.invokeStartEvent = false;
                          this.this$0.getEventListener$okhttp().responseBodyStart(this.this$0.getCall$okhttp());
                      }
                      if (read == -1) {
                          complete((IOException) null);
                          return -1;
                      }
                      long j = this.bytesReceived + read;
                      long j2 = this.contentLength;
                      if (j2 != -1) {
                          if (j > j2) {
                              throw new ProtocolException("expected " + this.contentLength + " bytes but received " + j);
                          }
                      }
                      this.bytesReceived = j;
                      if (j == j2) {
                          complete((IOException) null);
                      }
                      return read;
                  } catch (IOException e) {
                      throw complete(e);
                  }
              } else {
                  throw new IllegalStateException("closed".toString());
              }
          }
      }
  
      public Exchange(RealCall call2, EventListener eventListener2, ExchangeFinder finder2, ExchangeCodec codec2) {
          Intrinsics.checkNotNullParameter(call2, NotificationCompat.CATEGORY_CALL);
          Intrinsics.checkNotNullParameter(eventListener2, "eventListener");
          Intrinsics.checkNotNullParameter(finder2, "finder");
          Intrinsics.checkNotNullParameter(codec2, "codec");
          this.call = call2;
          this.eventListener = eventListener2;
          this.finder = finder2;
          this.codec = codec2;
          this.connection = codec2.getConnection();
      }
  
      private final void trackFailure(IOException e) {
          this.finder.trackFailure(e);
          this.codec.getConnection().trackFailure$okhttp(this.call, e);
      }
  
      public final <E extends IOException> E bodyComplete(long bytesRead, boolean responseDone, boolean requestDone, E e) {
          if (e != null) {
              trackFailure(e);
          }
          if (requestDone) {
              if (e != null) {
                  this.eventListener.requestFailed(this.call, e);
              } else {
                  this.eventListener.requestBodyEnd(this.call, bytesRead);
              }
          }
          if (responseDone) {
              if (e != null) {
                  this.eventListener.responseFailed(this.call, e);
              } else {
                  this.eventListener.responseBodyEnd(this.call, bytesRead);
              }
          }
          return this.call.messageDone$okhttp(this, requestDone, responseDone, e);
      }
  
      public final void cancel() {
          this.codec.cancel();
      }
  
      public final Sink createRequestBody(Request request, boolean duplex) throws IOException {
          Intrinsics.checkNotNullParameter(request, "request");
          this.isDuplex = duplex;
          RequestBody body = request.body();
          Intrinsics.checkNotNull(body);
          long contentLength = body.contentLength();
          this.eventListener.requestBodyStart(this.call);
          return new RequestBodySink(this, this.codec.createRequestBody(request, contentLength), contentLength);
      }
  
      public final void detachWithViolence() {
          this.codec.cancel();
          this.call.messageDone$okhttp(this, true, true, null);
      }
  
      public final void finishRequest() throws IOException {
          try {
              this.codec.finishRequest();
          } catch (IOException e) {
              this.eventListener.requestFailed(this.call, e);
              trackFailure(e);
              throw e;
          }
      }
  
      public final void flushRequest() throws IOException {
          try {
              this.codec.flushRequest();
          } catch (IOException e) {
              this.eventListener.requestFailed(this.call, e);
              trackFailure(e);
              throw e;
          }
      }
  
      public final RealCall getCall$okhttp() {
          return this.call;
      }
  
      public final RealConnection getConnection$okhttp() {
          return this.connection;
      }
  
      public final EventListener getEventListener$okhttp() {
          return this.eventListener;
      }
  
      public final ExchangeFinder getFinder$okhttp() {
          return this.finder;
      }
  
      public final boolean isCoalescedConnection$okhttp() {
          return !Intrinsics.areEqual((Object) this.finder.getAddress$okhttp().url().host(), (Object) this.connection.route().address().url().host());
      }
  
      public final boolean isDuplex$okhttp() {
          return this.isDuplex;
      }
  
      public final RealWebSocket.Streams newWebSocketStreams() throws SocketException {
          this.call.timeoutEarlyExit();
          return this.codec.getConnection().newWebSocketStreams$okhttp(this);
      }
  
      public final void noNewExchangesOnConnection() {
          this.codec.getConnection().noNewExchanges$okhttp();
      }
  
      public final void noRequestBody() {
          this.call.messageDone$okhttp(this, true, false, null);
      }
  
      public final ResponseBody openResponseBody(Response response) throws IOException {
          Intrinsics.checkNotNullParameter(response, "response");
          try {
              String header$default = Response.header$default(response, "Content-Type", (String) null, 2, (Object) null);
              Log1F380D.a((Object) header$default);
              long reportedContentLength = this.codec.reportedContentLength(response);
              return new RealResponseBody(header$default, reportedContentLength, Okio.buffer((Source) new ResponseBodySource(this, this.codec.openResponseBodySource(response), reportedContentLength)));
          } catch (IOException e) {
              this.eventListener.responseFailed(this.call, e);
              trackFailure(e);
              throw e;
          }
      }
  
      public final Response.Builder readResponseHeaders(boolean expectContinue) throws IOException {
          try {
              Response.Builder readResponseHeaders = this.codec.readResponseHeaders(expectContinue);
              if (readResponseHeaders != null) {
                  readResponseHeaders.initExchange$okhttp(this);
              }
              return readResponseHeaders;
          } catch (IOException e) {
              this.eventListener.responseFailed(this.call, e);
              trackFailure(e);
              throw e;
          }
      }
  
      public final void responseHeadersEnd(Response response) {
          Intrinsics.checkNotNullParameter(response, "response");
          this.eventListener.responseHeadersEnd(this.call, response);
      }
  
      public final void responseHeadersStart() {
          this.eventListener.responseHeadersStart(this.call);
      }
  
      public final Headers trailers() throws IOException {
          return this.codec.trailers();
      }
  
      public final void webSocketUpgradeFailed() {
          bodyComplete(-1, true, true, (IOException) null);
      }
  
      public final void writeRequestHeaders(Request request) throws IOException {
          Intrinsics.checkNotNullParameter(request, "request");
          try {
              this.eventListener.requestHeadersStart(this.call);
              this.codec.writeRequestHeaders(request);
              this.eventListener.requestHeadersEnd(this.call, request);
          } catch (IOException e) {
              this.eventListener.requestFailed(this.call, e);
              trackFailure(e);
              throw e;
          }
      }
  }
  