httpmime-4.3.5

16:36:48.316 INFO  jd.cli.Main - Decompiling httpmime-4.3.5.jar
package org.apache.http.entity.mime;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Random;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.entity.mime.content.ContentBody;

@Deprecated
public class MultipartEntity
  implements HttpEntity
{
  private static final char[] MULTIPART_CHARS = "-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
  private final MultipartEntityBuilder builder;
  private volatile MultipartFormEntity entity;
  
  public MultipartEntity(HttpMultipartMode mode, String boundary, Charset charset)
  {
    builder = new MultipartEntityBuilder().setMode(mode).setCharset(charset).setBoundary(boundary);
    
    entity = null;
  }
  
  public MultipartEntity(HttpMultipartMode mode)
  {
    this(mode, null, null);
  }
  
  public MultipartEntity()
  {
    this(HttpMultipartMode.STRICT, null, null);
  }
  
  protected String generateContentType(String boundary, Charset charset)
  {
    StringBuilder buffer = new StringBuilder();
    buffer.append("multipart/form-data; boundary=");
    buffer.append(boundary);
    if (charset != null)
    {
      buffer.append("; charset=");
      buffer.append(charset.name());
    }
    return buffer.toString();
  }
  
  protected String generateBoundary()
  {
    StringBuilder buffer = new StringBuilder();
    Random rand = new Random();
    int count = rand.nextInt(11) + 30;
    for (int i = 0; i < count; i++) {
      buffer.append(MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]);
    }
    return buffer.toString();
  }
  
  private MultipartFormEntity getEntity()
  {
    if (entity == null) {
      entity = builder.buildEntity();
    }
    return entity;
  }
  
  public void addPart(FormBodyPart bodyPart)
  {
    builder.addPart(bodyPart);
    entity = null;
  }
  
  public void addPart(String name, ContentBody contentBody)
  {
    addPart(new FormBodyPart(name, contentBody));
  }
  
  public boolean isRepeatable()
  {
    return getEntity().isRepeatable();
  }
  
  public boolean isChunked()
  {
    return getEntity().isChunked();
  }
  
  public boolean isStreaming()
  {
    return getEntity().isStreaming();
  }
  
  public long getContentLength()
  {
    return getEntity().getContentLength();
  }
  
  public Header getContentType()
  {
    return getEntity().getContentType();
  }
  
  public Header getContentEncoding()
  {
    return getEntity().getContentEncoding();
  }
  
  public void consumeContent()
    throws IOException, UnsupportedOperationException
  {
    if (isStreaming()) {
      throw new UnsupportedOperationException("Streaming entity does not implement #consumeContent()");
    }
  }
  
  public InputStream getContent()
    throws IOException, UnsupportedOperationException
  {
    throw new UnsupportedOperationException("Multipart form entity does not implement #getContent()");
  }
  
  public void writeTo(OutputStream outstream)
    throws IOException
  {
    getEntity().writeTo(outstream);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.MultipartEntity
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.List;

class HttpRFC6532Multipart
  extends AbstractMultipartForm
{
  private final List<FormBodyPart> parts;
  
  public HttpRFC6532Multipart(String subType, Charset charset, String boundary, List<FormBodyPart> parts)
  {
    super(subType, charset, boundary);
    this.parts = parts;
  }
  
  public List<FormBodyPart> getBodyParts()
  {
    return parts;
  }
  
  protected void formatMultipartHeader(FormBodyPart part, OutputStream out)
    throws IOException
  {
    Header header = part.getHeader();
    for (MinimalField field : header) {
      writeField(field, MIME.UTF8_CHARSET, out);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.HttpRFC6532Multipart
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.message.BasicHeader;

class MultipartFormEntity
  implements HttpEntity
{
  private final AbstractMultipartForm multipart;
  private final Header contentType;
  private final long contentLength;
  
  MultipartFormEntity(AbstractMultipartForm multipart, String contentType, long contentLength)
  {
    this.multipart = multipart;
    this.contentType = new BasicHeader("Content-Type", contentType);
    this.contentLength = contentLength;
  }
  
  AbstractMultipartForm getMultipart()
  {
    return multipart;
  }
  
  public boolean isRepeatable()
  {
    return contentLength != -1L;
  }
  
  public boolean isChunked()
  {
    return !isRepeatable();
  }
  
  public boolean isStreaming()
  {
    return !isRepeatable();
  }
  
  public long getContentLength()
  {
    return contentLength;
  }
  
  public Header getContentType()
  {
    return contentType;
  }
  
  public Header getContentEncoding()
  {
    return null;
  }
  
  public void consumeContent()
    throws IOException, UnsupportedOperationException
  {
    if (isStreaming()) {
      throw new UnsupportedOperationException("Streaming entity does not implement #consumeContent()");
    }
  }
  
  public InputStream getContent()
    throws IOException
  {
    throw new UnsupportedOperationException("Multipart form entity does not implement #getContent()");
  }
  
  public void writeTo(OutputStream outstream)
    throws IOException
  {
    multipart.writeTo(outstream);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.MultipartFormEntity
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.List;
import org.apache.http.entity.mime.content.ContentBody;

class HttpBrowserCompatibleMultipart
  extends AbstractMultipartForm
{
  private final List<FormBodyPart> parts;
  
  public HttpBrowserCompatibleMultipart(String subType, Charset charset, String boundary, List<FormBodyPart> parts)
  {
    super(subType, charset, boundary);
    this.parts = parts;
  }
  
  public List<FormBodyPart> getBodyParts()
  {
    return parts;
  }
  
  protected void formatMultipartHeader(FormBodyPart part, OutputStream out)
    throws IOException
  {
    Header header = part.getHeader();
    MinimalField cd = header.getField("Content-Disposition");
    writeField(cd, charset, out);
    String filename = part.getBody().getFilename();
    if (filename != null)
    {
      MinimalField ct = header.getField("Content-Type");
      writeField(ct, charset, out);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.HttpBrowserCompatibleMultipart
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class Header
  implements Iterable<MinimalField>
{
  private final List<MinimalField> fields;
  private final Map<String, List<MinimalField>> fieldMap;
  
  public Header()
  {
    fields = new LinkedList();
    fieldMap = new HashMap();
  }
  
  public void addField(MinimalField field)
  {
    if (field == null) {
      return;
    }
    String key = field.getName().toLowerCase(Locale.ENGLISH);
    List<MinimalField> values = (List)fieldMap.get(key);
    if (values == null)
    {
      values = new LinkedList();
      fieldMap.put(key, values);
    }
    values.add(field);
    fields.add(field);
  }
  
  public List<MinimalField> getFields()
  {
    return new ArrayList(fields);
  }
  
  public MinimalField getField(String name)
  {
    if (name == null) {
      return null;
    }
    String key = name.toLowerCase(Locale.ENGLISH);
    List<MinimalField> list = (List)fieldMap.get(key);
    if ((list != null) && (!list.isEmpty())) {
      return (MinimalField)list.get(0);
    }
    return null;
  }
  
  public List<MinimalField> getFields(String name)
  {
    if (name == null) {
      return null;
    }
    String key = name.toLowerCase(Locale.ENGLISH);
    List<MinimalField> list = (List)fieldMap.get(key);
    if ((list == null) || (list.isEmpty())) {
      return Collections.emptyList();
    }
    return new ArrayList(list);
  }
  
  public int removeFields(String name)
  {
    if (name == null) {
      return 0;
    }
    String key = name.toLowerCase(Locale.ENGLISH);
    List<MinimalField> removed = (List)fieldMap.remove(key);
    if ((removed == null) || (removed.isEmpty())) {
      return 0;
    }
    fields.removeAll(removed);
    return removed.size();
  }
  
  public void setField(MinimalField field)
  {
    if (field == null) {
      return;
    }
    String key = field.getName().toLowerCase(Locale.ENGLISH);
    List<MinimalField> list = (List)fieldMap.get(key);
    if ((list == null) || (list.isEmpty()))
    {
      addField(field);
      return;
    }
    list.clear();
    list.add(field);
    int firstOccurrence = -1;
    int index = 0;
    for (Iterator<MinimalField> it = fields.iterator(); it.hasNext(); index++)
    {
      MinimalField f = (MinimalField)it.next();
      if (f.getName().equalsIgnoreCase(field.getName()))
      {
        it.remove();
        if (firstOccurrence == -1) {
          firstOccurrence = index;
        }
      }
    }
    fields.add(firstOccurrence, field);
  }
  
  public Iterator<MinimalField> iterator()
  {
    return Collections.unmodifiableList(fields).iterator();
  }
  
  public String toString()
  {
    return fields.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.Header
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.List;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.util.Args;
import org.apache.http.util.ByteArrayBuffer;

abstract class AbstractMultipartForm
{
  private static ByteArrayBuffer encode(Charset charset, String string)
  {
    ByteBuffer encoded = charset.encode(CharBuffer.wrap(string));
    ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining());
    bab.append(encoded.array(), encoded.position(), encoded.remaining());
    return bab;
  }
  
  private static void writeBytes(ByteArrayBuffer b, OutputStream out)
    throws IOException
  {
    out.write(b.buffer(), 0, b.length());
  }
  
  private static void writeBytes(String s, Charset charset, OutputStream out)
    throws IOException
  {
    ByteArrayBuffer b = encode(charset, s);
    writeBytes(b, out);
  }
  
  private static void writeBytes(String s, OutputStream out)
    throws IOException
  {
    ByteArrayBuffer b = encode(MIME.DEFAULT_CHARSET, s);
    writeBytes(b, out);
  }
  
  protected static void writeField(MinimalField field, OutputStream out)
    throws IOException
  {
    writeBytes(field.getName(), out);
    writeBytes(FIELD_SEP, out);
    writeBytes(field.getBody(), out);
    writeBytes(CR_LF, out);
  }
  
  protected static void writeField(MinimalField field, Charset charset, OutputStream out)
    throws IOException
  {
    writeBytes(field.getName(), charset, out);
    writeBytes(FIELD_SEP, out);
    writeBytes(field.getBody(), charset, out);
    writeBytes(CR_LF, out);
  }
  
  private static final ByteArrayBuffer FIELD_SEP = encode(MIME.DEFAULT_CHARSET, ": ");
  private static final ByteArrayBuffer CR_LF = encode(MIME.DEFAULT_CHARSET, "\r\n");
  private static final ByteArrayBuffer TWO_DASHES = encode(MIME.DEFAULT_CHARSET, "--");
  private final String subType;
  protected final Charset charset;
  private final String boundary;
  
  public AbstractMultipartForm(String subType, Charset charset, String boundary)
  {
    Args.notNull(subType, "Multipart subtype");
    Args.notNull(boundary, "Multipart boundary");
    this.subType = subType;
    this.charset = (charset != null ? charset : MIME.DEFAULT_CHARSET);
    this.boundary = boundary;
  }
  
  public AbstractMultipartForm(String subType, String boundary)
  {
    this(subType, null, boundary);
  }
  
  public String getSubType()
  {
    return subType;
  }
  
  public Charset getCharset()
  {
    return charset;
  }
  
  public abstract List<FormBodyPart> getBodyParts();
  
  public String getBoundary()
  {
    return boundary;
  }
  
  void doWriteTo(OutputStream out, boolean writeContent)
    throws IOException
  {
    ByteArrayBuffer boundary = encode(charset, getBoundary());
    for (FormBodyPart part : getBodyParts())
    {
      writeBytes(TWO_DASHES, out);
      writeBytes(boundary, out);
      writeBytes(CR_LF, out);
      
      formatMultipartHeader(part, out);
      
      writeBytes(CR_LF, out);
      if (writeContent) {
        part.getBody().writeTo(out);
      }
      writeBytes(CR_LF, out);
    }
    writeBytes(TWO_DASHES, out);
    writeBytes(boundary, out);
    writeBytes(TWO_DASHES, out);
    writeBytes(CR_LF, out);
  }
  
  protected abstract void formatMultipartHeader(FormBodyPart paramFormBodyPart, OutputStream paramOutputStream)
    throws IOException;
  
  public void writeTo(OutputStream out)
    throws IOException
  {
    doWriteTo(out, true);
  }
  
  public long getTotalLength()
  {
    long contentLen = 0L;
    for (FormBodyPart part : getBodyParts())
    {
      ContentBody body = part.getBody();
      long len = body.getContentLength();
      if (len >= 0L) {
        contentLen += len;
      } else {
        return -1L;
      }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try
    {
      doWriteTo(out, false);
      byte[] extra = out.toByteArray();
      return contentLen + extra.length;
    }
    catch (IOException ex) {}
    return -1L;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.AbstractMultipartForm
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

import java.io.File;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.content.ByteArrayBody;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.util.Args;

public class MultipartEntityBuilder
{
  private static final char[] MULTIPART_CHARS = "-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
  private static final String DEFAULT_SUBTYPE = "form-data";
  private String subType = "form-data";
  private HttpMultipartMode mode = HttpMultipartMode.STRICT;
  private String boundary = null;
  private Charset charset = null;
  private List<FormBodyPart> bodyParts = null;
  
  public static MultipartEntityBuilder create()
  {
    return new MultipartEntityBuilder();
  }
  
  public MultipartEntityBuilder setMode(HttpMultipartMode mode)
  {
    this.mode = mode;
    return this;
  }
  
  public MultipartEntityBuilder setLaxMode()
  {
    mode = HttpMultipartMode.BROWSER_COMPATIBLE;
    return this;
  }
  
  public MultipartEntityBuilder setStrictMode()
  {
    mode = HttpMultipartMode.STRICT;
    return this;
  }
  
  public MultipartEntityBuilder setBoundary(String boundary)
  {
    this.boundary = boundary;
    return this;
  }
  
  public MultipartEntityBuilder setCharset(Charset charset)
  {
    this.charset = charset;
    return this;
  }
  
  MultipartEntityBuilder addPart(FormBodyPart bodyPart)
  {
    if (bodyPart == null) {
      return this;
    }
    if (bodyParts == null) {
      bodyParts = new ArrayList();
    }
    bodyParts.add(bodyPart);
    return this;
  }
  
  public MultipartEntityBuilder addPart(String name, ContentBody contentBody)
  {
    Args.notNull(name, "Name");
    Args.notNull(contentBody, "Content body");
    return addPart(new FormBodyPart(name, contentBody));
  }
  
  public MultipartEntityBuilder addTextBody(String name, String text, ContentType contentType)
  {
    return addPart(name, new StringBody(text, contentType));
  }
  
  public MultipartEntityBuilder addTextBody(String name, String text)
  {
    return addTextBody(name, text, ContentType.DEFAULT_TEXT);
  }
  
  public MultipartEntityBuilder addBinaryBody(String name, byte[] b, ContentType contentType, String filename)
  {
    return addPart(name, new ByteArrayBody(b, contentType, filename));
  }
  
  public MultipartEntityBuilder addBinaryBody(String name, byte[] b)
  {
    return addBinaryBody(name, b, ContentType.DEFAULT_BINARY, null);
  }
  
  public MultipartEntityBuilder addBinaryBody(String name, File file, ContentType contentType, String filename)
  {
    return addPart(name, new FileBody(file, contentType, filename));
  }
  
  public MultipartEntityBuilder addBinaryBody(String name, File file)
  {
    return addBinaryBody(name, file, ContentType.DEFAULT_BINARY, file != null ? file.getName() : null);
  }
  
  public MultipartEntityBuilder addBinaryBody(String name, InputStream stream, ContentType contentType, String filename)
  {
    return addPart(name, new InputStreamBody(stream, contentType, filename));
  }
  
  public MultipartEntityBuilder addBinaryBody(String name, InputStream stream)
  {
    return addBinaryBody(name, stream, ContentType.DEFAULT_BINARY, null);
  }
  
  private String generateContentType(String boundary, Charset charset)
  {
    StringBuilder buffer = new StringBuilder();
    buffer.append("multipart/form-data; boundary=");
    buffer.append(boundary);
    if (charset != null)
    {
      buffer.append("; charset=");
      buffer.append(charset.name());
    }
    return buffer.toString();
  }
  
  private String generateBoundary()
  {
    StringBuilder buffer = new StringBuilder();
    Random rand = new Random();
    int count = rand.nextInt(11) + 30;
    for (int i = 0; i < count; i++) {
      buffer.append(MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]);
    }
    return buffer.toString();
  }
  
  MultipartFormEntity buildEntity()
  {
    String st = subType != null ? subType : "form-data";
    Charset cs = charset;
    String b = boundary != null ? boundary : generateBoundary();
    List<FormBodyPart> bps = bodyParts != null ? new ArrayList(bodyParts) : Collections.emptyList();
    
    HttpMultipartMode m = mode != null ? mode : HttpMultipartMode.STRICT;
    AbstractMultipartForm form;
    switch (m)
    {
    case BROWSER_COMPATIBLE: 
      form = new HttpBrowserCompatibleMultipart(st, cs, b, bps);
      break;
    case RFC6532: 
      form = new HttpRFC6532Multipart(st, cs, b, bps);
      break;
    default: 
      form = new HttpStrictMultipart(st, cs, b, bps);
    }
    return new MultipartFormEntity(form, generateContentType(b, cs), form.getTotalLength());
  }
  
  public HttpEntity build()
  {
    return buildEntity();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.MultipartEntityBuilder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

public enum HttpMultipartMode
{
  STRICT,  BROWSER_COMPATIBLE,  RFC6532;
  
  private HttpMultipartMode() {}
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.HttpMultipartMode
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.List;

class HttpStrictMultipart
  extends AbstractMultipartForm
{
  private final List<FormBodyPart> parts;
  
  public HttpStrictMultipart(String subType, Charset charset, String boundary, List<FormBodyPart> parts)
  {
    super(subType, charset, boundary);
    this.parts = parts;
  }
  
  public List<FormBodyPart> getBodyParts()
  {
    return parts;
  }
  
  protected void formatMultipartHeader(FormBodyPart part, OutputStream out)
    throws IOException
  {
    Header header = part.getHeader();
    for (MinimalField field : header) {
      writeField(field, out);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.HttpStrictMultipart
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime.content;

import java.io.IOException;
import java.io.OutputStream;
import org.apache.http.entity.ContentType;
import org.apache.http.util.Args;

public class ByteArrayBody
  extends AbstractContentBody
{
  private final byte[] data;
  private final String filename;
  
  @Deprecated
  public ByteArrayBody(byte[] data, String mimeType, String filename)
  {
    this(data, ContentType.create(mimeType), filename);
  }
  
  public ByteArrayBody(byte[] data, ContentType contentType, String filename)
  {
    super(contentType);
    Args.notNull(data, "byte[]");
    this.data = data;
    this.filename = filename;
  }
  
  public ByteArrayBody(byte[] data, String filename)
  {
    this(data, "application/octet-stream", filename);
  }
  
  public String getFilename()
  {
    return filename;
  }
  
  public void writeTo(OutputStream out)
    throws IOException
  {
    out.write(data);
  }
  
  public String getCharset()
  {
    return null;
  }
  
  public String getTransferEncoding()
  {
    return "binary";
  }
  
  public long getContentLength()
  {
    return data.length;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.content.ByteArrayBody
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime.content;

public abstract interface ContentDescriptor
{
  public abstract String getMimeType();
  
  public abstract String getMediaType();
  
  public abstract String getSubType();
  
  public abstract String getCharset();
  
  public abstract String getTransferEncoding();
  
  public abstract long getContentLength();
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.content.ContentDescriptor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime.content;

import java.io.IOException;
import java.io.OutputStream;

public abstract interface ContentBody
  extends ContentDescriptor
{
  public abstract String getFilename();
  
  public abstract void writeTo(OutputStream paramOutputStream)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.content.ContentBody
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime.content;

import java.nio.charset.Charset;
import org.apache.http.entity.ContentType;
import org.apache.http.util.Args;

public abstract class AbstractContentBody
  implements ContentBody
{
  private final ContentType contentType;
  
  public AbstractContentBody(ContentType contentType)
  {
    Args.notNull(contentType, "Content type");
    this.contentType = contentType;
  }
  
  @Deprecated
  public AbstractContentBody(String mimeType)
  {
    this(ContentType.parse(mimeType));
  }
  
  public ContentType getContentType()
  {
    return contentType;
  }
  
  public String getMimeType()
  {
    return contentType.getMimeType();
  }
  
  public String getMediaType()
  {
    String mimeType = contentType.getMimeType();
    int i = mimeType.indexOf('/');
    if (i != -1) {
      return mimeType.substring(0, i);
    }
    return mimeType;
  }
  
  public String getSubType()
  {
    String mimeType = contentType.getMimeType();
    int i = mimeType.indexOf('/');
    if (i != -1) {
      return mimeType.substring(i + 1);
    }
    return null;
  }
  
  public String getCharset()
  {
    Charset charset = contentType.getCharset();
    return charset != null ? charset.name() : null;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.content.AbstractContentBody
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime.content;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.entity.ContentType;
import org.apache.http.util.Args;

public class InputStreamBody
  extends AbstractContentBody
{
  private final InputStream in;
  private final String filename;
  
  @Deprecated
  public InputStreamBody(InputStream in, String mimeType, String filename)
  {
    this(in, ContentType.create(mimeType), filename);
  }
  
  public InputStreamBody(InputStream in, String filename)
  {
    this(in, ContentType.DEFAULT_BINARY, filename);
  }
  
  public InputStreamBody(InputStream in, ContentType contentType, String filename)
  {
    super(contentType);
    Args.notNull(in, "Input stream");
    this.in = in;
    this.filename = filename;
  }
  
  public InputStreamBody(InputStream in, ContentType contentType)
  {
    this(in, contentType, null);
  }
  
  public InputStream getInputStream()
  {
    return in;
  }
  
  public void writeTo(OutputStream out)
    throws IOException
  {
    Args.notNull(out, "Output stream");
    try
    {
      byte[] tmp = new byte['?'];
      int l;
      while ((l = in.read(tmp)) != -1) {
        out.write(tmp, 0, l);
      }
      out.flush();
    }
    finally
    {
      in.close();
    }
  }
  
  public String getTransferEncoding()
  {
    return "binary";
  }
  
  public long getContentLength()
  {
    return -1L;
  }
  
  public String getFilename()
  {
    return filename;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.content.InputStreamBody
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime.content;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import org.apache.http.Consts;
import org.apache.http.entity.ContentType;
import org.apache.http.util.Args;

public class StringBody
  extends AbstractContentBody
{
  private final byte[] content;
  
  @Deprecated
  public static StringBody create(String text, String mimeType, Charset charset)
    throws IllegalArgumentException
  {
    try
    {
      return new StringBody(text, mimeType, charset);
    }
    catch (UnsupportedEncodingException ex)
    {
      throw new IllegalArgumentException("Charset " + charset + " is not supported", ex);
    }
  }
  
  @Deprecated
  public static StringBody create(String text, Charset charset)
    throws IllegalArgumentException
  {
    return create(text, null, charset);
  }
  
  @Deprecated
  public static StringBody create(String text)
    throws IllegalArgumentException
  {
    return create(text, null, null);
  }
  
  @Deprecated
  public StringBody(String text, String mimeType, Charset charset)
    throws UnsupportedEncodingException
  {
    this(text, ContentType.create(mimeType, charset));
  }
  
  @Deprecated
  public StringBody(String text, Charset charset)
    throws UnsupportedEncodingException
  {
    this(text, "text/plain", charset);
  }
  
  @Deprecated
  public StringBody(String text)
    throws UnsupportedEncodingException
  {
    this(text, "text/plain", Consts.ASCII);
  }
  
  public StringBody(String text, ContentType contentType)
  {
    super(contentType);
    Args.notNull(text, "Text");
    Charset charset = contentType.getCharset();
    String csname = charset != null ? charset.name() : Consts.ASCII.name();
    try
    {
      content = text.getBytes(csname);
    }
    catch (UnsupportedEncodingException ex)
    {
      throw new UnsupportedCharsetException(csname);
    }
  }
  
  public Reader getReader()
  {
    Charset charset = getContentType().getCharset();
    return new InputStreamReader(new ByteArrayInputStream(content), charset != null ? charset : Consts.ASCII);
  }
  
  public void writeTo(OutputStream out)
    throws IOException
  {
    Args.notNull(out, "Output stream");
    InputStream in = new ByteArrayInputStream(content);
    byte[] tmp = new byte['?'];
    int l;
    while ((l = in.read(tmp)) != -1) {
      out.write(tmp, 0, l);
    }
    out.flush();
  }
  
  public String getTransferEncoding()
  {
    return "8bit";
  }
  
  public long getContentLength()
  {
    return content.length;
  }
  
  public String getFilename()
  {
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.content.StringBody
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime.content;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.entity.ContentType;
import org.apache.http.util.Args;

public class FileBody
  extends AbstractContentBody
{
  private final File file;
  private final String filename;
  
  @Deprecated
  public FileBody(File file, String filename, String mimeType, String charset)
  {
    this(file, ContentType.create(mimeType, charset), filename);
  }
  
  @Deprecated
  public FileBody(File file, String mimeType, String charset)
  {
    this(file, null, mimeType, charset);
  }
  
  @Deprecated
  public FileBody(File file, String mimeType)
  {
    this(file, ContentType.create(mimeType), null);
  }
  
  public FileBody(File file)
  {
    this(file, ContentType.DEFAULT_BINARY, file != null ? file.getName() : null);
  }
  
  public FileBody(File file, ContentType contentType, String filename)
  {
    super(contentType);
    Args.notNull(file, "File");
    this.file = file;
    this.filename = filename;
  }
  
  public FileBody(File file, ContentType contentType)
  {
    this(file, contentType, null);
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    return new FileInputStream(file);
  }
  
  public void writeTo(OutputStream out)
    throws IOException
  {
    Args.notNull(out, "Output stream");
    InputStream in = new FileInputStream(file);
    try
    {
      byte[] tmp = new byte['?'];
      int l;
      while ((l = in.read(tmp)) != -1) {
        out.write(tmp, 0, l);
      }
      out.flush();
    }
    finally
    {
      in.close();
    }
  }
  
  public String getTransferEncoding()
  {
    return "binary";
  }
  
  public long getContentLength()
  {
    return file.length();
  }
  
  public String getFilename()
  {
    return filename;
  }
  
  public File getFile()
  {
    return file;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.content.FileBody
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.entity.mime.content.ContentBody;

@Deprecated
public class HttpMultipart
  extends AbstractMultipartForm
{
  private final HttpMultipartMode mode;
  private final List<FormBodyPart> parts;
  
  public HttpMultipart(String subType, Charset charset, String boundary, HttpMultipartMode mode)
  {
    super(subType, charset, boundary);
    this.mode = mode;
    parts = new ArrayList();
  }
  
  public HttpMultipart(String subType, Charset charset, String boundary)
  {
    this(subType, charset, boundary, HttpMultipartMode.STRICT);
  }
  
  public HttpMultipart(String subType, String boundary)
  {
    this(subType, null, boundary);
  }
  
  public HttpMultipartMode getMode()
  {
    return mode;
  }
  
  protected void formatMultipartHeader(FormBodyPart part, OutputStream out)
    throws IOException
  {
    Header header = part.getHeader();
    switch (mode)
    {
    case BROWSER_COMPATIBLE: 
      MinimalField cd = header.getField("Content-Disposition");
      writeField(cd, charset, out);
      String filename = part.getBody().getFilename();
      if (filename != null)
      {
        MinimalField ct = header.getField("Content-Type");
        writeField(ct, charset, out);
      }
      break;
    default: 
      for (MinimalField field : header) {
        writeField(field, out);
      }
    }
  }
  
  public List<FormBodyPart> getBodyParts()
  {
    return parts;
  }
  
  public void addBodyPart(FormBodyPart part)
  {
    if (part == null) {
      return;
    }
    parts.add(part);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.HttpMultipart
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.content.AbstractContentBody;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.util.Args;

public class FormBodyPart
{
  private final String name;
  private final Header header;
  private final ContentBody body;
  
  public FormBodyPart(String name, ContentBody body)
  {
    Args.notNull(name, "Name");
    Args.notNull(body, "Body");
    this.name = name;
    this.body = body;
    header = new Header();
    
    generateContentDisp(body);
    generateContentType(body);
    generateTransferEncoding(body);
  }
  
  public String getName()
  {
    return name;
  }
  
  public ContentBody getBody()
  {
    return body;
  }
  
  public Header getHeader()
  {
    return header;
  }
  
  public void addField(String name, String value)
  {
    Args.notNull(name, "Field name");
    header.addField(new MinimalField(name, value));
  }
  
  protected void generateContentDisp(ContentBody body)
  {
    StringBuilder buffer = new StringBuilder();
    buffer.append("form-data; name=\"");
    buffer.append(getName());
    buffer.append("\"");
    if (body.getFilename() != null)
    {
      buffer.append("; filename=\"");
      buffer.append(body.getFilename());
      buffer.append("\"");
    }
    addField("Content-Disposition", buffer.toString());
  }
  
  protected void generateContentType(ContentBody body)
  {
    ContentType contentType;
    ContentType contentType;
    if ((body instanceof AbstractContentBody)) {
      contentType = ((AbstractContentBody)body).getContentType();
    } else {
      contentType = null;
    }
    if (contentType != null)
    {
      addField("Content-Type", contentType.toString());
    }
    else
    {
      StringBuilder buffer = new StringBuilder();
      buffer.append(body.getMimeType());
      if (body.getCharset() != null)
      {
        buffer.append("; charset=");
        buffer.append(body.getCharset());
      }
      addField("Content-Type", buffer.toString());
    }
  }
  
  protected void generateTransferEncoding(ContentBody body)
  {
    addField("Content-Transfer-Encoding", body.getTransferEncoding());
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.FormBodyPart
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

import java.nio.charset.Charset;
import org.apache.http.Consts;

public final class MIME
{
  public static final String CONTENT_TYPE = "Content-Type";
  public static final String CONTENT_TRANSFER_ENC = "Content-Transfer-Encoding";
  public static final String CONTENT_DISPOSITION = "Content-Disposition";
  public static final String ENC_8BIT = "8bit";
  public static final String ENC_BINARY = "binary";
  public static final Charset DEFAULT_CHARSET = Consts.ASCII;
  public static final Charset UTF8_CHARSET = Consts.UTF_8;
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.MIME
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

class HttpMultipart$1 {}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.HttpMultipart.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

class MultipartEntityBuilder$1 {}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.MultipartEntityBuilder.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity.mime;

public class MinimalField
{
  private final String name;
  private final String value;
  
  public MinimalField(String name, String value)
  {
    this.name = name;
    this.value = value;
  }
  
  public String getName()
  {
    return name;
  }
  
  public String getBody()
  {
    return value;
  }
  
  public String toString()
  {
    StringBuilder buffer = new StringBuilder();
    buffer.append(name);
    buffer.append(": ");
    buffer.append(value);
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.mime.MinimalField
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd