/** * Saves attachment to a file. * * @param destination The destination file to be written. */ public void writeToFile(final File destination) { InputStream input = null; final OutputStream output; try { input = getDataSource().getInputStream(); output = new FileOutputStream(destination); StreamUtil.copy(input, output); } catch (final IOException ioex) { throw new MailException(ioex); } finally { StreamUtil.close(input); } }
/** * Saves attachment to the output stream. * * @param out OutputStream where attachment should be copied to. */ public void writeToStream(final OutputStream out) { InputStream input = null; try { input = getDataSource().getInputStream(); StreamUtil.copy(input, out); } catch (final IOException ioex) { throw new MailException(ioex); } finally { StreamUtil.close(input); } }
/** * Creates attachment body part. Handles regular and inline attachments. * * @param attachment Body part {@link EmailAttachment}. * @return {@link MimeBodyPart} which represents body part attachment. * @throws MessagingException if there is a failure. */ protected MimeBodyPart createAttachmentBodyPart(final EmailAttachment<? extends DataSource> attachment) throws MessagingException { final MimeBodyPart part = new MimeBodyPart(); final String attachmentName = attachment.getEncodedName(); if (attachmentName != null) { part.setFileName(attachmentName); } part.setDataHandler(new DataHandler(attachment.getDataSource())); if (attachment.getContentId() != null) { part.setContentID(StringPool.LEFT_CHEV + attachment.getContentId() + StringPool.RIGHT_CHEV); } if (attachment.isInline()) { part.setDisposition(INLINE); } return part; }
/** * Saves attachment to a file. * * @param destination The destination file to be written. */ public void writeToFile(final File destination) { InputStream input = null; final OutputStream output; try { input = getDataSource().getInputStream(); output = new FileOutputStream(destination); StreamUtil.copy(input, output); } catch (final IOException ioex) { throw new MailException(ioex); } finally { StreamUtil.close(input); } }
/** * Saves attachment to the output stream. * * @param out OutputStream where attachment should be copied to. */ public void writeToStream(final OutputStream out) { InputStream input = null; try { input = getDataSource().getInputStream(); StreamUtil.copy(input, out); } catch (final IOException ioex) { throw new MailException(ioex); } finally { StreamUtil.close(input); } }
/** * Creates attachment body part. Handles regular and inline attachments. * * @param attachment Body part {@link EmailAttachment}. * @return {@link MimeBodyPart} which represents body part attachment. * @throws MessagingException if there is a failure. */ protected MimeBodyPart createAttachmentBodyPart(final EmailAttachment<? extends DataSource> attachment) throws MessagingException { final MimeBodyPart part = new MimeBodyPart(); final String attachmentName = attachment.getEncodedName(); if (attachmentName != null) { part.setFileName(attachmentName); } part.setDataHandler(new DataHandler(attachment.getDataSource())); if (attachment.getContentId() != null) { part.setContentID(StringPool.LEFT_CHEV + attachment.getContentId() + StringPool.RIGHT_CHEV); } if (attachment.isInline()) { part.setDisposition(INLINE); } return part; }