Fields Summary |
---|
private static final Log | LOGLog object for this class. |
protected static final String | BOUNDARYThe boundary |
protected static final byte[] | BOUNDARY_BYTESThe boundary as a byte array. |
private static final byte[] | DEFAULT_BOUNDARY_BYTESThe default boundary to be used if {@link #setPartBoundary(byte[])} has not
been called. |
protected static final String | CRLFCarriage return/linefeed |
protected static final byte[] | CRLF_BYTESCarriage return/linefeed as a byte array |
protected static final String | QUOTEContent dispostion characters |
protected static final byte[] | QUOTE_BYTESContent dispostion as a byte array |
protected static final String | EXTRAExtra characters |
protected static final byte[] | EXTRA_BYTESExtra characters as a byte array |
protected static final String | CONTENT_DISPOSITIONContent dispostion characters |
protected static final byte[] | CONTENT_DISPOSITION_BYTESContent dispostion as a byte array |
protected static final String | CONTENT_TYPEContent type header |
protected static final byte[] | CONTENT_TYPE_BYTESContent type header as a byte array |
protected static final String | CHARSETContent charset |
protected static final byte[] | CHARSET_BYTESContent charset as a byte array |
protected static final String | CONTENT_TRANSFER_ENCODINGContent type header |
protected static final byte[] | CONTENT_TRANSFER_ENCODING_BYTESContent type header as a byte array |
private byte[] | boundaryBytesThe ASCII bytes to use as the multipart boundary. |
Methods Summary |
---|
public static java.lang.String | getBoundary()Return the boundary string.
return BOUNDARY;
|
public abstract java.lang.String | getCharSet()Return the character encoding of this part.
|
public abstract java.lang.String | getContentType()Returns the content type of this part.
|
public static long | getLengthOfParts(com.android.internal.http.multipart.Part[] parts)Return the total sum of all parts and that of the last boundary
return getLengthOfParts(parts, DEFAULT_BOUNDARY_BYTES);
|
public static long | getLengthOfParts(com.android.internal.http.multipart.Part[] parts, byte[] partBoundary)Gets the length of the multipart message including the given parts.
LOG.trace("getLengthOfParts(Parts[])");
if (parts == null) {
throw new IllegalArgumentException("Parts may not be null");
}
long total = 0;
for (int i = 0; i < parts.length; i++) {
// set the part boundary before we calculate the part's length
parts[i].setPartBoundary(partBoundary);
long l = parts[i].length();
if (l < 0) {
return -1;
}
total += l;
}
total += EXTRA_BYTES.length;
total += partBoundary.length;
total += EXTRA_BYTES.length;
total += CRLF_BYTES.length;
return total;
|
public abstract java.lang.String | getName()Return the name of this part.
|
protected byte[] | getPartBoundary()Gets the part boundary to be used.
if (boundaryBytes == null) {
// custom boundary bytes have not been set, use the default.
return DEFAULT_BOUNDARY_BYTES;
} else {
return boundaryBytes;
}
|
public abstract java.lang.String | getTransferEncoding()Return the transfer encoding of this part.
|
public boolean | isRepeatable()Tests if this part can be sent more than once.
return true;
|
public long | length()Return the full length of all the data.
If you override this method make sure to override
#send(OutputStream) as well
LOG.trace("enter length()");
if (lengthOfData() < 0) {
return -1;
}
ByteArrayOutputStream overhead = new ByteArrayOutputStream();
sendStart(overhead);
sendDispositionHeader(overhead);
sendContentTypeHeader(overhead);
sendTransferEncodingHeader(overhead);
sendEndOfHeader(overhead);
sendEnd(overhead);
return overhead.size() + lengthOfData();
|
protected abstract long | lengthOfData()Return the length of the main content
|
public void | send(java.io.OutputStream out)Write all the data to the output stream.
If you override this method make sure to override
#length() as well
LOG.trace("enter send(OutputStream out)");
sendStart(out);
sendDispositionHeader(out);
sendContentTypeHeader(out);
sendTransferEncodingHeader(out);
sendEndOfHeader(out);
sendData(out);
sendEnd(out);
|
protected void | sendContentTypeHeader(java.io.OutputStream out)Write the content type header to the specified output stream
LOG.trace("enter sendContentTypeHeader(OutputStream out)");
String contentType = getContentType();
if (contentType != null) {
out.write(CRLF_BYTES);
out.write(CONTENT_TYPE_BYTES);
out.write(EncodingUtils.getAsciiBytes(contentType));
String charSet = getCharSet();
if (charSet != null) {
out.write(CHARSET_BYTES);
out.write(EncodingUtils.getAsciiBytes(charSet));
}
}
|
protected abstract void | sendData(java.io.OutputStream out)Write the data to the specified output stream
|
protected void | sendDispositionHeader(java.io.OutputStream out)Write the content disposition header to the specified output stream
LOG.trace("enter sendDispositionHeader(OutputStream out)");
out.write(CONTENT_DISPOSITION_BYTES);
out.write(QUOTE_BYTES);
out.write(EncodingUtils.getAsciiBytes(getName()));
out.write(QUOTE_BYTES);
|
protected void | sendEnd(java.io.OutputStream out)Write the end data to the output stream.
LOG.trace("enter sendEnd(OutputStream out)");
out.write(CRLF_BYTES);
|
protected void | sendEndOfHeader(java.io.OutputStream out)Write the end of the header to the output stream
LOG.trace("enter sendEndOfHeader(OutputStream out)");
out.write(CRLF_BYTES);
out.write(CRLF_BYTES);
|
public static void | sendParts(java.io.OutputStream out, com.android.internal.http.multipart.Part[] parts)Write all parts and the last boundary to the specified output stream.
sendParts(out, parts, DEFAULT_BOUNDARY_BYTES);
|
public static void | sendParts(java.io.OutputStream out, com.android.internal.http.multipart.Part[] parts, byte[] partBoundary)Write all parts and the last boundary to the specified output stream.
if (parts == null) {
throw new IllegalArgumentException("Parts may not be null");
}
if (partBoundary == null || partBoundary.length == 0) {
throw new IllegalArgumentException("partBoundary may not be empty");
}
for (int i = 0; i < parts.length; i++) {
// set the part boundary before the part is sent
parts[i].setPartBoundary(partBoundary);
parts[i].send(out);
}
out.write(EXTRA_BYTES);
out.write(partBoundary);
out.write(EXTRA_BYTES);
out.write(CRLF_BYTES);
|
protected void | sendStart(java.io.OutputStream out)Write the start to the specified output stream
LOG.trace("enter sendStart(OutputStream out)");
out.write(EXTRA_BYTES);
out.write(getPartBoundary());
out.write(CRLF_BYTES);
|
protected void | sendTransferEncodingHeader(java.io.OutputStream out)Write the content transfer encoding header to the specified
output stream
LOG.trace("enter sendTransferEncodingHeader(OutputStream out)");
String transferEncoding = getTransferEncoding();
if (transferEncoding != null) {
out.write(CRLF_BYTES);
out.write(CONTENT_TRANSFER_ENCODING_BYTES);
out.write(EncodingUtils.getAsciiBytes(transferEncoding));
}
|
void | setPartBoundary(byte[] boundaryBytes)Sets the part boundary. Only meant to be used by
{@link Part#sendParts(OutputStream, Part[], byte[])}
and {@link Part#getLengthOfParts(Part[], byte[])}
this.boundaryBytes = boundaryBytes;
|
public java.lang.String | toString()Return a string representation of this object.
return this.getName();
|