org.apache.commons.httpclient.methods.multipart

Class Part

public abstract class Part extends Object

Abstract class for one Part of a multipart post object.

Since: 2.0

Author: Matthew Albright Jeff Dever Adrian Sutton Mike Bowler Oleg Kalnichevski

Field Summary
protected static StringBOUNDARY
The boundary
protected static byte[]BOUNDARY_BYTES
The boundary as a byte array.
protected static StringCHARSET
Content charset
protected static byte[]CHARSET_BYTES
Content charset as a byte array
protected static StringCONTENT_DISPOSITION
Content dispostion characters
protected static byte[]CONTENT_DISPOSITION_BYTES
Content dispostion as a byte array
protected static StringCONTENT_TRANSFER_ENCODING
Content type header
protected static byte[]CONTENT_TRANSFER_ENCODING_BYTES
Content type header as a byte array
protected static StringCONTENT_TYPE
Content type header
protected static byte[]CONTENT_TYPE_BYTES
Content type header as a byte array
protected static StringCRLF
Carriage return/linefeed
protected static byte[]CRLF_BYTES
Carriage return/linefeed as a byte array
protected static StringEXTRA
Extra characters
protected static byte[]EXTRA_BYTES
Extra characters as a byte array
protected static StringQUOTE
Content dispostion characters
protected static byte[]QUOTE_BYTES
Content dispostion as a byte array
Method Summary
static StringgetBoundary()
Return the boundary string.
abstract StringgetCharSet()
Return the character encoding of this part.
abstract StringgetContentType()
Returns the content type of this part.
static longgetLengthOfParts(Part[] parts)
Return the total sum of all parts and that of the last boundary
static longgetLengthOfParts(Part[] parts, byte[] partBoundary)
Gets the length of the multipart message including the given parts.
abstract StringgetName()
Return the name of this part.
protected byte[]getPartBoundary()
Gets the part boundary to be used.
abstract StringgetTransferEncoding()
Return the transfer encoding of this part.
booleanisRepeatable()
Tests if this part can be sent more than once.
longlength()
Return the full length of all the data.
protected abstract longlengthOfData()
Return the length of the main content
voidsend(OutputStream out)
Write all the data to the output stream.
protected voidsendContentTypeHeader(OutputStream out)
Write the content type header to the specified output stream
protected abstract voidsendData(OutputStream out)
Write the data to the specified output stream
protected voidsendDispositionHeader(OutputStream out)
Write the content disposition header to the specified output stream
protected voidsendEnd(OutputStream out)
Write the end data to the output stream.
protected voidsendEndOfHeader(OutputStream out)
Write the end of the header to the output stream
static voidsendParts(OutputStream out, Part[] parts)
Write all parts and the last boundary to the specified output stream.
static voidsendParts(OutputStream out, Part[] parts, byte[] partBoundary)
Write all parts and the last boundary to the specified output stream.
protected voidsendStart(OutputStream out)
Write the start to the specified output stream
protected voidsendTransferEncodingHeader(OutputStream out)
Write the content transfer encoding header to the specified output stream
StringtoString()
Return a string representation of this object.

Field Detail

BOUNDARY

protected static final String BOUNDARY

Deprecated: use {@link org.apache.commons.httpclient.params.HttpMethodParams#MULTIPART_BOUNDARY}

The boundary

BOUNDARY_BYTES

protected static final byte[] BOUNDARY_BYTES

Deprecated:

The boundary as a byte array.

CHARSET

protected static final String CHARSET
Content charset

CHARSET_BYTES

protected static final byte[] CHARSET_BYTES
Content charset as a byte array

CONTENT_DISPOSITION

protected static final String CONTENT_DISPOSITION
Content dispostion characters

CONTENT_DISPOSITION_BYTES

protected static final byte[] CONTENT_DISPOSITION_BYTES
Content dispostion as a byte array

CONTENT_TRANSFER_ENCODING

protected static final String CONTENT_TRANSFER_ENCODING
Content type header

CONTENT_TRANSFER_ENCODING_BYTES

protected static final byte[] CONTENT_TRANSFER_ENCODING_BYTES
Content type header as a byte array

CONTENT_TYPE

protected static final String CONTENT_TYPE
Content type header

CONTENT_TYPE_BYTES

protected static final byte[] CONTENT_TYPE_BYTES
Content type header as a byte array

CRLF

protected static final String CRLF
Carriage return/linefeed

CRLF_BYTES

protected static final byte[] CRLF_BYTES
Carriage return/linefeed as a byte array

EXTRA

protected static final String EXTRA
Extra characters

EXTRA_BYTES

protected static final byte[] EXTRA_BYTES
Extra characters as a byte array

QUOTE

protected static final String QUOTE
Content dispostion characters

QUOTE_BYTES

protected static final byte[] QUOTE_BYTES
Content dispostion as a byte array

Method Detail

getBoundary

public static String getBoundary()

Deprecated: uses a constant string. Rather use {@link #getPartBoundary}

Return the boundary string.

Returns: the boundary string

getCharSet

public abstract String getCharSet()
Return the character encoding of this part.

Returns: the character encoding, or null to exclude the character encoding header

getContentType

public abstract String getContentType()
Returns the content type of this part.

Returns: the content type, or null to exclude the content type header

getLengthOfParts

public static long getLengthOfParts(Part[] parts)
Return the total sum of all parts and that of the last boundary

Parameters: parts The parts.

Returns: The total length

Throws: IOException If an I/O error occurs while writing the parts.

getLengthOfParts

public static long getLengthOfParts(Part[] parts, byte[] partBoundary)
Gets the length of the multipart message including the given parts.

Parameters: parts The parts. partBoundary The ASCII bytes to use as the part boundary.

Returns: The total length

Throws: IOException If an I/O error occurs while writing the parts.

Since: 3.0

getName

public abstract String getName()
Return the name of this part.

Returns: The name.

getPartBoundary

protected byte[] getPartBoundary()
Gets the part boundary to be used.

Returns: the part boundary as an array of bytes.

Since: 3.0

getTransferEncoding

public abstract String getTransferEncoding()
Return the transfer encoding of this part.

Returns: the transfer encoding, or null to exclude the transfer encoding header

isRepeatable

public boolean isRepeatable()
Tests if this part can be sent more than once.

Returns: true if {@link #sendData(OutputStream)} can be successfully called more than once.

Since: 3.0

length

public long length()
Return the full length of all the data. If you override this method make sure to override #send(OutputStream) as well

Returns: long The length.

Throws: IOException If an IO problem occurs

lengthOfData

protected abstract long lengthOfData()
Return the length of the main content

Returns: long The length.

Throws: IOException If an IO problem occurs

send

public void send(OutputStream out)
Write all the data to the output stream. If you override this method make sure to override #length() as well

Parameters: out The output stream

Throws: IOException If an IO problem occurs.

sendContentTypeHeader

protected void sendContentTypeHeader(OutputStream out)
Write the content type header to the specified output stream

Parameters: out The output stream

Throws: IOException If an IO problem occurs.

sendData

protected abstract void sendData(OutputStream out)
Write the data to the specified output stream

Parameters: out The output stream

Throws: IOException If an IO problem occurs.

sendDispositionHeader

protected void sendDispositionHeader(OutputStream out)
Write the content disposition header to the specified output stream

Parameters: out The output stream

Throws: IOException If an IO problem occurs.

sendEnd

protected void sendEnd(OutputStream out)
Write the end data to the output stream.

Parameters: out The output stream

Throws: IOException If an IO problem occurs.

sendEndOfHeader

protected void sendEndOfHeader(OutputStream out)
Write the end of the header to the output stream

Parameters: out The output stream

Throws: IOException If an IO problem occurs.

sendParts

public static void sendParts(OutputStream out, Part[] parts)
Write all parts and the last boundary to the specified output stream.

Parameters: out The stream to write to. parts The parts to write.

Throws: IOException If an I/O error occurs while writing the parts.

sendParts

public static void sendParts(OutputStream out, Part[] parts, byte[] partBoundary)
Write all parts and the last boundary to the specified output stream.

Parameters: out The stream to write to. parts The parts to write. partBoundary The ASCII bytes to use as the part boundary.

Throws: IOException If an I/O error occurs while writing the parts.

Since: 3.0

sendStart

protected void sendStart(OutputStream out)
Write the start to the specified output stream

Parameters: out The output stream

Throws: IOException If an IO problem occurs.

sendTransferEncodingHeader

protected void sendTransferEncodingHeader(OutputStream out)
Write the content transfer encoding header to the specified output stream

Parameters: out The output stream

Throws: IOException If an IO problem occurs.

toString

public String toString()
Return a string representation of this object.

Returns: A string representation of this object.

See Also: java.lang.Object#toString()

Copyright (c) 1999-2005 - Apache Software Foundation