public abstract class

Part

extends Object
implements Part
java.lang.Object
   ↳ com.ning.http.multipart.Part
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

This class is an adaptation of the Apache HttpClient implementationhttp://hc.apache.org/httpclient-3.x/

Summary

Constants
String BOUNDARY The boundary
String CHARSET Content charset
String CONTENT_DISPOSITION Content dispostion characters
String CONTENT_TRANSFER_ENCODING Content type header
String CONTENT_TYPE Content type header
String CRLF Carriage return/linefeed
String EXTRA Extra characters
String QUOTE Content dispostion characters
Public Constructors
Part()
Public Methods
static String getBoundary()
This method is deprecated. uses a constant string. Rather use getPartBoundary()
abstract String getCharSet()
Return the character encoding of this part.
abstract String getContentType()
Returns the content type of this part.
static long getLengthOfParts(Part[] parts)
Return the total sum of all parts and that of the last boundary
static long getLengthOfParts(Part[] parts, byte[] partBoundary)
Gets the length of the multipart message including the given parts.
abstract String getName()
Return the name of this part.
abstract String getTransferEncoding()
Return the transfer encoding of this part.
boolean isRepeatable()
Tests if this part can be sent more than once.
long length()
Return the full length of all the data.
void send(OutputStream out)
Write all the data to the output stream.
static void sendMessageEnd(OutputStream out, byte[] partBoundary)
static void sendPart(OutputStream out, Part part, byte[] partBoundary)
Write all parts and the last boundary to the specified output stream.
static void sendParts(OutputStream out, Part[] parts)
Write all parts and the last boundary to the specified output stream.
static void sendParts(OutputStream out, Part[] parts, byte[] partBoundary)
Write all parts and the last boundary to the specified output stream.
String toString()
Return a string representation of this object.
Protected Methods
byte[] getPartBoundary()
Gets the part boundary to be used.
abstract long lengthOfData()
Return the length of the main content
void sendContentTypeHeader(OutputStream out)
Write the content type header to the specified output stream
abstract void sendData(OutputStream out)
Write the data to the specified output stream
void sendDispositionHeader(OutputStream out)
Write the content disposition header to the specified output stream
void sendEnd(OutputStream out)
Write the end data to the output stream.
void sendEndOfHeader(OutputStream out)
Write the end of the header to the output stream
void sendStart(OutputStream out)
Write the start to the specified output stream
void sendTransferEncodingHeader(OutputStream out)
Write the content transfer encoding header to the specified output stream
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.ning.http.client.Part

Constants

protected static final String BOUNDARY

The boundary

Constant Value: "----------------314159265358979323846"

protected static final String CHARSET

Content charset

Constant Value: "; charset="

protected static final String CONTENT_DISPOSITION

Content dispostion characters

Constant Value: "Content-Disposition: form-data; name="

protected static final String CONTENT_TRANSFER_ENCODING

Content type header

Constant Value: "Content-Transfer-Encoding: "

protected static final String CONTENT_TYPE

Content type header

Constant Value: "Content-Type: "

protected static final String CRLF

Carriage return/linefeed

Constant Value: " "

protected static final String EXTRA

Extra characters

Constant Value: "--"

protected static final String QUOTE

Content dispostion characters

Constant Value: """

Public Constructors

public Part ()

Public Methods

public static String getBoundary ()

This method is deprecated.
uses a constant string. Rather use getPartBoundary()

Return the boundary string.

Returns
  • the boundary string

public abstract String getCharSet ()

Return the character encoding of this part.

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

public abstract String getContentType ()

Returns the content type of this part.

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

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.

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.

public abstract String getName ()

Return the name of this part.

Returns
  • The name.

public abstract String getTransferEncoding ()

Return the transfer encoding of this part.

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

public boolean isRepeatable ()

Tests if this part can be sent more than once.

Returns

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

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.

public static void sendMessageEnd (OutputStream out, byte[] partBoundary)

Throws
IOException

public static void sendPart (OutputStream out, Part part, byte[] partBoundary)

Write all parts and the last boundary to the specified output stream.

Parameters
out The stream to write to.
part The part to write.
Throws
IOException If an I/O error occurs while writing the parts.

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.

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.

public String toString ()

Return a string representation of this object.

Returns
  • A string representation of this object.
See Also

Protected Methods

protected byte[] getPartBoundary ()

Gets the part boundary to be used.

Returns
  • the part boundary as an array of bytes.

protected abstract long lengthOfData ()

Return the length of the main content

Returns
  • long The length.
Throws
IOException If an IO problem occurs

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.

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.

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.

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.

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.

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.

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.