FormEncoding.java 1.9 KB
package com.squareup.mimecraft;

import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.Map;

public final class FormEncoding
  implements Part
{
  private static final Map<String, String> a = Collections.singletonMap("Content-Type", "application/x-www-form-urlencoded");
  private final byte[] b;
  
  private FormEncoding(String paramString)
  {
    try
    {
      this.b = paramString.getBytes("UTF-8");
      return;
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      throw new IllegalArgumentException("Unable to convert input to UTF-8: " + paramString, localUnsupportedEncodingException);
    }
  }
  
  public final Map<String, String> getHeaders()
  {
    return a;
  }
  
  public final void writeBodyTo(OutputStream paramOutputStream)
    throws IOException
  {
    paramOutputStream.write(this.b);
  }
  
  public static class Builder
  {
    private final StringBuilder a = new StringBuilder();
    
    public Builder add(String paramString1, String paramString2)
    {
      if (this.a.length() > 0) {
        this.a.append('&');
      }
      try
      {
        this.a.append(URLEncoder.encode(paramString1, "UTF-8")).append('=').append(URLEncoder.encode(paramString2, "UTF-8"));
        return this;
      }
      catch (UnsupportedEncodingException paramString1)
      {
        throw new AssertionError(paramString1);
      }
    }
    
    public FormEncoding build()
    {
      if (this.a.length() == 0) {
        throw new IllegalStateException("Form encoded body must have at least one part.");
      }
      return new FormEncoding(this.a.toString(), (byte)0);
    }
  }
}


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