當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteArrayDataSource.setName方法代碼示例

本文整理匯總了Java中javax.mail.util.ByteArrayDataSource.setName方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteArrayDataSource.setName方法的具體用法?Java ByteArrayDataSource.setName怎麽用?Java ByteArrayDataSource.setName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.util.ByteArrayDataSource的用法示例。


在下文中一共展示了ByteArrayDataSource.setName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBuilderSimpleBuildWithStandardEmail

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
@Test
public void testBuilderSimpleBuildWithStandardEmail()
		throws IOException {
	ByteArrayDataSource namedAttachment = new ByteArrayDataSource("Black Tie Optional", "text/plain");
	namedAttachment.setName("dresscode.txt"); // normally not needed, but otherwise the equals will fail
	String base64String = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABeElEQVRYw2NgoAAYGxu3GxkZ7TY1NZVloDcAWq4MxH+B+D8Qv3FwcOCgtwM6oJaDMTAUXOhmuYqKCjvQ0pdoDrCnmwNMTEwakC0H4u8GBgYC9Ap6DSD+iewAoIPm0ctyLqBlp9F8/x+YE4zpYT8T0LL16JYD8U26+B7oyz4sloPwenpYno3DchCeROsUbwa05A8eB3wB4kqgIxOAuArIng7EW4H4EhC/B+JXQLwDaI4ryZaDSjeg5mt4LCcFXyIn1fdSyXJQVt1OtMWGhoai0OD8T0W8GohZifE1PxD/o7LlsPLiFNAKRrwOABWptLAcqc6QGDAHQEOAYaAc8BNotsJAOgAUAosG1AFA/AtUoY3YEFhKMAvS2AE7iC1+WaG1H6gY3gzE36hUFJ8mqzbU1dUVBBqQBzTgIDQRkWo5qCZdpaenJ0Zx1aytrc0DDB0foIG1oAYKqC0IZK8D4n1AfA6IzwPxXpCFoGoZVEUDaRGGUTAKRgEeAAA2eGJC+ETCiAAAAABJRU5ErkJggg==";
	
	final Email email = EmailBuilder.startingBlank()
			.from("lollypop", "[email protected]")
			.to("C.Cane", "[email protected]")
			.withPlainText("We should meet up!")
			.withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>")
			.withSubject("hey")
			.withAttachment("dresscode.txt", namedAttachment)
			.withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain")
			.withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png")
			.buildEmail();
	
	assertThat(EmailHelper.createDummyEmailBuilder(true, true, false).buildEmail()).isEqualTo(email);
}
 
開發者ID:bbottema,項目名稱:simple-java-mail,代碼行數:21,代碼來源:EmailPopulatingBuilderUsingDefaultsFromPropertyFileTest.java

示例2: testBuilderSimpleBuildWithStandardEmail_PlusOptionals

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
@Test
public void testBuilderSimpleBuildWithStandardEmail_PlusOptionals()
		throws IOException {
	ByteArrayDataSource namedAttachment = new ByteArrayDataSource("Black Tie Optional", "text/plain");
	namedAttachment.setName("dresscode.txt"); // normally not needed, but otherwise the equals will fail
	String base64String = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABeElEQVRYw2NgoAAYGxu3GxkZ7TY1NZVloDcAWq4MxH+B+D8Qv3FwcOCgtwM6oJaDMTAUXOhmuYqKCjvQ0pdoDrCnmwNMTEwakC0H4u8GBgYC9Ap6DSD+iewAoIPm0ctyLqBlp9F8/x+YE4zpYT8T0LL16JYD8U26+B7oyz4sloPwenpYno3DchCeROsUbwa05A8eB3wB4kqgIxOAuArIng7EW4H4EhC/B+JXQLwDaI4ryZaDSjeg5mt4LCcFXyIn1fdSyXJQVt1OtMWGhoai0OD8T0W8GohZifE1PxD/o7LlsPLiFNAKRrwOABWptLAcqc6QGDAHQEOAYaAc8BNotsJAOgAUAosG1AFA/AtUoY3YEFhKMAvS2AE7iC1+WaG1H6gY3gzE36hUFJ8mqzbU1dUVBBqQBzTgIDQRkWo5qCZdpaenJ0Zx1aytrc0DDB0foIG1oAYKqC0IZK8D4n1AfA6IzwPxXpCFoGoZVEUDaRGGUTAKRgEeAAA2eGJC+ETCiAAAAABJRU5ErkJggg==";
	
	final Email email = EmailBuilder.startingBlank()
			.from("lollypop", "[email protected]")
			.withReplyTo("lollypop-reply", "[email protected]")
			.withBounceTo("lollypop-bounce", "[email protected]")
			.to("C.Cane", "[email protected]")
			.withPlainText("We should meet up!")
			.withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>")
			.withSubject("hey")
			.withAttachment("dresscode.txt", namedAttachment)
			.withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain")
			.withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png")
			.withDispositionNotificationTo("[email protected]")
			.withReturnReceiptTo("Complex Email", "[email protected]")
			.withHeader("dummyHeader", "dummyHeaderValue")
			.buildEmail();
	
	assertThat(EmailHelper.createDummyEmailBuilder(true, false, true).buildEmail()).isEqualTo(email);
}
 
開發者ID:bbottema,項目名稱:simple-java-mail,代碼行數:26,代碼來源:EmailPopulatingBuilderUsingDefaultsFromPropertyFileTest.java

示例3: ebMSMessageContentToEbMSMessage

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
public static EbMSMessage ebMSMessageContentToEbMSMessage(CollaborationProtocolAgreement cpa, EbMSMessageContent content, String hostname) throws DatatypeConfigurationException
{
	MessageHeader messageHeader = createMessageHeader(cpa,content.getContext(),hostname);

	AckRequested ackRequested = createAckRequested(cpa,content.getContext());
	
	Manifest manifest = createManifest();
	for (int i = 0; i < content.getAttachments().size(); i++)
		manifest.getReference().add(createReference(i + 1));
	
	List<DataSource> attachments = new ArrayList<DataSource>();
	for (EbMSAttachment attachment : content.getAttachments())
	{
		ByteArrayDataSource ds = new ByteArrayDataSource(attachment.getContent(),attachment.getContentType());
		ds.setName(attachment.getName());
		attachments.add(ds);
	}

	return new EbMSMessage(messageHeader,ackRequested,manifest,attachments);
}
 
開發者ID:mprins,項目名稱:muleebmsadapter,代碼行數:21,代碼來源:EbMSMessageUtils.java

示例4: createDataSource

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
/**
 * 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
 */
private static 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 = MimeMessageParser.getContent(dataSource.getInputStream());
    final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType);
    final String dataSourceName = getDataSourceName(part, dataSource);

    result.setName(dataSourceName);
    return result;
}
 
開發者ID:QianWorks,項目名稱:qianworks-meican,代碼行數:21,代碼來源:MimeMessageParser.java

示例5: createDataSource

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:bbottema,項目名稱:simple-java-mail,代碼行數:19,代碼來源:MimeMessageParser.java

示例6: withEmbeddedImage

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:bbottema,項目名稱:simple-java-mail,代碼行數:18,代碼來源:EmailPopulatingBuilder.java

示例7: createDummyEmailBuilder

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
public static EmailPopulatingBuilder createDummyEmailBuilder(@Nullable String id, boolean includeSubjectAndBody, boolean basicFields, boolean includeCustomHeaders)
		throws IOException {
	EmailPopulatingBuilder builder = EmailBuilder.startingBlank()
			.fixingMessageId(id)
			.from("lollypop", "[email protected]")
			// don't forget to add your own address here ->
			.to("C.Cane", "[email protected]");
	
	if (!basicFields) {
		// normally not needed, but for the test it is because the MimeMessage will
		// have it added automatically as well, so the parsed Email will also have it then
		builder = builder
			.withReplyTo("lollypop-reply", "[email protected]")
			.withBounceTo("lollypop-bounce", "[email protected]");
	}
	if (includeSubjectAndBody) {
		builder = builder
			.withSubject("hey")
			.withPlainText("We should meet up!")
			.withHTMLText("<b>We should meet up!</b><img src='cid:thumbsup'>");
	}

	if (includeCustomHeaders) {
		builder = builder
			.withHeader("dummyHeader", "dummyHeaderValue")
			.withDispositionNotificationTo("[email protected]")
			.withReturnReceiptTo("Complex Email", "[email protected]");
	}

	// add two text files in different ways and a black thumbs up embedded image ->
	ByteArrayDataSource namedAttachment = new ByteArrayDataSource("Black Tie Optional", "text/plain");
	namedAttachment.setName("dresscode.txt"); // normally not needed, but otherwise the equals will fail
	String base64String = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABeElEQVRYw2NgoAAYGxu3GxkZ7TY1NZVloDcAWq4MxH+B+D8Qv3FwcOCgtwM6oJaDMTAUXOhmuYqKCjvQ0pdoDrCnmwNMTEwakC0H4u8GBgYC9Ap6DSD+iewAoIPm0ctyLqBlp9F8/x+YE4zpYT8T0LL16JYD8U26+B7oyz4sloPwenpYno3DchCeROsUbwa05A8eB3wB4kqgIxOAuArIng7EW4H4EhC/B+JXQLwDaI4ryZaDSjeg5mt4LCcFXyIn1fdSyXJQVt1OtMWGhoai0OD8T0W8GohZifE1PxD/o7LlsPLiFNAKRrwOABWptLAcqc6QGDAHQEOAYaAc8BNotsJAOgAUAosG1AFA/AtUoY3YEFhKMAvS2AE7iC1+WaG1H6gY3gzE36hUFJ8mqzbU1dUVBBqQBzTgIDQRkWo5qCZdpaenJ0Zx1aytrc0DDB0foIG1oAYKqC0IZK8D4n1AfA6IzwPxXpCFoGoZVEUDaRGGUTAKRgEeAAA2eGJC+ETCiAAAAABJRU5ErkJggg==";
	
	return builder
			.withAttachment("dresscode.txt", namedAttachment)
			.withAttachment("location.txt", "On the moon!".getBytes(Charset.defaultCharset()), "text/plain")
			.withEmbeddedImage("thumbsup", parseBase64Binary(base64String), "image/png");
}
 
開發者ID:bbottema,項目名稱:simple-java-mail,代碼行數:40,代碼來源:EmailHelper.java

示例8: getBodyAsDataSource

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
public DataSource getBodyAsDataSource(String fileName, AttachmentType type) throws IOException
{

    final ByteArrayDataSource body = new ByteArrayDataSource(reportBody, type.toString());
    body.setName(fileName);

    return body;
}
 
開發者ID:rlsutton1,項目名稱:VaadinUtils,代碼行數:9,代碼來源:RenderedReport.java

示例9: attach

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public void attach(MimePart part) throws MessagingException, IOException
{
    log.log(Level.FINE,"Attempting reattachment for {0} of type {1}", new Object[]{part, part.getContentType()});

	String contentType = part.getContentType().toLowerCase();
	
	if (contentType.startsWith("multipart/"))
	{
	    log.log(Level.FINE,"Content is multipart");
		
		Multipart multi = (Multipart)part.getContent();
		
		// This is necessary because of the mysterious JavaMail bug 4404733
		part.setContent(multi);

		for (int i=0; i<multi.getCount(); i++)
			this.attach((MimePart)multi.getBodyPart(i));
	}
	else if (contentType.startsWith(SubEthaMessage.DETACHMENT_MIME_TYPE))
	{
		Long attachmentId = (Long)part.getContent();

		log.log(Level.FINE,"Reattaching attachment {0} for type {1}", new Object[]{attachmentId, contentType});

		try
		{
			Attachment att = this.em.get(Attachment.class, attachmentId);
               if (INPUTSTREAM_RESET_NOT_NEEDED_OR_ISSUE_44)
               {
                   String ct = att.getContentType();
                   ByteArrayDataSource bads = new ByteArrayDataSource(att.getContentStream(), ct);
                   //this was lazy, now it always runs. What is the performance impact (~6 string searches/operations)?
                   if (ct!=null) bads.setName(MailUtils.getNameFromContentType(ct));
                   DataHandler dh = new DataHandler(bads);
                   
                   part.setDataHandler(dh);
               }
               else
               {
   				part.setDataHandler(
   						new DataHandler(
   								new TrivialDataSource(
   										att.getContentStream(),
   										att.getContentType())));
               }
			part.removeHeader(SubEthaMessage.HDR_ORIGINAL_CONTENT_TYPE);
		}
		catch (NotFoundException ex)
		{
			// Log an error and otherwise leave the mime part as-is.
		    log.log(Level.SEVERE,"Missing referenced attachment {0}", attachmentId);
		}
	}
	else
	{
		Object content = part.getContent();
		
		if (content instanceof MimePart)
		{
		    log.log(Level.FINE,"Content {0} is part, probably a message", contentType );
			
			this.attach((MimePart)content);
		}
		else
		{
		    log.log(Level.FINE,"Ignoring part of type {0}", contentType);
		}
	}
}
 
開發者ID:voodoodyne,項目名稱:subetha,代碼行數:71,代碼來源:DetacherBean.java

示例10: getDataSource

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
private ByteArrayDataSource getDataSource(String name)
		throws IOException {
	ByteArrayDataSource ds = new ByteArrayDataSource("", "text/text");
	ds.setName(name);
	return ds;
}
 
開發者ID:bbottema,項目名稱:simple-java-mail,代碼行數:7,代碼來源:MimeMessageHelperTest.java

示例11: addAttachment

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
/**
 * 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 EmailBuilder 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;
}
 
開發者ID:QianWorks,項目名稱:qianworks-meican,代碼行數:17,代碼來源:EmailBuilder.java

示例12: withAttachment

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:bbottema,項目名稱:simple-java-mail,代碼行數:21,代碼來源:EmailPopulatingBuilder.java

示例13: embedImage

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
/**
 * 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 Email#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. '&lt;cid:signature&gt;').
 * @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 Email#addEmbeddedImage(String, DataSource)
 */
public EmailBuilder embedImage(final String name, final byte[] data, final String mimetype) {
	final ByteArrayDataSource dataSource = new ByteArrayDataSource(data, mimetype);
	dataSource.setName(name);
	return embedImage(name, dataSource);
}
 
開發者ID:QianWorks,項目名稱:qianworks-meican,代碼行數:16,代碼來源:EmailBuilder.java

示例14: addEmbeddedImage

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
/**
 * 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. '&lt;cid:signature&gt;').
 * @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);
}
 
開發者ID:QianWorks,項目名稱:qianworks-meican,代碼行數:16,代碼來源:Email.java

示例15: addAttachment

import javax.mail.util.ByteArrayDataSource; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:QianWorks,項目名稱:qianworks-meican,代碼行數:16,代碼來源:Email.java


注:本文中的javax.mail.util.ByteArrayDataSource.setName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。