package com.l7tech.common.http;

import com.l7tech.common.io.ByteLimitInputStream;
import com.l7tech.util.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class SimpleHttpClient implements GenericHttpClient {
   private final GenericHttpClient a;
   private final int b;
   private static final String[] c;

   public SimpleHttpClient(GenericHttpClient var1) {
      this(var1, 0);
   }

   public SimpleHttpClient(GenericHttpClient var1, int var2) {
      if (var1 == null) {
         throw new NullPointerException();
      }

      this.a = var1;
      this.b = var2;
   }

   @Override
   public GenericHttpRequest createRequest(HttpMethod var1, GenericHttpRequestParams var2) throws GenericHttpException {
      return this.a.createRequest(var1, var2);
   }

   public SimpleHttpClient.SimpleHttpResponse get(GenericHttpRequestParams var1) throws GenericHttpException {
      try {
         GenericHttpRequest var2 = this.createRequest(HttpMethod.GET, var1);

         f var6;
         try {
            GenericHttpResponse var3 = var2.getResponse();

            try {
               InputStream var4 = var3.getInputStream();

               try {
                  byte[] var10000;
                  label82: {
                     try {
                        if (this.b <= 0) {
                           var10000 = IOUtils.slurpStream(var4);
                           break label82;
                        }
                     } catch (Throwable var12) {
                        throw a(var12);
                     }

                     var10000 = IOUtils.slurpStream(new ByteLimitInputStream(var4, 1024, this.b));
                  }

                  byte[] var5 = var10000;
                  var6 = new f(var3, var5);
               } catch (Throwable var13) {
                  if (var4 != null) {
                     try {
                        var4.close();
                     } catch (Throwable var9) {
                        var13.addSuppressed(var9);
                     }
                  }

                  throw var13;
               }

               try {
                  if (var4 != null) {
                     var4.close();
                  }
               } catch (Throwable var11) {
                  throw a(var11);
               }
            } catch (Throwable var14) {
               if (var3 != null) {
                  try {
                     var3.close();
                  } catch (Throwable var8) {
                     var14.addSuppressed(var8);
                  }
               }

               throw var14;
            }

            try {
               if (var3 != null) {
                  var3.close();
               }
            } catch (Throwable var15) {
               throw a(var15);
            }
         } catch (Throwable var16) {
            if (var2 != null) {
               try {
                  var2.close();
               } catch (Throwable var7) {
                  var16.addSuppressed(var7);
               }
            }

            throw var16;
         }

         try {
            if (var2 != null) {
               var2.close();
            }

            return var6;
         } catch (Throwable var10) {
            throw a(var10);
         }
      } catch (IOException var17) {
         throw new GenericHttpException(var17);
      }
   }

   public SimpleHttpClient.SimpleHttpResponse get(String var1) throws GenericHttpException {
      try {
         if (var1 == null) {
            throw new GenericHttpException(c[1]);
         }
      } catch (MalformedURLException var5) {
         throw a(var5);
      }

      try {
         return this.get(new GenericHttpRequestParams(new URL(var1)));
      } catch (MalformedURLException var4) {
         String[] var3 = c;
         throw new GenericHttpException(var3[0] + var1 + var3[2]);
      }
   }

   public GenericHttpRequest post(GenericHttpRequestParams var1) throws GenericHttpException {
      return this.createRequest(HttpMethod.POST, var1);
   }

   public SimpleHttpClient.SimpleHttpResponse post(GenericHttpRequestParams param1, byte[] param2) throws GenericHttpException {
      // $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 1
      // 01: ifnull 0f
      // 04: aload 2
      // 05: ifnonnull 1b
      // 08: goto 0f
      // 0b: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 0e: athrow
      // 0f: new java/lang/NullPointerException
      // 12: dup
      // 13: invokespecial java/lang/NullPointerException.<init> ()V
      // 16: athrow
      // 17: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 1a: athrow
      // 1b: aconst_null
      // 1c: astore 3
      // 1d: aconst_null
      // 1e: astore 4
      // 20: aconst_null
      // 21: astore 5
      // 23: aload 0
      // 24: getstatic com/l7tech/common/http/HttpMethod.POST Lcom/l7tech/common/http/HttpMethod;
      // 27: aload 1
      // 28: invokevirtual com/l7tech/common/http/SimpleHttpClient.createRequest (Lcom/l7tech/common/http/HttpMethod;Lcom/l7tech/common/http/GenericHttpRequestParams;)Lcom/l7tech/common/http/GenericHttpRequest;
      // 2b: astore 3
      // 2c: aload 3
      // 2d: new java/io/ByteArrayInputStream
      // 30: dup
      // 31: aload 2
      // 32: invokespecial java/io/ByteArrayInputStream.<init> ([B)V
      // 35: invokeinterface com/l7tech/common/http/GenericHttpRequest.setInputStream (Ljava/io/InputStream;)V 2
      // 3a: aload 3
      // 3b: invokeinterface com/l7tech/common/http/GenericHttpRequest.getResponse ()Lcom/l7tech/common/http/GenericHttpResponse; 1
      // 40: astore 4
      // 42: aload 4
      // 44: invokevirtual com/l7tech/common/http/GenericHttpResponse.getInputStream ()Ljava/io/InputStream;
      // 47: astore 5
      // 49: aload 5
      // 4b: invokestatic com/l7tech/util/IOUtils.slurpStream (Ljava/io/InputStream;)[B
      // 4e: astore 6
      // 50: new com/l7tech/common/http/f
      // 53: dup
      // 54: aload 4
      // 56: aload 6
      // 58: invokespecial com/l7tech/common/http/f.<init> (Lcom/l7tech/common/http/GenericHttpResponseParams;[B)V
      // 5b: astore 7
      // 5d: aload 4
      // 5f: ifnull 6e
      // 62: aload 4
      // 64: invokevirtual com/l7tech/common/http/GenericHttpResponse.close ()V
      // 67: goto 6e
      // 6a: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 6d: athrow
      // 6e: aload 3
      // 6f: ifnull 7f
      // 72: aload 3
      // 73: invokeinterface com/l7tech/common/http/GenericHttpRequest.close ()V 1
      // 78: goto 7f
      // 7b: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 7e: athrow
      // 7f: aload 5
      // 81: invokestatic com/l7tech/util/ResourceUtils.closeQuietly (Ljava/io/Closeable;)V
      // 84: aload 7
      // 86: areturn
      // 87: astore 6
      // 89: new com/l7tech/common/http/GenericHttpException
      // 8c: dup
      // 8d: aload 6
      // 8f: invokespecial com/l7tech/common/http/GenericHttpException.<init> (Ljava/lang/Throwable;)V
      // 92: athrow
      // 93: astore 8
      // 95: aload 4
      // 97: ifnull a6
      // 9a: aload 4
      // 9c: invokevirtual com/l7tech/common/http/GenericHttpResponse.close ()V
      // 9f: goto a6
      // a2: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // a5: athrow
      // a6: aload 3
      // a7: ifnull b7
      // aa: aload 3
      // ab: invokeinterface com/l7tech/common/http/GenericHttpRequest.close ()V 1
      // b0: goto b7
      // b3: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // b6: athrow
      // b7: aload 5
      // b9: invokestatic com/l7tech/util/ResourceUtils.closeQuietly (Ljava/io/Closeable;)V
      // bc: aload 8
      // be: athrow
      // try (2 -> 11): 11 java/io/IOException
      // try (0 -> 4): 5 java/io/IOException
      // try (19 -> 45): 63 java/io/IOException
      // try (19 -> 45): 69 null
      // try (52 -> 56): 57 java/io/IOException
      // try (45 -> 49): 50 java/io/IOException
      // try (63 -> 70): 69 null
      // try (70 -> 74): 75 java/io/IOException
      // try (77 -> 81): 82 java/io/IOException
   }

   public SimpleHttpClient.SimpleXmlResponse postXml(GenericHttpRequestParams param1, Document param2) throws GenericHttpException, SAXException {
      // $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:
      // 000: aload 1
      // 001: ifnull 00f
      // 004: aload 2
      // 005: ifnonnull 01b
      // 008: goto 00f
      // 00b: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 00e: athrow
      // 00f: new java/lang/NullPointerException
      // 012: dup
      // 013: invokespecial java/lang/NullPointerException.<init> ()V
      // 016: athrow
      // 017: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 01a: athrow
      // 01b: aconst_null
      // 01c: astore 3
      // 01d: aconst_null
      // 01e: astore 4
      // 020: aload 1
      // 021: invokevirtual com/l7tech/common/http/GenericHttpRequestParams.getContentType ()Lcom/l7tech/common/mime/ContentTypeHeader;
      // 024: ifnonnull 035
      // 027: aload 1
      // 028: getstatic com/l7tech/common/mime/ContentTypeHeader.XML_DEFAULT Lcom/l7tech/common/mime/ContentTypeHeader;
      // 02b: invokevirtual com/l7tech/common/http/GenericHttpRequestParams.setContentType (Lcom/l7tech/common/mime/ContentTypeHeader;)V
      // 02e: goto 035
      // 031: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 034: athrow
      // 035: aload 2
      // 036: invokestatic com/l7tech/common/io/XmlUtil.nodeToString (Lorg/w3c/dom/Node;)Ljava/lang/String;
      // 039: aload 1
      // 03a: invokevirtual com/l7tech/common/http/GenericHttpRequestParams.getContentType ()Lcom/l7tech/common/mime/ContentTypeHeader;
      // 03d: invokevirtual com/l7tech/common/mime/ContentTypeHeader.getEncoding ()Ljava/nio/charset/Charset;
      // 040: invokevirtual java/lang/String.getBytes (Ljava/nio/charset/Charset;)[B
      // 043: astore 5
      // 045: aload 0
      // 046: getstatic com/l7tech/common/http/HttpMethod.POST Lcom/l7tech/common/http/HttpMethod;
      // 049: aload 1
      // 04a: invokevirtual com/l7tech/common/http/SimpleHttpClient.createRequest (Lcom/l7tech/common/http/HttpMethod;Lcom/l7tech/common/http/GenericHttpRequestParams;)Lcom/l7tech/common/http/GenericHttpRequest;
      // 04d: astore 3
      // 04e: aload 3
      // 04f: new java/io/ByteArrayInputStream
      // 052: dup
      // 053: aload 5
      // 055: invokespecial java/io/ByteArrayInputStream.<init> ([B)V
      // 058: invokeinterface com/l7tech/common/http/GenericHttpRequest.setInputStream (Ljava/io/InputStream;)V 2
      // 05d: aload 3
      // 05e: invokeinterface com/l7tech/common/http/GenericHttpRequest.getResponse ()Lcom/l7tech/common/http/GenericHttpResponse; 1
      // 063: astore 4
      // 065: aload 4
      // 067: invokevirtual com/l7tech/common/http/GenericHttpResponse.getContentType ()Lcom/l7tech/common/mime/ContentTypeHeader;
      // 06a: astore 6
      // 06c: aload 6
      // 06e: ifnonnull 082
      // 071: new org/xml/sax/SAXException
      // 074: dup
      // 075: getstatic com/l7tech/common/http/SimpleHttpClient.c [Ljava/lang/String;
      // 078: bipush 4
      // 079: aaload
      // 07a: invokespecial org/xml/sax/SAXException.<init> (Ljava/lang/String;)V
      // 07d: athrow
      // 07e: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 081: athrow
      // 082: aload 6
      // 084: invokevirtual com/l7tech/common/mime/ContentTypeHeader.isXml ()Z
      // 087: ifne 0a6
      // 08a: new org/xml/sax/SAXException
      // 08d: dup
      // 08e: aload 6
      // 090: invokevirtual com/l7tech/common/mime/ContentTypeHeader.getFullValue ()Ljava/lang/String;
      // 093: getstatic com/l7tech/common/http/SimpleHttpClient.c [Ljava/lang/String;
      // 096: bipush 3
      // 097: aaload
      // 098: swap
      // 099: invokedynamic makeConcatWithConstants (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; bsm=java/lang/invoke/StringConcatFactory.makeConcatWithConstants (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite; args=[ "\u0001\u0001" ]
      // 09e: invokespecial org/xml/sax/SAXException.<init> (Ljava/lang/String;)V
      // 0a1: athrow
      // 0a2: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 0a5: athrow
      // 0a6: aload 4
      // 0a8: invokevirtual com/l7tech/common/http/GenericHttpResponse.getInputStream ()Ljava/io/InputStream;
      // 0ab: invokestatic com/l7tech/common/io/XmlUtil.parse (Ljava/io/InputStream;)Lorg/w3c/dom/Document;
      // 0ae: astore 7
      // 0b0: new com/l7tech/common/http/g
      // 0b3: dup
      // 0b4: aload 4
      // 0b6: aload 7
      // 0b8: invokespecial com/l7tech/common/http/g.<init> (Lcom/l7tech/common/http/GenericHttpResponseParams;Lorg/w3c/dom/Document;)V
      // 0bb: astore 8
      // 0bd: aload 4
      // 0bf: ifnull 0ce
      // 0c2: aload 4
      // 0c4: invokevirtual com/l7tech/common/http/GenericHttpResponse.close ()V
      // 0c7: goto 0ce
      // 0ca: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 0cd: athrow
      // 0ce: aload 3
      // 0cf: ifnull 0df
      // 0d2: aload 3
      // 0d3: invokeinterface com/l7tech/common/http/GenericHttpRequest.close ()V 1
      // 0d8: goto 0df
      // 0db: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 0de: athrow
      // 0df: aload 8
      // 0e1: areturn
      // 0e2: astore 5
      // 0e4: new com/l7tech/common/http/GenericHttpException
      // 0e7: dup
      // 0e8: aload 5
      // 0ea: invokespecial com/l7tech/common/http/GenericHttpException.<init> (Ljava/lang/Throwable;)V
      // 0ed: athrow
      // 0ee: astore 9
      // 0f0: aload 4
      // 0f2: ifnull 101
      // 0f5: aload 4
      // 0f7: invokevirtual com/l7tech/common/http/GenericHttpResponse.close ()V
      // 0fa: goto 101
      // 0fd: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 100: athrow
      // 101: aload 3
      // 102: ifnull 112
      // 105: aload 3
      // 106: invokeinterface com/l7tech/common/http/GenericHttpRequest.close ()V 1
      // 10b: goto 112
      // 10e: invokestatic com/l7tech/common/http/SimpleHttpClient.a (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 111: athrow
      // 112: aload 9
      // 114: athrow
      // try (61 -> 75): 75 java/io/IOException
      // try (50 -> 59): 59 java/io/IOException
      // try (17 -> 23): 24 java/io/IOException
      // try (2 -> 11): 11 java/io/IOException
      // try (0 -> 4): 5 java/io/IOException
      // try (26 -> 87): 103 java/io/IOException
      // try (26 -> 87): 109 null
      // try (94 -> 98): 99 java/io/IOException
      // try (87 -> 91): 92 java/io/IOException
      // try (103 -> 110): 109 null
      // try (110 -> 114): 115 java/io/IOException
      // try (117 -> 121): 122 java/io/IOException
   }

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

   static {
      String[] var5 = new String[5];
      int var3 = 0;
      String var2 = "B^}ct\u0016A+eYN8X\u000bFYxqq\u0011B+eYN\u0002,\u001e";
      int var4 = "B^}ct\u0016A+eYN8X\u000bFYxqq\u0011B+eYN\u0002,\u001e".length();
      char var1 = '\r';
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 86;
         String var10001 = var2.substring(++var7, var7 + var1);
         byte var10002 = -1;

         while (true) {
            String var8 = a(var10000, a(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var8;
                  if ((var7 += var1) >= var4) {
                     c = var5;
                     return;
                  }

                  var1 = var2.charAt(var7);
                  break;
               default:
                  var5[var3++] = var8;
                  if ((var7 += var1) < var4) {
                     var1 = var2.charAt(var7);
                     continue label24;
                  }

                  var2 = "L@mgb\u0004C{\u0005xeb\u0007\u0010m@lah\u0018\u0010iDm7c\u0005^3}S[-\t_pQ{yyJDgU{--:L@mgb\u0004C{\u0005xeb\u0007\u0010m@lah\u0018\u0010zLz7c\u0005D>Lpta\u001fT{\u0005\u007f7N\u0005^j@pc >In@>\u007fh\u000bT{W";
                  var4 = "L@mgb\u0004C{\u0005xeb\u0007\u0010m@lah\u0018\u0010iDm7c\u0005^3}S[-\t_pQ{yyJDgU{--:L@mgb\u0004C{\u0005xeb\u0007\u0010m@lah\u0018\u0010zLz7c\u0005D>Lpta\u001fT{\u0005\u007f7N\u0005^j@pc >In@>\u007fh\u000bT{W"
                     .length();
                  var1 = '/';
                  var7 = -1;
            }

            var10000 = 67;
            var10001 = var2.substring(++var7, var7 + var1);
            var10002 = 0;
         }
      }
   }

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

      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 -> 93;
            case 1 -> 102;
            case 2 -> 93;
            case 3 -> 84;
            case 4 -> 78;
            case 5 -> 41;
            default -> 115;
         });
      }

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

   public interface SimpleHttpResponse extends GenericHttpResponseParams {
      byte[] getBytes();

      String getString() throws IOException;
   }

   public interface SimpleXmlResponse extends GenericHttpResponseParams {
      Document getDocument();
   }
}
