package com.l7tech.message;

import com.l7tech.common.mime.ContentTypeHeader;
import com.l7tech.common.mime.MimeHeader;
import com.l7tech.common.mime.MimeHeaders;
import com.l7tech.common.mime.NoSuchPartException;
import com.l7tech.common.mime.PartInfo;
import java.io.IOException;
import java.io.InputStream;
import org.w3c.dom.Document;

class k implements PartInfo {
   private final PartInfo a;
   private final boolean b;
   final j this$1;

   private k(j var1, PartInfo var2) {
      this.this$1 = var1;
      this.a = var2;
      this.b = var2.getPosition() == 0;
   }

   public MimeHeader getHeader(String var1) {
      return this.a.getHeader(var1);
   }

   public int getPosition() {
      return this.a.getPosition();
   }

   public InputStream getInputStream(boolean var1) throws IOException, NoSuchPartException {
      try {
         if (this.b) {
            this.this$1.a();
         }
      } catch (IOException var2) {
         throw a(var2);
      }

      return this.a.getInputStream(var1);
   }

   public byte[] getBytesIfAlreadyAvailable() {
      return this.b && !this.this$1.this$0.e ? null : this.a.getBytesIfAlreadyAvailable();
   }

   public byte[] getBytesIfAvailableOrSmallerThan(int param1) throws IOException, NoSuchPartException {
      // $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/message/k.b Z
      // 04: ifeq 21
      // 07: aload 0
      // 08: getfield com/l7tech/message/k.this$1 Lcom/l7tech/message/j;
      // 0b: getfield com/l7tech/message/j.this$0 Lcom/l7tech/message/XmlFacet;
      // 0e: getfield com/l7tech/message/XmlFacet.e Z
      // 11: ifne 21
      // 14: goto 1b
      // 17: invokestatic com/l7tech/message/k.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 1a: athrow
      // 1b: aconst_null
      // 1c: areturn
      // 1d: invokestatic com/l7tech/message/k.a (Ljava/io/IOException;)Ljava/io/IOException;
      // 20: athrow
      // 21: aload 0
      // 22: getfield com/l7tech/message/k.a Lcom/l7tech/common/mime/PartInfo;
      // 25: iload 1
      // 26: invokeinterface com/l7tech/common/mime/PartInfo.getBytesIfAvailableOrSmallerThan (I)[B 2
      // 2b: areturn
      // try (0 -> 8): 9 java/io/IOException
      // try (3 -> 13): 13 java/io/IOException
   }

   public void setBodyBytes(byte[] var1) throws IOException {
      try {
         this.a.setBodyBytes(var1);
         if (this.b) {
            this.a();
         }
      } catch (IOException var2) {
         throw a(var2);
      }
   }

   public void setBodyBytes(byte[] var1, int var2, int var3) throws IOException {
      try {
         this.a.setBodyBytes(var1, var2, var3);
         if (this.b) {
            this.a();
         }
      } catch (IOException var4) {
         throw a(var4);
      }
   }

   private void a() {
      if (this.this$1.this$0.d != null && this.this$1.this$0.c == null && this.this$1.this$0.getMessage().isEnableOriginalDocument()) {
         this.this$1.this$0.c = (Document)this.this$1.this$0.d.getDocument().cloneNode(true);
      }

      this.this$1.this$0.d = null;
      this.this$1.this$0.e = false;
      this.this$1.this$0.getMessage().b();
   }

   public void setContentType(ContentTypeHeader var1) {
      this.a.setContentType(var1);
      if (this.b && !var1.isXml()) {
         this.a();
      }
   }

   public MimeHeaders getHeaders() {
      return this.a.getHeaders();
   }

   public long getContentLength() {
      return this.b && !this.this$1.this$0.e ? -1L : this.a.getContentLength();
   }

   public long getActualContentLength() throws IOException, NoSuchPartException {
      try {
         if (this.b) {
            this.this$1.a();
         }
      } catch (IOException var1) {
         throw a(var1);
      }

      return this.a.getActualContentLength();
   }

   public ContentTypeHeader getContentType() {
      return this.a.getContentType();
   }

   public String getContentId(boolean var1) {
      return this.a.getContentId(var1);
   }

   public boolean isValidated() {
      return this.a.isValidated();
   }

   public void setValidated(boolean var1) {
      this.a.setValidated(var1);
   }

   public boolean isBodyAvailable() {
      return this.a.isBodyAvailable();
   }

   public boolean isBodyStashed() {
      return this.a.isBodyStashed();
   }

   public boolean isBodyRead() {
      return this.a.isBodyRead();
   }

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