FileBackedMimeBodyPartpublic class FileBackedMimeBodyPart extends MimeBodyPart
Fields Summary |
---|
private static final int | BUF_SIZE | private final File | _file |
Constructors Summary |
---|
public FileBackedMimeBodyPart(File file)Create a MimeBodyPart backed by the data in file.
super(new SharedFileInputStream(file));
_file = file;
| public FileBackedMimeBodyPart(InputStream content, File file)Create a MimeBodyPart backed by file based on the headers and
content data in content.
this(saveStreamToFile(content, file));
| public FileBackedMimeBodyPart(InternetHeaders headers, InputStream body, File file)Create a MimeBodyPart backed by file, with the headers
given in headers and body content taken from the stream body.
this(saveStreamToFile(headers, body, file));
|
Methods Summary |
---|
public void | dispose()Close off the underlying shared streams and remove the backing file.
((SharedFileInputStream)contentStream).getRoot().dispose();
if (_file.exists() && !_file.delete())
{
throw new IOException("deletion of underlying file <" + _file.getCanonicalPath() + "> failed.");
}
| private static void | saveContentToStream(java.io.OutputStream out, java.io.InputStream content)
byte[] buf = new byte[BUF_SIZE];
int len;
while ((len = content.read(buf, 0, buf.length)) > 0)
{
out.write(buf, 0, len);
}
out.close();
content.close();
| private static java.io.File | saveStreamToFile(java.io.InputStream content, java.io.File tempFile)
saveContentToStream(new FileOutputStream(tempFile), content);
return tempFile;
| private static java.io.File | saveStreamToFile(javax.mail.internet.InternetHeaders headers, java.io.InputStream content, java.io.File tempFile)
OutputStream out = new FileOutputStream(tempFile);
Enumeration en = headers.getAllHeaderLines();
while (en.hasMoreElements())
{
writeHeader(out, (String)en.nextElement());
}
writeSeperator(out);
saveContentToStream(out, content);
return tempFile;
| private static void | writeHeader(java.io.OutputStream out, java.lang.String header)
for (int i = 0; i != header.length(); i++)
{
out.write(header.charAt(i));
}
writeSeperator(out);
| private static void | writeSeperator(java.io.OutputStream out)
out.write('\r");
out.write('\n");
| public void | writeTo(java.io.OutputStream out)
if (!_file.exists())
{
throw new IOException("file " + _file.getCanonicalPath() + " no longer exists.");
}
super.writeTo(out);
|
|