ds.setName(DataSourceClassPathResolver.class.getResource(resourceName).toString()); result = ds;
/** * Parses the MimePart to create a DataSource. * * @param parent the parent multi-part * @param part the current part to be processed * @return the DataSource * @throws MessagingException creating the DataSource failed * @throws IOException creating the DataSource failed */ protected DataSource createDataSource(final Multipart parent, final MimePart part) throws MessagingException, IOException { final DataHandler dataHandler = part.getDataHandler(); final DataSource dataSource = dataHandler.getDataSource(); final String contentType = getBaseMimeType(dataSource.getContentType()); final byte[] content = this.getContent(dataSource.getInputStream()); final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType); final String dataSourceName = getDataSourceName(part, dataSource); result.setName(dataSourceName); return result; }
s.readFully(content); ByteArrayDataSource dataSource = new ByteArrayDataSource(content, contentType); dataSource.setName(name);
ByteArrayDataSource dataSource = new ByteArrayDataSource(content, contentType); dataSource.setName(name);
/** * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates * to {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}. * * @param name The name of the image as being referred to from the message content body (eg. '<cid:signature>'). * @param data The byte data of the image to be embedded. * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg"). * @see ByteArrayDataSource * @see #addEmbeddedImage(String, DataSource) */ public Builder embedImage(final String name, final byte[] data, final String mimetype) { final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype); dataSource.setName(name); return embedImage(name, dataSource); }
/** * Adds an embedded image (attachment type) to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to * {@link #addEmbeddedImage(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}. * * @param name The name of the image as being referred to from the message content body (eg. '<cid:signature>'). * @param data The byte data of the image to be embedded. * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg"). * @see ByteArrayDataSource * @see #addEmbeddedImage(String, DataSource) */ public void addEmbeddedImage(final String name, final byte[] data, final String mimetype) { final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype); dataSource.setName(name); addEmbeddedImage(name, dataSource); }
s.readFully(content); ByteArrayDataSource dataSource = new ByteArrayDataSource(content, contentType); dataSource.setName(name);
/** * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to {@link * #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}. * * @param name The name of the extension (eg. filename including extension). * @param data The byte data of the attachment. * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf"). * @see ByteArrayDataSource * @see #addAttachment(String, DataSource) */ public void addAttachment(final String name, final byte[] data, final String mimetype) { final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype); dataSource.setName(name); addAttachment(name, dataSource); }
/** * Adds an attachment to the email message and generates the necessary {@link DataSource} with the given byte data. Then delegates to {@link * #addAttachment(String, DataSource)}. At this point the datasource is actually a {@link ByteArrayDataSource}. * * @param name The name of the extension (eg. filename including extension). * @param data The byte data of the attachment. * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf"). * @see ByteArrayDataSource * @see #addAttachment(String, DataSource) */ public Builder addAttachment(final String name, final byte[] data, final String mimetype) { final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype); dataSource.setName(name); addAttachment(name, dataSource); return this; }
@Override public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException { final javax.mail.util.ByteArrayDataSource ds = (javax.mail.util.ByteArrayDataSource) super.resolve(resourceLocation, isLenient); ds.setName(null); return ds; }
/** * Delegates to {@link #withEmbeddedImage(String, DataSource)}, with a named {@link ByteArrayDataSource} created using the provided name, data and * mimetype. * * @param name The name of the image as being referred to from the message content body (eg. 'signature'). * @param data The byte data of the image to be embedded. * @param mimetype The content type of the given data (eg. "image/gif" or "image/jpeg"). */ public EmailPopulatingBuilder withEmbeddedImage(@Nonnull final String name, @Nonnull final byte[] data, @Nonnull final String mimetype) { checkNonEmptyArgument(name, "name"); checkNonEmptyArgument(data, "data"); checkNonEmptyArgument(mimetype, "mimetype"); final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype); dataSource.setName(name); return withEmbeddedImage(name, dataSource); }
/** * Delegates to {@link #withAttachment(String, DataSource)}, with a named {@link ByteArrayDataSource} created using the provided name, data and * mimetype. * * @param name Optional name of the attachment (eg. 'filename.ext'). If omitted, the internal name of the datasource is used. If that too is * empty, a name will be generated using {@link java.util.UUID}. * @param data The binary data of the attachment. * @param mimetype The content type of the given data (eg. "plain/text", "image/gif" or "application/pdf"). * * @see #withAttachment(String, DataSource) * @see #withAttachments(List) */ public EmailPopulatingBuilder withAttachment(@Nullable final String name, @Nonnull final byte[] data, @Nonnull final String mimetype) { checkNonEmptyArgument(data, "data"); checkNonEmptyArgument(mimetype, "mimetype"); final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype); dataSource.setName(MiscUtil.encodeText(name)); withAttachment(name, dataSource); return this; }
/** * @param inStream * @param fileName * e.g. "file.txt" * @param fileExtension * e.g. "txt", "jpg" * @return */ public static DataSource createDataSource(InputStream inStream, String fileName, String fileExtension) { try { String mimeType = getContentTypeForExtension(fileExtension); if (mimeType == null) { mimeType = "application/octet-stream"; } ByteArrayDataSource item = new ByteArrayDataSource(inStream, mimeType); item.setName(fileName); return item; } catch (Exception e) { throw new ProcessingException("Unexpected: ", e); } }
public NormalizedMessageImpl(NormalizedMessage message) throws MessagingException { try { DOMSource domSource = (DOMSource)sourceTransformer.toDOMSource(message); if (domSource != null) { this.content = domSource; } for (Iterator it = message.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); this.properties.put(name, message.getProperty(name)); } for (Iterator it = message.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); DataHandler dh = message.getAttachment(name); DataSource ds = dh.getDataSource(); if (!(ds instanceof ByteArrayDataSource)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); copyInputStream(ds.getInputStream(), baos); ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), ds.getContentType()); bads.setName(ds.getName()); dh = new DataHandler(bads); } this.attachments.put(name, dh); } this.subject = message.getSecuritySubject(); } catch (MessagingException e) { throw e; } catch (Exception e) { throw new MessagingException(e); } }
final ByteArrayDataSource datasource = new ByteArrayDataSource(outputStream.toByteArray(), FileTypeMap.getDefaultFileTypeMap().getContentType(remoteFile.getName())); datasource.setName(remoteFile.getName()); final DataHandler result = new DataHandler(datasource); logger.fine(remoteFile.getName() + " set as DataHandler");
/** * The sftp-client MUST be connected. This method DOES NOT close the * sftp-client * * @param remoteFile * @param client * a sftpclient, MUST be CONNECTED * @return the retrieved file, as a datahandler * @throws IOException * the file is not found or FTP access problem */ private DataHandler getAsDataHandler(SftpFile remoteFile, SftpClient client) throws IOException { DataHandler result; this.logger.info("start receiving file " + remoteFile.getFilename() + " from SFTP server"); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(remoteFile .getAttributes().getSize().intValue()); client.get(remoteFile.getFilename(), outputStream); outputStream.flush(); logger.finest(remoteFile.getFilename() + " file received from SFTP server"); final ByteArrayDataSource datasource = new ByteArrayDataSource(outputStream.toByteArray(), FileTypeMap.getDefaultFileTypeMap().getContentType(remoteFile.getFilename())); outputStream.close(); datasource.setName(remoteFile.getFilename()); result = new DataHandler(datasource); logger.finest(remoteFile.getFilename() + " set as DataHandler"); return result; }
/** * Parses the MimePart to create a DataSource. * * @param part the current part to be processed * @return the DataSource */ @Nonnull private static DataSource createDataSource(@Nonnull final MimePart part) { final DataHandler dataHandler = retrieveDataHandler(part); final DataSource dataSource = dataHandler.getDataSource(); final String contentType = parseBaseMimeType(dataSource.getContentType()); final byte[] content = readContent(retrieveInputStream(dataSource)); final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType); final String dataSourceName = parseDataSourceName(part, dataSource); result.setName(dataSourceName); return result; }
public DataSource toDataSource() { byte [] data = getData(); ByteArrayDataSource dataSource = new ByteArrayDataSource(data, new Tika().detect(data)); dataSource.setName(getName()); return dataSource; } }
/** * Parses the MimePart to create a DataSource. * * @param parent the parent multi-part * @param part the current part to be processed * @return the DataSource * @throws MessagingException creating the DataSource failed * @throws IOException creating the DataSource failed */ protected DataSource createDataSource(final Multipart parent, final MimePart part) throws MessagingException, IOException { final DataHandler dataHandler = part.getDataHandler(); final DataSource dataSource = dataHandler.getDataSource(); final String contentType = getBaseMimeType(dataSource.getContentType()); final byte[] content = this.getContent(dataSource.getInputStream()); final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType); final String dataSourceName = getDataSourceName(part, dataSource); result.setName(dataSourceName); return result; }
/** * Parses the MimePart to create a DataSource. * * @param part the current part to be processed * @return the DataSource * @throws MessagingException creating the DataSource failed * @throws IOException creating the DataSource failed */ protected DataSource createDataSource(final MimePart part) throws MessagingException, IOException { final DataHandler dataHandler = part.getDataHandler(); final DataSource dataSource = dataHandler.getDataSource(); final String contentType = getBaseMimeType(dataSource.getContentType()); final byte[] content = this.getContent(dataSource.getInputStream()); final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType); final String dataSourceName = getDataSourceName(part, dataSource); result.setName(dataSourceName); return result; }