Class Part
java.lang.Object
org.apache.commons.httpclient.methods.multipart.Part
- Direct Known Subclasses:
PartBase
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
FieldsModifier and TypeFieldDescriptionprotected static final StringDeprecated.protected static final byte[]Deprecated.protected static final StringContent charsetprotected static final byte[]Content charset as a byte arrayprotected static final StringContent dispostion charactersprotected static final byte[]Content dispostion as a byte arrayprotected static final StringContent type headerprotected static final byte[]Content type header as a byte arrayprotected static final StringContent type headerprotected static final byte[]Content type header as a byte arrayprotected static final StringCarriage return/linefeedprotected static final byte[]Carriage return/linefeed as a byte arrayprotected static final StringExtra charactersprotected static final byte[]Extra characters as a byte arrayprotected static final StringContent dispostion charactersprotected static final byte[]Content dispostion as a byte array -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringDeprecated.uses a constant string.abstract StringReturn the character encoding of this part.abstract StringReturns the content type of this part.static longgetLengthOfParts(Part[] parts) Return the total sum of all parts and that of the last boundarystatic 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[]Gets the part boundary to be used.abstract StringReturn the transfer encoding of this part.booleanTests if this part can be sent more than once.longlength()Return the full length of all the data.protected abstract longReturn the length of the main contentvoidsend(OutputStream out) Write all the data to the output stream.protected voidWrite the content type header to the specified output streamprotected abstract voidsendData(OutputStream out) Write the data to the specified output streamprotected voidWrite the content disposition header to the specified output streamprotected voidsendEnd(OutputStream out) Write the end data to the output stream.protected voidWrite the end of the header to the output streamstatic 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 streamprotected voidWrite the content transfer encoding header to the specified output streamtoString()Return a string representation of this object.
-
Field Details
-
BOUNDARY
Deprecated.The boundary- See Also:
-
BOUNDARY_BYTES
protected static final byte[] BOUNDARY_BYTESDeprecated.The boundary as a byte array. -
CRLF
-
CRLF_BYTES
protected static final byte[] CRLF_BYTESCarriage return/linefeed as a byte array -
QUOTE
-
QUOTE_BYTES
protected static final byte[] QUOTE_BYTESContent dispostion as a byte array -
EXTRA
-
EXTRA_BYTES
protected static final byte[] EXTRA_BYTESExtra characters as a byte array -
CONTENT_DISPOSITION
-
CONTENT_DISPOSITION_BYTES
protected static final byte[] CONTENT_DISPOSITION_BYTESContent dispostion as a byte array -
CONTENT_TYPE
-
CONTENT_TYPE_BYTES
protected static final byte[] CONTENT_TYPE_BYTESContent type header as a byte array -
CHARSET
-
CHARSET_BYTES
protected static final byte[] CHARSET_BYTESContent charset as a byte array -
CONTENT_TRANSFER_ENCODING
-
CONTENT_TRANSFER_ENCODING_BYTES
protected static final byte[] CONTENT_TRANSFER_ENCODING_BYTESContent type header as a byte array
-
-
Constructor Details
-
Part
public Part()
-
-
Method Details
-
getBoundary
Deprecated.uses a constant string. Rather usegetPartBoundary()Return the boundary string.- Returns:
- the boundary string
-
getName
-
getContentType
Returns the content type of this part.- Returns:
- the content type, or
nullto exclude the content type header
-
getCharSet
Return the character encoding of this part.- Returns:
- the character encoding, or
nullto exclude the character encoding header
-
getTransferEncoding
Return the transfer encoding of this part.- Returns:
- the transfer encoding, or
nullto exclude the transfer encoding header
-
getPartBoundary
protected byte[] getPartBoundary()Gets the part boundary to be used.- Returns:
- the part boundary as an array of bytes.
- Since:
- 3.0
-
isRepeatable
public boolean isRepeatable()Tests if this part can be sent more than once.- Returns:
trueifsendData(OutputStream)can be successfully called more than once.- Since:
- 3.0
-
sendStart
Write the start to the specified output stream- Parameters:
out- The output stream- Throws:
IOException- If an IO problem occurs.
-
sendDispositionHeader
Write the content disposition header to the specified output stream- Parameters:
out- The output stream- Throws:
IOException- If an IO problem occurs.
-
sendContentTypeHeader
Write the content type header to the specified output stream- Parameters:
out- The output stream- Throws:
IOException- If an IO problem occurs.
-
sendTransferEncodingHeader
Write the content transfer encoding header to the specified output stream- Parameters:
out- The output stream- Throws:
IOException- If an IO problem occurs.
-
sendEndOfHeader
Write the end of the header to the output stream- Parameters:
out- The output stream- Throws:
IOException- If an IO problem occurs.
-
sendData
Write the data to the specified output stream- Parameters:
out- The output stream- Throws:
IOException- If an IO problem occurs.
-
lengthOfData
Return the length of the main content- Returns:
- long The length.
- Throws:
IOException- If an IO problem occurs
-
sendEnd
Write the end data to the output stream.- Parameters:
out- The output stream- Throws:
IOException- If an IO problem occurs.
-
send
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.
-
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
-
toString
-
sendParts
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) throws IOException 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
-
getLengthOfParts
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
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
-
HttpMethodParams.MULTIPART_BOUNDARY