Part.java 8.25 KB
package com.squareup.mimecraft;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.LinkedHashMap;
import java.util.Map;
import sd;

public abstract interface Part
{
  public abstract Map<String, String> getHeaders();
  
  public abstract void writeBodyTo(OutputStream paramOutputStream)
    throws IOException;
  
  public static class Builder
  {
    int a;
    private String b;
    private String c;
    private String d;
    private String e;
    private File f;
    private InputStream g;
    private byte[] h;
    private Multipart i;
    private boolean j = false;
    
    private void a()
    {
      if (this.j) {
        throw new IllegalStateException("Only one body per part.");
      }
      this.j = true;
    }
    
    public Builder body(Multipart paramMultipart)
    {
      sd.a(paramMultipart, "Multipart body must not be null.");
      if (this.b != null) {
        throw new IllegalStateException("Content type must not be explicitly set for multipart body.");
      }
      a();
      this.b = null;
      this.i = paramMultipart;
      return this;
    }
    
    public Builder body(File paramFile)
    {
      sd.a(paramFile, "File body must not be null.");
      a();
      this.f = paramFile;
      return this;
    }
    
    public Builder body(InputStream paramInputStream)
    {
      sd.a(paramInputStream, "Stream body must not be null.");
      a();
      this.g = paramInputStream;
      return this;
    }
    
    public Builder body(String paramString)
    {
      sd.a(paramString, "String body must not be null.");
      a();
      try
      {
        byte[] arrayOfByte = paramString.getBytes("UTF-8");
        this.h = arrayOfByte;
        this.a = arrayOfByte.length;
        return this;
      }
      catch (UnsupportedEncodingException localUnsupportedEncodingException)
      {
        throw new IllegalArgumentException("Unable to convert input to UTF-8: " + paramString, localUnsupportedEncodingException);
      }
    }
    
    public Builder body(byte[] paramArrayOfByte)
    {
      sd.a(paramArrayOfByte, "Byte array body must not be null.");
      a();
      this.h = paramArrayOfByte;
      this.a = paramArrayOfByte.length;
      return this;
    }
    
    public Part build()
    {
      LinkedHashMap localLinkedHashMap = new LinkedHashMap();
      if (this.e != null) {
        localLinkedHashMap.put("Content-Disposition", this.e);
      }
      if (this.b != null) {
        localLinkedHashMap.put("Content-Type", this.b);
      }
      if (this.a != 0) {
        localLinkedHashMap.put("Content-Length", Integer.toString(this.a));
      }
      if (this.c != null) {
        localLinkedHashMap.put("Content-Language", this.c);
      }
      if (this.d != null) {
        localLinkedHashMap.put("Content-Transfer-Encoding", this.d);
      }
      if (this.h != null) {
        return new a(localLinkedHashMap, this.h);
      }
      if (this.g != null) {
        return new e(localLinkedHashMap, this.g, (byte)0);
      }
      if (this.f != null) {
        return new b(localLinkedHashMap, this.f, (byte)0);
      }
      if (this.i != null)
      {
        localLinkedHashMap.putAll(this.i.getHeaders());
        return new d(localLinkedHashMap, this.i);
      }
      throw new IllegalStateException("Part required body to be set.");
    }
    
    public Builder contentDisposition(String paramString)
    {
      sd.a(paramString, "Disposition must not be empty.");
      sd.b(this.e, "Disposition header already set.");
      this.e = paramString;
      return this;
    }
    
    public Builder contentEncoding(String paramString)
    {
      sd.a(paramString, "Encoding must not be empty.");
      sd.b(this.d, "Encoding header already set.");
      this.d = paramString;
      return this;
    }
    
    public Builder contentLanguage(String paramString)
    {
      sd.a(paramString, "Language must not be empty.");
      sd.b(this.c, "Language header already set.");
      this.c = paramString;
      return this;
    }
    
    public Builder contentLength(int paramInt)
    {
      if (paramInt <= 0) {
        throw new IllegalStateException("Length must be greater than zero.");
      }
      if (this.a != 0) {
        throw new IllegalStateException("Length header already set.");
      }
      this.a = paramInt;
      return this;
    }
    
    public Builder contentType(String paramString)
    {
      sd.a(paramString, "Type must not be empty.");
      sd.b(this.b, "Type header already set.");
      sd.b(this.i, "Type cannot be set with multipart body.");
      this.b = paramString;
      return this;
    }
    
    static final class a
      extends Part.Builder.c
    {
      private final byte[] a;
      
      a(Map<String, String> paramMap, byte[] paramArrayOfByte)
      {
        super();
        this.a = paramArrayOfByte;
      }
      
      public final void writeBodyTo(OutputStream paramOutputStream)
        throws IOException
      {
        paramOutputStream.write(this.a);
      }
    }
    
    static final class b
      extends Part.Builder.c
    {
      private final File a;
      private final byte[] b = new byte['က'];
      
      private b(Map<String, String> paramMap, File paramFile)
      {
        super();
        this.a = paramFile;
      }
      
      /* Error */
      public final void writeBodyTo(OutputStream paramOutputStream)
        throws IOException
      {
        // Byte code:
        //   0: new 34	java/io/FileInputStream
        //   3: dup
        //   4: aload_0
        //   5: getfield 22	com/squareup/mimecraft/Part$Builder$b:a	Ljava/io/File;
        //   8: invokespecial 37	java/io/FileInputStream:<init>	(Ljava/io/File;)V
        //   11: astore_2
        //   12: aload_2
        //   13: aload_1
        //   14: aload_0
        //   15: getfield 20	com/squareup/mimecraft/Part$Builder$b:b	[B
        //   18: invokestatic 42	sd:a	(Ljava/io/InputStream;Ljava/io/OutputStream;[B)V
        //   21: aload_2
        //   22: invokevirtual 48	java/io/InputStream:close	()V
        //   25: return
        //   26: astore_1
        //   27: aconst_null
        //   28: astore_2
        //   29: aload_2
        //   30: ifnull +7 -> 37
        //   33: aload_2
        //   34: invokevirtual 48	java/io/InputStream:close	()V
        //   37: aload_1
        //   38: athrow
        //   39: astore_1
        //   40: return
        //   41: astore_2
        //   42: goto -5 -> 37
        //   45: astore_1
        //   46: goto -17 -> 29
        // Local variable table:
        //   start	length	slot	name	signature
        //   0	49	0	this	b
        //   0	49	1	paramOutputStream	OutputStream
        //   11	23	2	localFileInputStream	java.io.FileInputStream
        //   41	1	2	localIOException	IOException
        // Exception table:
        //   from	to	target	type
        //   0	12	26	finally
        //   21	25	39	java/io/IOException
        //   33	37	41	java/io/IOException
        //   12	21	45	finally
      }
    }
    
    static abstract class c
      implements Part
    {
      private final Map<String, String> a;
      
      protected c(Map<String, String> paramMap)
      {
        this.a = paramMap;
      }
      
      public Map<String, String> getHeaders()
      {
        return this.a;
      }
    }
    
    static final class d
      extends Part.Builder.c
    {
      private final Part a;
      
      protected d(Map<String, String> paramMap, Part paramPart)
      {
        super();
        this.a = paramPart;
      }
      
      public final void writeBodyTo(OutputStream paramOutputStream)
        throws IOException
      {
        this.a.writeBodyTo(paramOutputStream);
      }
    }
    
    static final class e
      extends Part.Builder.c
    {
      private final InputStream a;
      private final byte[] b = new byte['က'];
      
      private e(Map<String, String> paramMap, InputStream paramInputStream)
      {
        super();
        this.a = paramInputStream;
      }
      
      public final void writeBodyTo(OutputStream paramOutputStream)
        throws IOException
      {
        sd.a(this.a, paramOutputStream, this.b);
      }
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/mimecraft/Part.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */