FilePartpublic class FilePart extends PartBase This class implements a part of a Multipart post object that
consists of a file. |
Fields Summary |
---|
public static final String | DEFAULT_CONTENT_TYPEDefault content encoding of file attachments. | public static final String | DEFAULT_CHARSETDefault charset of file attachments. | public static final String | DEFAULT_TRANSFER_ENCODINGDefault transfer encoding of file attachments. | private static final Log | LOGLog object for this class. | protected static final String | FILE_NAMEAttachment's file name | private static final byte[] | FILE_NAME_BYTESAttachment's file name as a byte array | private PartSource | sourceSource of the file part. |
Constructors Summary |
---|
public FilePart(String name, PartSource partSource, String contentType, String charset)FilePart Constructor.
super(
name,
contentType == null ? DEFAULT_CONTENT_TYPE : contentType,
charset == null ? "ISO-8859-1" : charset,
DEFAULT_TRANSFER_ENCODING
);
if (partSource == null) {
throw new IllegalArgumentException("Source may not be null");
}
this.source = partSource;
| public FilePart(String name, PartSource partSource)FilePart Constructor.
this(name, partSource, null, null);
| public FilePart(String name, File file)FilePart Constructor.
this(name, new FilePartSource(file), null, null);
| public FilePart(String name, File file, String contentType, String charset)FilePart Constructor.
this(name, new FilePartSource(file), contentType, charset);
| public FilePart(String name, String fileName, File file)FilePart Constructor.
this(name, new FilePartSource(fileName, file), null, null);
| public FilePart(String name, String fileName, File file, String contentType, String charset)FilePart Constructor.
this(name, new FilePartSource(fileName, file), contentType, charset);
|
Methods Summary |
---|
protected PartSource | getSource()Returns the source of the file part.
LOG.trace("enter getSource()");
return this.source;
| protected long | lengthOfData()Return the length of the data.
LOG.trace("enter lengthOfData()");
return source.getLength();
| protected void | sendData(java.io.OutputStream out)Write the data in "source" to the specified stream.
LOG.trace("enter sendData(OutputStream out)");
if (lengthOfData() == 0) {
// this file contains no data, so there is nothing to send.
// we don't want to create a zero length buffer as this will
// cause an infinite loop when reading.
LOG.debug("No data to send.");
return;
}
byte[] tmp = new byte[4096];
InputStream instream = source.createInputStream();
try {
int len;
while ((len = instream.read(tmp)) >= 0) {
out.write(tmp, 0, len);
}
} finally {
// we're done with the stream, close it
instream.close();
}
| protected void | sendDispositionHeader(java.io.OutputStream out)Write the disposition header to the output stream
LOG.trace("enter sendDispositionHeader(OutputStream out)");
super.sendDispositionHeader(out);
String filename = this.source.getFileName();
if (filename != null) {
out.write(FILE_NAME_BYTES);
out.write(QUOTE_BYTES);
out.write(EncodingUtils.getAsciiBytes(filename));
out.write(QUOTE_BYTES);
}
|
|