com.ning.http.multipart
Class Part

java.lang.Object
  extended by com.ning.http.multipart.Part
All Implemented Interfaces:
Part
Direct Known Subclasses:
PartBase

public abstract class Part
extends Object
implements Part

This class is an adaptation of the Apache HttpClient implementation


Field Summary
protected static String BOUNDARY
          The boundary
protected static String CHARSET
          Content charset
protected static String CONTENT_DISPOSITION
          Content dispostion characters
protected static String CONTENT_TRANSFER_ENCODING
          Content type header
protected static String CONTENT_TYPE
          Content type header
protected static String CRLF
          Carriage return/linefeed
protected static String EXTRA
          Extra characters
protected static String QUOTE
          Content dispostion characters
 
Constructor Summary
Part()
           
 
Method Summary
static String getBoundary()
          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.
protected  byte[] getPartBoundary()
          Gets the part boundary to be used.
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.
protected abstract  long lengthOfData()
          Return the length of the main content
 void send(OutputStream out)
          Write all the data to the output stream.
protected  void sendContentTypeHeader(OutputStream out)
          Write the content type header to the specified output stream
protected abstract  void sendData(OutputStream out)
          Write the data to the specified output stream
protected  void sendDispositionHeader(OutputStream out)
          Write the content disposition header to the specified output stream
protected  void sendEnd(OutputStream out)
          Write the end data to the output stream.
protected  void sendEndOfHeader(OutputStream out)
          Write the end of the header 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.
protected  void sendStart(OutputStream out)
          Write the start to the specified output stream
protected  void sendTransferEncodingHeader(OutputStream out)
          Write the content transfer encoding header to the specified output stream
 String toString()
          Return a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BOUNDARY

protected static final String BOUNDARY
The boundary

See Also:
Constant Field Values

CRLF

protected static final String CRLF
Carriage return/linefeed

See Also:
Constant Field Values

QUOTE

protected static final String QUOTE
Content dispostion characters

See Also:
Constant Field Values

EXTRA

protected static final String EXTRA
Extra characters

See Also:
Constant Field Values

CONTENT_DISPOSITION

protected static final String CONTENT_DISPOSITION
Content dispostion characters

See Also:
Constant Field Values

CONTENT_TYPE

protected static final String CONTENT_TYPE
Content type header

See Also:
Constant Field Values

CHARSET

protected static final String CHARSET
Content charset

See Also:
Constant Field Values

CONTENT_TRANSFER_ENCODING

protected static final String CONTENT_TRANSFER_ENCODING
Content type header

See Also:
Constant Field Values
Constructor Detail

Part

public Part()
Method Detail

getBoundary

public static String getBoundary()
Deprecated. uses a constant string. Rather use getPartBoundary()

Return the boundary string.

Returns:
the boundary string

getName

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

Specified by:
getName in interface Part
Returns:
The name.

getContentType

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

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

getCharSet

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

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

getTransferEncoding

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

Returns:
the transfer encoding, or null to 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:
true if sendData(java.io.OutputStream) can be successfully called more than once.
Since:
3.0

sendStart

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

Parameters:
out - The output stream
Throws:
IOException - If an IO problem occurs.

sendDispositionHeader

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

Parameters:
out - The output stream
Throws:
IOException - If an IO problem occurs.

sendContentTypeHeader

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

Parameters:
out - The output stream
Throws:
IOException - If an IO problem occurs.

sendTransferEncodingHeader

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

Parameters:
out - The output stream
Throws:
IOException - If an IO problem occurs.

sendEndOfHeader

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

Parameters:
out - The output stream
Throws:
IOException - If an IO problem occurs.

sendData

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

Parameters:
out - The output stream
Throws:
IOException - If an IO problem occurs.

lengthOfData

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

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

sendEnd

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

Parameters:
out - The output stream
Throws:
IOException - If an IO problem occurs.

send

public void send(OutputStream out)
          throws IOException
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

public long length()
            throws IOException
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

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

Overrides:
toString in class Object
Returns:
A string representation of this object.
See Also:
Object.toString()

sendParts

public static void sendParts(OutputStream out,
                             Part[] parts)
                      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.
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

sendMessageEnd

public static void sendMessageEnd(OutputStream out,
                                  byte[] partBoundary)
                           throws IOException
Throws:
IOException

sendPart

public static void sendPart(OutputStream out,
                            Part part,
                            byte[] partBoundary)
                     throws IOException
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.
Since:
N/A

getLengthOfParts

public static long getLengthOfParts(Part[] parts)
                             throws IOException
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)
                             throws IOException
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


Copyright © 2011. All Rights Reserved.