Construct a new MimeMessageInputStreamSource from an
InputStream
that contains the bytes of a
MimeMessage.
//We want to immediately read this into a temporary file
//Create a temp file and channel the input stream into it
OutputStream fout = null;
try {
file = File.createTempFile(key, ".m64");
fout = new BufferedOutputStream(new FileOutputStream(file));
int b = -1;
while ((b = in.read()) != -1) {
fout.write(b);
}
fout.flush();
sourceId = file.getCanonicalPath();
} catch (IOException ioe) {
// We had an IOException preparing the temporary file, so
// don't just leave it around to garbage collect later.
// It isn't as if we are going to use it after we throw
// the MessagingException.
if (fout != null) try {
fout.close();
fout = null;
} catch (IOException _) {
// Ignored - logging unavailable to log this error.
}
if (file != null) {
file.delete();
file = null;
}
throw new MessagingException("Unable to retrieve the data: " + ioe.getMessage(), ioe);
} finally {
try {
if (fout != null) {
fout.close();
}
} catch (IOException ioe) {
// Ignored - logging unavailable to log this non-fatal error.
}
try {
if (in != null) {
in.close();
}
} catch (IOException ioe) {
// Ignored - logging unavailable to log this non-fatal error.
}
}