FileDocCategorySizeDatePackage
StringPart.javaAPI DocAndroid 5.1 API5356Thu Mar 12 22:22:10 GMT 2015com.android.internal.http.multipart

StringPart

public class StringPart extends PartBase
Simple string parameter for a multipart post
author
Matthew Albright
author
Jeff Dever
author
Mike Bowler
author
Oleg Kalnichevski
since
2.0
deprecated
Please use {@link java.net.URLConnection} and friends instead. The Apache HTTP client is no longer maintained and may be removed in a future release. Please visit this webpage for further details.

Fields Summary
private static final Log
LOG
Log object for this class.
public static final String
DEFAULT_CONTENT_TYPE
Default content encoding of string parameters.
public static final String
DEFAULT_CHARSET
Default charset of string parameters
public static final String
DEFAULT_TRANSFER_ENCODING
Default transfer encoding of string parameters
private byte[]
content
Contents of this StringPart.
private String
value
The String value of this part.
Constructors Summary
public StringPart(String name, String value, String charset)
Constructor.

param
name The name of the part
param
value the string to post
param
charset the charset to be used to encode the string, if null the {@link #DEFAULT_CHARSET default} is used


                                           
           
        
        super(
            name,
            DEFAULT_CONTENT_TYPE,
            charset == null ? DEFAULT_CHARSET : charset,
            DEFAULT_TRANSFER_ENCODING
        );
        if (value == null) {
            throw new IllegalArgumentException("Value may not be null");
        }
        if (value.indexOf(0) != -1) {
            // See RFC 2048, 2.8. "8bit Data"
            throw new IllegalArgumentException("NULs may not be present in string parts");
        }
        this.value = value;
    
public StringPart(String name, String value)
Constructor.

param
name The name of the part
param
value the string to post

        this(name, value, null);
    
Methods Summary
private byte[]getContent()
Gets the content in bytes. Bytes are lazily created to allow the charset to be changed after the part is created.

return
the content in bytes

        if (content == null) {
            content = EncodingUtils.getBytes(value, getCharSet());
        }
        return content;
    
protected longlengthOfData()
Return the length of the data.

return
The length of the data.
see
Part#lengthOfData()

        LOG.trace("enter lengthOfData()");
        return getContent().length;
    
protected voidsendData(java.io.OutputStream out)
Writes the data to the given OutputStream.

param
out the OutputStream to write to
throws
IOException if there is a write error

        LOG.trace("enter sendData(OutputStream)");
        out.write(getContent());
    
public voidsetCharSet(java.lang.String charSet)

        super.setCharSet(charSet);
        this.content = null;