org.apache.commons.httpclient.methods.multipart

Class FilePart

public class FilePart extends PartBase

This class implements a part of a Multipart post object that consists of a file.

Since: 2.0

Author: Matthew Albright Jeff Dever Adrian Sutton Michael Becke Mark Diggory Mike Bowler Oleg Kalnichevski

Field Summary
static StringDEFAULT_CHARSET
Default charset of file attachments.
static StringDEFAULT_CONTENT_TYPE
Default content encoding of file attachments.
static StringDEFAULT_TRANSFER_ENCODING
Default transfer encoding of file attachments.
protected static StringFILE_NAME
Attachment's file name
Constructor Summary
FilePart(String name, PartSource partSource, String contentType, String charset)
FilePart Constructor.
FilePart(String name, PartSource partSource)
FilePart Constructor.
FilePart(String name, File file)
FilePart Constructor.
FilePart(String name, File file, 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 PartSourcegetSource()
Returns the source of the file part.
protected longlengthOfData()
Return the length of the data.
protected voidsendData(OutputStream out)
Write the data in "source" to the specified stream.
protected voidsendDispositionHeader(OutputStream out)
Write the disposition header to the output stream

Field Detail

DEFAULT_CHARSET

public static final String DEFAULT_CHARSET
Default charset of file attachments.

DEFAULT_CONTENT_TYPE

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

DEFAULT_TRANSFER_ENCODING

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

FILE_NAME

protected static final String FILE_NAME
Attachment's file name

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 {@link #DEFAULT_CONTENT_TYPE default} is used charset the charset encoding for this part, if null the {@link #DEFAULT_CHARSET 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)
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)
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 {@link #DEFAULT_CONTENT_TYPE default} is used charset the charset encoding for this part, if null the {@link #DEFAULT_CHARSET 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)
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)
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 {@link #DEFAULT_CONTENT_TYPE default} is used charset the charset encoding for this part, if null the {@link #DEFAULT_CHARSET default} is used

Throws: FileNotFoundException if the file is not a normal file or if it is not readable.

Method Detail

getSource

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

Returns: The source.

lengthOfData

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

Returns: The length.

Throws: IOException if an IO problem occurs

See Also: lengthOfData

sendData

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

Parameters: out The output stream.

Throws: IOException if an IO problem occurs.

See Also: sendData

sendDispositionHeader

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

Parameters: out The output stream

Throws: IOException If an IO problem occurs

See Also: sendDispositionHeader

Copyright (c) 1999-2005 - Apache Software Foundation