package com.l7tech.common.http.prov.apache.components;

import com.l7tech.common.http.RerunnableHttpRequest;
import com.l7tech.common.io.NonCloseableOutputStream;
import com.l7tech.common.mime.ContentTypeHeader;
import com.l7tech.util.IOUtils;
import com.l7tech.util.ResourceUtils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.zip.GZIPOutputStream;
import org.apache.hc.core5.function.Supplier;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;

final class g implements HttpEntity {
   private final ContentTypeHeader a;
   private final boolean b;
   private final Long c;
   private final InputStream d;
   private final RerunnableHttpRequest.InputStreamFactory e;
   private long f;
   private byte[] g;
   private IOException h;
   private String i;
   private static final String j;

   g(ContentTypeHeader var1, Long var2, boolean var3, InputStream var4) {
      this.a = var1;
      this.c = var2;
      this.b = var3;
      this.d = var4;
      this.e = null;
      this.i = var1 != null ? var1.getEncoding().name() : null;
   }

   g(ContentTypeHeader var1, Long var2, boolean var3, RerunnableHttpRequest.InputStreamFactory var4) {
      this.a = var1;
      this.c = var2;
      this.b = var3;
      this.d = null;
      this.e = var4;
      this.i = var1 != null ? var1.getEncoding().name() : null;
   }

   public boolean isRepeatable() {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 0
      // 01: invokevirtual com/l7tech/common/http/prov/apache/components/g.b ()V
      // 04: aload 0
      // 05: getfield com/l7tech/common/http/prov/apache/components/g.e Lcom/l7tech/common/http/RerunnableHttpRequest$InputStreamFactory;
      // 08: ifnonnull 19
      // 0b: aload 0
      // 0c: getfield com/l7tech/common/http/prov/apache/components/g.g [B
      // 0f: ifnull 21
      // 12: goto 19
      // 15: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 18: athrow
      // 19: bipush 1
      // 1a: goto 22
      // 1d: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 20: athrow
      // 21: bipush 0
      // 22: ireturn
      // try (0 -> 8): 9 java/lang/IllegalStateException
      // try (5 -> 13): 13 java/lang/IllegalStateException
   }

   public boolean isChunked() {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 0
      // 01: getfield com/l7tech/common/http/prov/apache/components/g.c Ljava/lang/Long;
      // 04: ifnull 25
      // 07: aload 0
      // 08: getfield com/l7tech/common/http/prov/apache/components/g.c Ljava/lang/Long;
      // 0b: invokevirtual java/lang/Long.longValue ()J
      // 0e: getstatic com/l7tech/common/http/prov/apache/components/HttpComponentsClient.e I
      // 11: i2l
      // 12: lcmp
      // 13: ifle 25
      // 16: goto 1d
      // 19: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 1c: athrow
      // 1d: bipush 1
      // 1e: goto 26
      // 21: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 24: athrow
      // 25: bipush 0
      // 26: ireturn
      // try (0 -> 10): 11 java/lang/IllegalStateException
      // try (3 -> 15): 15 java/lang/IllegalStateException
   }

   public Set<String> getTrailerNames() {
      return Collections.emptySet();
   }

   public void writeTo(OutputStream var1) throws IOException {
      try {
         this.b();
         if (this.g != null) {
            IOUtils.copyStream(new ByteArrayInputStream(this.a()), var1);
            return;
         }
      } catch (IOException var7) {
         throw a(var7);
      }

      if (this.e != null) {
         InputStream var2 = null;

         try {
            var2 = this.e.getInputStream();
            this.a(var2, var1);
         } finally {
            ResourceUtils.closeQuietly(var2);
         }
      } else {
         this.a(this.d, var1);
      }
   }

   public boolean isStreaming() {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 0
      // 01: invokevirtual com/l7tech/common/http/prov/apache/components/g.b ()V
      // 04: aload 0
      // 05: getfield com/l7tech/common/http/prov/apache/components/g.e Lcom/l7tech/common/http/RerunnableHttpRequest$InputStreamFactory;
      // 08: ifnonnull 19
      // 0b: aload 0
      // 0c: getfield com/l7tech/common/http/prov/apache/components/g.g [B
      // 0f: ifnull 21
      // 12: goto 19
      // 15: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 18: athrow
      // 19: bipush 1
      // 1a: goto 22
      // 1d: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 20: athrow
      // 21: bipush 0
      // 22: ireturn
      // try (0 -> 8): 9 java/lang/IllegalStateException
      // try (5 -> 13): 13 java/lang/IllegalStateException
   }

   public Supplier<List<? extends Header>> getTrailers() {
      return null;
   }

   public long getContentLength() {
      this.b();
      return this.f;
   }

   public String getContentType() {
      try {
         if (this.a != null) {
            return this.a.getFullValue();
         }
      } catch (IllegalStateException var1) {
         throw a(var1);
      }

      return null;
   }

   public String getContentEncoding() {
      return this.i;
   }

   public void setContentEncoding(String var1) {
      this.i = var1;
   }

   public InputStream getContent() throws IOException, IllegalStateException {
      return this.d;
   }

   private void a(InputStream var1, OutputStream var2) throws IOException {
      if (this.b) {
         GZIPOutputStream var3 = null;

         try {
            var3 = new GZIPOutputStream(new NonCloseableOutputStream(var2));
            IOUtils.copyStream(var1, var3);
            var3.flush();
         } finally {
            ResourceUtils.closeQuietly(var3);
         }
      } else {
         IOUtils.copyStream(var1, var2);
      }
   }

   private byte[] a() throws IOException {
      try {
         if (this.h != null) {
            throw this.h;
         }
      } catch (IOException var1) {
         throw a(var1);
      }

      return this.g;
   }

   private void b() {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 0
      // 01: getfield com/l7tech/common/http/prov/apache/components/g.b Z
      // 04: ifeq b4
      // 07: aload 0
      // 08: getfield com/l7tech/common/http/prov/apache/components/g.g [B
      // 0b: ifnonnull 9f
      // 0e: goto 15
      // 11: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 14: athrow
      // 15: aload 0
      // 16: getfield com/l7tech/common/http/prov/apache/components/g.c Ljava/lang/Long;
      // 19: ifnull 9f
      // 1c: goto 23
      // 1f: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 22: athrow
      // 23: aload 0
      // 24: getfield com/l7tech/common/http/prov/apache/components/g.c Ljava/lang/Long;
      // 27: invokevirtual java/lang/Long.longValue ()J
      // 2a: getstatic com/l7tech/common/http/prov/apache/components/HttpComponentsClient.e I
      // 2d: i2l
      // 2e: lcmp
      // 2f: ifgt 9f
      // 32: goto 39
      // 35: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 38: athrow
      // 39: aload 0
      // 3a: getfield com/l7tech/common/http/prov/apache/components/g.e Lcom/l7tech/common/http/RerunnableHttpRequest$InputStreamFactory;
      // 3d: ifnull 65
      // 40: aconst_null
      // 41: astore 1
      // 42: aload 0
      // 43: getfield com/l7tech/common/http/prov/apache/components/g.e Lcom/l7tech/common/http/RerunnableHttpRequest$InputStreamFactory;
      // 46: invokeinterface com/l7tech/common/http/RerunnableHttpRequest$InputStreamFactory.getInputStream ()Ljava/io/InputStream; 1
      // 4b: astore 1
      // 4c: aload 0
      // 4d: aload 1
      // 4e: invokestatic com/l7tech/util/IOUtils.compressGzip (Ljava/io/InputStream;)[B
      // 51: putfield com/l7tech/common/http/prov/apache/components/g.g [B
      // 54: aload 1
      // 55: invokestatic com/l7tech/util/ResourceUtils.closeQuietly (Ljava/io/Closeable;)V
      // 58: goto 62
      // 5b: astore 2
      // 5c: aload 1
      // 5d: invokestatic com/l7tech/util/ResourceUtils.closeQuietly (Ljava/io/Closeable;)V
      // 60: aload 2
      // 61: athrow
      // 62: goto 70
      // 65: aload 0
      // 66: aload 0
      // 67: getfield com/l7tech/common/http/prov/apache/components/g.d Ljava/io/InputStream;
      // 6a: invokestatic com/l7tech/util/IOUtils.compressGzip (Ljava/io/InputStream;)[B
      // 6d: putfield com/l7tech/common/http/prov/apache/components/g.g [B
      // 70: aload 0
      // 71: aload 0
      // 72: getfield com/l7tech/common/http/prov/apache/components/g.g [B
      // 75: arraylength
      // 76: i2l
      // 77: putfield com/l7tech/common/http/prov/apache/components/g.f J
      // 7a: aload 0
      // 7b: getstatic com/l7tech/common/http/prov/apache/components/g.j Ljava/lang/String;
      // 7e: invokevirtual com/l7tech/common/http/prov/apache/components/g.setContentEncoding (Ljava/lang/String;)V
      // 81: goto d0
      // 84: astore 1
      // 85: aload 0
      // 86: bipush 0
      // 87: newarray 8
      // 89: putfield com/l7tech/common/http/prov/apache/components/g.g [B
      // 8c: aload 0
      // 8d: aload 1
      // 8e: putfield com/l7tech/common/http/prov/apache/components/g.h Ljava/io/IOException;
      // 91: aload 0
      // 92: aload 0
      // 93: getfield com/l7tech/common/http/prov/apache/components/g.c Ljava/lang/Long;
      // 96: invokevirtual java/lang/Long.longValue ()J
      // 99: putfield com/l7tech/common/http/prov/apache/components/g.f J
      // 9c: goto d0
      // 9f: aload 0
      // a0: getfield com/l7tech/common/http/prov/apache/components/g.g [B
      // a3: ifnonnull d0
      // a6: aload 0
      // a7: ldc2_w -1
      // aa: putfield com/l7tech/common/http/prov/apache/components/g.f J
      // ad: goto d0
      // b0: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // b3: athrow
      // b4: aload 0
      // b5: aload 0
      // b6: getfield com/l7tech/common/http/prov/apache/components/g.c Ljava/lang/Long;
      // b9: ifnonnull c6
      // bc: ldc2_w -1
      // bf: goto cd
      // c2: invokestatic com/l7tech/common/http/prov/apache/components/g.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // c5: athrow
      // c6: aload 0
      // c7: getfield com/l7tech/common/http/prov/apache/components/g.c Ljava/lang/Long;
      // ca: invokevirtual java/lang/Long.longValue ()J
      // cd: putfield com/l7tech/common/http/prov/apache/components/g.f J
      // d0: return
      // try (9 -> 22): 23 java/io/IOException
      // try (3 -> 12): 13 java/io/IOException
      // try (0 -> 6): 7 java/io/IOException
      // try (30 -> 38): 41 null
      // try (25 -> 61): 62 java/io/IOException
      // try (76 -> 83): 83 java/io/IOException
      // try (85 -> 91): 91 java/io/IOException
   }

   public void close() {
      ResourceUtils.closeQuietly(this.d);
   }

   private static Exception a(Exception var0) {
      return var0;
   }

   static {
      String var10002 = a(21, a("\u000e(lz"));
      byte var10001 = -1;
      j = var10002;
   }

   private static char[] a(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 35);
      }

      return var10000;
   }

   private static String a(int var0, char[] var1) {
      int var10003 = var1.length;
      int var10002 = var0;
      char[] var10001 = var1;
      int var10000 = var10003;

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 124;
            case 1 -> 71;
            case 2 -> 16;
            case 3 -> 31;
            case 4 -> 3;
            case 5 -> 117;
            default -> 35;
         });
      }

      return new String(var10001).intern();
   }
}
