com.ning.http.multipart
Class FilePart

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

public class FilePart
extends PartBase

This class is an adaptation of the Apache HttpClient implementation


Field Summary
static String DEFAULT_CHARSET
          Default charset of file attachments.
static String DEFAULT_CONTENT_TYPE
          Default content encoding of file attachments.
static String DEFAULT_TRANSFER_ENCODING
          Default transfer encoding of file attachments.
protected static String FILE_NAME
          Attachment's file name
 
Fields inherited from class com.ning.http.multipart.Part
BOUNDARY, CHARSET, CONTENT_DISPOSITION, CONTENT_TRANSFER_ENCODING, CONTENT_TYPE, CRLF, EXTRA, QUOTE
 
Constructor Summary
FilePart(String name, File file)
          FilePart Constructor.
FilePart(String name, File file, String contentType, String charset)
          FilePart Constructor.
FilePart(String name, PartSource partSource)
          FilePart Constructor.
FilePart(String name, PartSource partSource, String contentType, String charset)
          FilePart Constructor.
FilePart(String name, String fileName, File file)
          FilePart Constructor.
FilePart(String name, String fileName, File file, String contentType, String charset)
          FilePart Constructor.
 
Method Summary
protected  PartSource getSource()
          Returns the source of the file part.
protected  long lengthOfData()
          Return the length of the data.
protected  void sendData(OutputStream out)
          Write the data in "source" to the specified stream.
protected  void sendDispositionHeader(OutputStream out)
          Write the disposition header to the output stream
 
Methods inherited from class com.ning.http.multipart.PartBase
getCharSet, getContentType, getName, getTransferEncoding, setCharSet, setContentType, setName, setTransferEncoding
 
Methods inherited from class com.ning.http.multipart.Part
getBoundary, getLengthOfParts, getLengthOfParts, getPartBoundary, isRepeatable, length, send, sendContentTypeHeader, sendEnd, sendEndOfHeader, sendMessageEnd, sendPart, sendParts, sendParts, sendStart, sendTransferEncodingHeader, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CONTENT_TYPE

public static final String DEFAULT_CONTENT_TYPE
Default content encoding of file attachments.

See Also:
Constant Field Values

DEFAULT_CHARSET

public static final String DEFAULT_CHARSET
Default charset of file attachments.

See Also:
Constant Field Values

DEFAULT_TRANSFER_ENCODING

public static final String DEFAULT_TRANSFER_ENCODING
Default transfer encoding of file attachments.

See Also:
Constant Field Values

FILE_NAME

protected static final String FILE_NAME
Attachment's file name

See Also:
Constant Field Values
Constructor Detail

FilePart

public FilePart(String name,
                PartSource partSource,
                String contentType,
                String charset)
FilePart Constructor.

Parameters:
name - the name for this part
partSource - the source for this part
contentType - the content type for this part, if null the default is used
charset - the charset encoding for this part, if null the default is used

FilePart

public FilePart(String name,
                PartSource partSource)
FilePart Constructor.

Parameters:
name - the name for this part
partSource - the source for this part

FilePart

public FilePart(String name,
                File file)
         throws FileNotFoundException
FilePart Constructor.

Parameters:
name - the name of the file part
file - the file to post
Throws:
FileNotFoundException - if the file is not a normal file or if it is not readable.

FilePart

public FilePart(String name,
                File file,
                String contentType,
                String charset)
         throws FileNotFoundException
FilePart Constructor.

Parameters:
name - the name of the file part
file - the file to post
contentType - the content type for this part, if null the default is used
charset - the charset encoding for this part, if null the default is used
Throws:
FileNotFoundException - if the file is not a normal file or if it is not readable.

FilePart

public FilePart(String name,
                String fileName,
                File file)
         throws FileNotFoundException
FilePart Constructor.

Parameters:
name - the name of the file part
fileName - the file name
file - the file to post
Throws:
FileNotFoundException - if the file is not a normal file or if it is not readable.

FilePart

public FilePart(String name,
                String fileName,
                File file,
                String contentType,
                String charset)
         throws FileNotFoundException
FilePart Constructor.

Parameters:
name - the name of the file part
fileName - the file name
file - the file to post
contentType - the content type for this part, if null the default is used
charset - the charset encoding for this part, if null the default is used
Throws:
FileNotFoundException - if the file is not a normal file or if it is not readable.
Method Detail

sendDispositionHeader

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

Overrides:
sendDispositionHeader in class Part
Parameters:
out - The output stream
Throws:
IOException - If an IO problem occurs

sendData

protected void sendData(OutputStream out)
                 throws IOException
Write the data in "source" to the specified stream.

Specified by:
sendData in class Part
Parameters:
out - The output stream.
Throws:
IOException - if an IO problem occurs.

getSource

protected PartSource getSource()
Returns the source of the file part.

Returns:
The source.

lengthOfData

protected long lengthOfData()
                     throws IOException
Return the length of the data.

Specified by:
lengthOfData in class Part
Returns:
The length.
Throws:
IOException - if an IO problem occurs


Copyright © 2011. All Rights Reserved.