javax.mail.internet.MimeMessage.getDataHandler()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中javax.mail.internet.MimeMessage.getDataHandler()方法的一些代码示例,展示了MimeMessage.getDataHandler()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeMessage.getDataHandler()方法的具体详情如下:
包路径:javax.mail.internet.MimeMessage
类名称:MimeMessage
方法名:getDataHandler

MimeMessage.getDataHandler介绍

[英]Return a DataHandler for this Message's content.

The implementation provided here works approximately as follows. Note the use of the getContentStream method to generate the byte stream for the content. Also note that any transfer-decoding is done automatically within this method.

getDataHandler() { 
if (dh == null) { 
dh = new DataHandler(new MimePartDataSource(this)); 
} 
return dh; 
} 
class MimePartDataSource implements DataSource { 
public getInputStream() { 
return MimeUtility.decode( 
getContentStream(), getEncoding()); 
} 
.... <other DataSource methods> 
}

[中]返回此邮件内容的DataHandler。
这里提供的实现大致如下。注意使用getContentStream方法为内容生成字节流。还要注意的是,任何传输解码都是在此方法中自动完成的。

getDataHandler() { 
if (dh == null) { 
dh = new DataHandler(new MimePartDataSource(this)); 
} 
return dh; 
} 
class MimePartDataSource implements DataSource { 
public getInputStream() { 
return MimeUtility.decode( 
getContentStream(), getEncoding()); 
} 
.... <other DataSource methods> 
}

代码示例

代码示例来源:origin: cloudfoundry/uaa

public String getContentString() throws MessagingException, IOException {
  return StreamUtils.copyToString(mimeMessage.getDataHandler().getInputStream(), Charset.forName("UTF-8"));
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Return a decoded input stream for this Message's "content". <p>
 *
 * This implementation obtains the input stream from the DataHandler,
 * that is, it invokes <code>getDataHandler().getInputStream()</code>.
 *
 * @return         an InputStream
 * @exception       IOException this is typically thrown by the
 *            DataHandler. Refer to the documentation for
 *            javax.activation.DataHandler for more details.
 * @exception    MessagingException for other failures
 *
 * @see    #getContentStream
 * @see     javax.activation.DataHandler#getInputStream
 */
public InputStream getInputStream() 
  throws IOException, MessagingException {
return getDataHandler().getInputStream();
}

代码示例来源:origin: com.sun.mail/javax.mail

/**
 * Return a decoded input stream for this Message's "content". <p>
 *
 * This implementation obtains the input stream from the DataHandler,
 * that is, it invokes <code>getDataHandler().getInputStream()</code>.
 *
 * @return         an InputStream
 * @exception       IOException this is typically thrown by the
 *            DataHandler. Refer to the documentation for
 *            javax.activation.DataHandler for more details.
 * @exception    MessagingException for other failures
 *
 * @see    #getContentStream
 * @see     javax.activation.DataHandler#getInputStream
 */
@Override
public InputStream getInputStream() 
  throws IOException, MessagingException {
return getDataHandler().getInputStream();
}

代码示例来源:origin: camunda/camunda-bpm-platform

public static String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException {
 DataHandler dataHandler = mimeMessage.getDataHandler();
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 dataHandler.writeTo(baos);
 baos.flush();
 return baos.toString();
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException {
 DataHandler dataHandler = mimeMessage.getDataHandler();
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 dataHandler.writeTo(baos);
 baos.flush();
 return baos.toString();
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void testMessageConversionWithHtmlAndContentType() throws Exception {
  JavaMailSender sender = mock(JavaMailSender.class);
  MailSendingMessageHandler handler = new MailSendingMessageHandler(sender);
  StringWriter writer = new StringWriter();
  FileReader reader = new FileReader("src/test/java/org/springframework/integration/mail/config/test.html");
  FileCopyUtils.copy(reader, writer);
  Message<String> message = MessageBuilder.withPayload(writer.getBuffer().toString())
              .setHeader(MailHeaders.TO, "to")
              .setHeader(MailHeaders.FROM, "from")
              .setHeader(MailHeaders.CONTENT_TYPE, "text/html")
              .build();
  MimeMessage mMessage = new TestMimeMessage();
  // MOCKS
  when(sender.createMimeMessage()).thenReturn(mMessage);
  doAnswer(invocation -> {
    MimeMessage mimeMessage = invocation.getArgument(0);
    assertEquals("text/html", mimeMessage.getDataHandler().getContentType());
    return null;
  }).when(sender).send(Mockito.any(MimeMessage.class));
  // handle message
  handler.handleMessage(message);
  verify(sender, times(1)).send(Mockito.any(MimeMessage.class));
}

代码示例来源:origin: camunda/camunda-bpm-platform

return super.getDataHandler();

代码示例来源:origin: com.sun.mail/javax.mail

return super.getDataHandler();

代码示例来源:origin: camunda/camunda-bpm-platform

Object c;
try {
  c = getDataHandler().getContent();
} catch (FolderClosedIOException fex) {
  throw new FolderClosedException(fex.getFolder(), fex.getMessage());

代码示例来源:origin: com.sun.mail/javax.mail

Object c;
try {
  c = getDataHandler().getContent();
} catch (FolderClosedIOException fex) {
  throw new FolderClosedException(fex.getFolder(), fex.getMessage());

代码示例来源:origin: org.apache.james/james-server-core-library

/**
 * @see javax.mail.Part#getDataHandler()
 */
public DataHandler getDataHandler() throws MessagingException {
  return getWrappedMessage().getDataHandler();
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

public Object getContent() throws MessagingException, IOException {
  return getDataHandler().getContent();
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

public InputStream getInputStream() throws MessagingException, IOException {
  return getDataHandler().getInputStream();
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

public Object getContent() throws MessagingException, IOException {
  return getDataHandler().getContent();
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

public InputStream getInputStream() throws MessagingException, IOException {
  return getDataHandler().getInputStream();
}

代码示例来源:origin: org.glassfish.metro/webservices-extra

/**
 * Return a decoded input stream for this Message's "content". <p>
 *
 * This implementation obtains the input stream from the DataHandler,
 * that is, it invokes <code>getDataHandler().getInputStream()</code>.
 *
 * @return         an InputStream
 * @exception       IOException this is typically thrown by the
 *            DataHandler. Refer to the documentation for
 *            javax.activation.DataHandler for more details.
 * @exception    MessagingException for other failures
 *
 * @see    #getContentStream
 * @see     javax.activation.DataHandler#getInputStream
 */
@Override
public InputStream getInputStream() 
  throws IOException, MessagingException {
return getDataHandler().getInputStream();
}

代码示例来源:origin: javax.mail/javax.mail-api

/**
 * Return a decoded input stream for this Message's "content". <p>
 *
 * This implementation obtains the input stream from the DataHandler,
 * that is, it invokes <code>getDataHandler().getInputStream()</code>.
 *
 * @return         an InputStream
 * @exception       IOException this is typically thrown by the
 *            DataHandler. Refer to the documentation for
 *            javax.activation.DataHandler for more details.
 * @exception    MessagingException for other failures
 *
 * @see    #getContentStream
 * @see     javax.activation.DataHandler#getInputStream
 */
@Override
public InputStream getInputStream() 
  throws IOException, MessagingException {
return getDataHandler().getInputStream();
}

代码示例来源:origin: com.meltmedia.cadmium/cadmium-email

public MimeBodyPart newOriginalBodyPart( MimeMessage message )
  throws MessagingException
 {
  // get the data handler for this message.
  DataHandler handler = message.getDataHandler();

  // add the original body to the new body part.
  MimeBodyPart originalPart = new MimeBodyPart();
  originalPart.setDataHandler(handler);
  originalPart.setHeader("Content-ID", "original-message");

  return originalPart;
 }
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

protected String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException {
 DataHandler dataHandler = mimeMessage.getDataHandler();
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 dataHandler.writeTo(baos);
 baos.flush();
 return baos.toString();
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

public static String getMessage(MimeMessage mimeMessage) throws MessagingException, IOException {
 DataHandler dataHandler = mimeMessage.getDataHandler();
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 dataHandler.writeTo(baos);
 baos.flush();
 return baos.toString();
}

相关文章

MimeMessage类方法