im.yixin.sdk.http.multipart
类 MultipartEntity

java.lang.Object
  继承者 org.apache.http.entity.AbstractHttpEntity
      继承者 im.yixin.sdk.http.multipart.MultipartEntity
所有已实现的接口:
org.apache.http.HttpEntity

public class MultipartEntity
extends org.apache.http.entity.AbstractHttpEntity

Implements a request entity suitable for an HTTP multipart POST method.

The HTTP multipart POST method is defined in section 3.3 of RFC1867:

The media-type multipart/form-data follows the rules of all multipart MIME data streams as outlined in RFC 1521. The multipart/form-data contains a series of parts. Each part is expected to contain a content-disposition header where the value is "form-data" and a name attribute specifies the field name within the form, e.g., 'content-disposition: form-data; name="xxxxx"', where xxxxx is the field name corresponding to that field. Field names originally in non-ASCII character sets may be encoded using the method outlined in RFC 1522.

This entity is designed to be used in conjunction with the HttpRequest to provide multipart posts. Example usage:

 File f = new File("/path/fileToUpload.txt");
 HttpRequest request = new HttpRequest("http://host/some_path");
 Part[] parts = { new StringPart("param_name", "value"), new FilePart(f.getName(), f) };
 filePost.setEntity(new MultipartRequestEntity(parts, filePost.getParams()));
 HttpClient client = new HttpClient();
 int status = client.executeMethod(filePost);
 

从以下版本开始:
3.0

字段摘要
static java.lang.String MULTIPART_BOUNDARY
          Sets the value to use as the multipart boundary.
protected  Part[] parts
          The MIME parts as set by the constructor
 
从类 org.apache.http.entity.AbstractHttpEntity 继承的字段
chunked, contentEncoding, contentType
 
构造方法摘要
MultipartEntity(Part[] parts)
           
MultipartEntity(Part[] parts, org.apache.http.params.HttpParams params)
          Creates a new multipart entity containing the given parts.
 
方法摘要
static byte[] generateMultipartBoundary()
          Generates a random multipart boundary string.
 java.io.InputStream getContent()
           
 long getContentLength()
           
 org.apache.http.Header getContentType()
           
protected  byte[] getMultipartBoundary()
          Returns the MIME boundary string that is used to demarcate boundaries of this part.
 boolean isRepeatable()
          Returns true if all parts are repeatable, false otherwise.
 boolean isStreaming()
           
 void writeTo(java.io.OutputStream out)
           
 
从类 org.apache.http.entity.AbstractHttpEntity 继承的方法
consumeContent, getContentEncoding, isChunked, setChunked, setContentEncoding, setContentEncoding, setContentType, setContentType
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

MULTIPART_BOUNDARY

public static final java.lang.String MULTIPART_BOUNDARY
Sets the value to use as the multipart boundary.

This parameter expects a value if type String.

另请参见:
常量字段值

parts

protected Part[] parts
The MIME parts as set by the constructor

构造方法详细信息

MultipartEntity

public MultipartEntity(Part[] parts,
                       org.apache.http.params.HttpParams params)
Creates a new multipart entity containing the given parts.

参数:
parts - The parts to include.
params - The params of the HttpMethod using this entity.

MultipartEntity

public MultipartEntity(Part[] parts)
方法详细信息

generateMultipartBoundary

public static byte[] generateMultipartBoundary()
Generates a random multipart boundary string.


getMultipartBoundary

protected byte[] getMultipartBoundary()
Returns the MIME boundary string that is used to demarcate boundaries of this part. The first call to this method will implicitly create a new boundary string. To create a boundary string first the HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise a random one is generated.

返回:
The boundary string of this entity in ASCII encoding.

isRepeatable

public boolean isRepeatable()
Returns true if all parts are repeatable, false otherwise.


writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
抛出:
java.io.IOException

getContentType

public org.apache.http.Header getContentType()
指定者:
接口 org.apache.http.HttpEntity 中的 getContentType
覆盖:
org.apache.http.entity.AbstractHttpEntity 中的 getContentType

getContentLength

public long getContentLength()

getContent

public java.io.InputStream getContent()
                               throws java.io.IOException,
                                      java.lang.IllegalStateException
抛出:
java.io.IOException
java.lang.IllegalStateException

isStreaming

public boolean isStreaming()