当前位置: 首页>>代码示例>>Java>>正文


Java MimeUtility.decode方法代码示例

本文整理汇总了Java中javax.mail.internet.MimeUtility.decode方法的典型用法代码示例。如果您正苦于以下问题:Java MimeUtility.decode方法的具体用法?Java MimeUtility.decode怎么用?Java MimeUtility.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.internet.MimeUtility的用法示例。


在下文中一共展示了MimeUtility.decode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decodeBase64

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/***
 * decode base64
 *
 * @param b
 * @return
 * @throws Exception
 */
// metas: 03749
public static byte[] decodeBase64(byte[] b)
{
	try
	{
		ByteArrayInputStream bais = new ByteArrayInputStream(b);
		InputStream b64is = MimeUtility.decode(bais, "base64");
		byte[] tmp = new byte[b.length];
		int n = b64is.read(tmp);
		byte[] res = new byte[n];
		System.arraycopy(tmp, 0, res, 0, n);
		return res;
	}
	catch (Exception e)
	{
		throw new AdempiereException(e);
	}
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:26,代码来源:Util.java

示例2: decodeFromUtf8

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
private static String decodeFromUtf8(String text, String encoding, String charset) throws Exception {
    if (text.length() == 0) {
        return text;
    }

    byte[] asciiBytes = text.getBytes("UTF-8");
    InputStream decodedStream = MimeUtility.decode(new ByteArrayInputStream(asciiBytes), encoding);
    byte[] tmp = new byte[asciiBytes.length];
    int n = decodedStream.read(tmp);
    byte[] res = new byte[n];
    System.arraycopy(tmp, 0, res, 0, n);
    return new String(res, charset);
}
 
开发者ID:saksham,项目名称:hulaki,代码行数:14,代码来源:SmtpMessage.java

示例3: write

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
 * Outputs the decoded content from the
 * <code>encodedString</quote> string to the <code>os</code> output stream.
 * 
 * @param os the output stream
 * @param encodedString the content to write 
 * @param charsetName the name of the charset
 * @param encoding the name of the encoding
 * @throws IOException
 * @throws MessagingException
 */
public static void write(OutputStream os, String encodedString,
        String charsetName, String encoding) throws IOException,
        MessagingException
{
    String charset = charsetName != null ? MimeUtility
            .javaCharset(charsetName) : null;
    byte[] b = charset == null ? encodedString.getBytes() : encodedString
            .getBytes(charset);
    InputStream is = MimeUtility.decode(new ByteArrayInputStream(b),
            encoding);

    byte[] buffer = new byte[4096];
    int nb = 0;

    while ((nb = is.read(buffer)) >= 0)
        os.write(buffer, 0, nb);
}
 
开发者ID:edeoliveira,项目名称:Mailster,代码行数:29,代码来源:MailUtilities.java

示例4: getInputStream

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/** 
 * Gets <code>InputStream</code> from which data in the
 * <code>AttachmentDataSource</code> can be read.
 * 
 * @return An <code>InputStream</code>.
 * @throws IOException 
 */
public InputStream getInputStream() throws IOException {
    final InputStream is;
    if (data != null) {
        is = new ByteArrayInputStream(data);
    }
    else {
        InputStream fis = null;
        if (dataSource != null) {
            fis = dataSource.getInputStream();
        } else {
            final File file = new File(name);
            if (file.length() < (offset + length)) {
                throw new IOException("Premature end-of-file: file name=" +
                    name + " | file length=" + file.length() + " | offset=" +
                    offset + " | length to be read=" + length);
            }
            fis = new FileInputStream(name);
        }
        is = new PartialInputStream(fis, offset, length);
    }

    if (encoding == null) {
        return is;
    }
    else {
        try {
            return MimeUtility.decode(is, encoding);
        }
        catch (MessagingException e) {
            throw new IOException(e.getMessage());
        }
    }
}
 
开发者ID:cecid,项目名称:hermes,代码行数:41,代码来源:AttachmentDataSource.java

示例5: decode

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
 * Dekodiert einen UTF-8-QUOTED-PRINTABLE-String in einen Java-Unicode-String.
 */
public String decode(String in) {
	try {
		InputStream input = MimeUtility.decode(new ReaderInputStream(new StringReader(in), "UTF-8"),
				"quoted-printable");
		StringWriter sw = new StringWriter();
		OutputStream output = new WriterOutputStream(sw, "UTF-8");
		copyAndClose(input, output);
		return sw.toString();
	} catch (Exception e) {
		throw new RuntimeException("Exception caught in VntConverter.encode(in):", e);
	}

}
 
开发者ID:udamken,项目名称:VntConverter,代码行数:17,代码来源:VntConverter.java

示例6: decodeContentTypeAsQuotedPrintable

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
 * Try to decode the contentType String as quoted-printable String into a ContentType.
 * @param contentType
 * @return new ContentType instance or null
 */
private static ContentType decodeContentTypeAsQuotedPrintable(String contentType) {
	try {
		ByteArrayInputStream baos = new ByteArrayInputStream(contentType.getBytes("utf-8"));
		InputStream decode = MimeUtility.decode(baos, "quoted-printable");
		String contentTypeString = new String(ByteStreams.toByteArray(decode), "utf-8");
		return new ContentType(contentTypeString);
	} catch (Exception e) {
		return null;
	}
}
 
开发者ID:nickrussler,项目名称:eml-to-pdf-converter,代码行数:16,代码来源:ContentTypeCleaner.java

示例7: decode

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
public static byte[] decode(byte[] b) throws IOException, MessagingException  {
   ByteArrayInputStream bais = new ByteArrayInputStream(b);
   InputStream b64is = MimeUtility.decode(bais, "base64");
   byte[] tmp = new byte[b.length];
   int n = b64is.read(tmp);
   byte[] res = new byte[n];
   System.arraycopy(tmp, 0, res, 0, n);
   return res;
}
 
开发者ID:frapu78,项目名称:processeditor,代码行数:10,代码来源:Base64Utils.java

示例8: decode

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
 * Decodes the string <code>encodedString</code> encoded as
 * <code>encoding</code> with the charset named <code>charsetName</code>.
 * If decoding fails, it returns the original string.
 * <p>
 * All the encodings defined in RFC 2045 are supported here. They include
 * "base64", "quoted-printable", "7bit", "8bit", and "binary". In addition,
 * "uuencode" is also supported.
 * 
 * @see javax.mail.internet.MimeUtility#decode(java.io.InputStream, java.lang.String)
 * @param encodedString the string to decode
 * @param charsetName the name of the charset
 * @param encoding the encoding used for the string
 * @return the decoded String
 */
public static String decode(String encodedString, String charsetName,
        String encoding)
{
    try
    {
        String charset = charsetName != null ? MimeUtility
                .javaCharset(charsetName) : null;
        byte[] b = charset == null
                ? encodedString.getBytes()
                : encodedString.getBytes(charset);
        InputStream is = MimeUtility.decode(new ByteArrayInputStream(b),
                encoding);

        StringBuilder sb = new StringBuilder();
        byte[] buffer = new byte[4096];
        int nb = 0;

        while ((nb = is.read(buffer)) >= 0)
            sb.append(new String(buffer, 0, nb));

        return sb.toString();
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return encodedString;
    }
    catch (NoClassDefFoundError nex)
    {
        nex.printStackTrace();
        return encodedString;
    }
}
 
开发者ID:edeoliveira,项目名称:Mailster,代码行数:49,代码来源:MailUtilities.java

示例9: decodeMIMEText

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
 * Abstract the encoding issue.
 * @param stm raw stream
 * @param enc  a transfer encoding named in the multipart header, see MimeUtility.decode() for more detail
 * @return byte data for the stream.  Caller still has to decode to proper charset.
 * @throws Exception on error
 */
private static byte[] decodeMIMEText(InputStream stm, String enc) throws Exception {
    InputStream decodedContent = null;
    try {
        decodedContent = MimeUtility.decode(stm, enc);
        return IOUtils.toByteArray(decodedContent);
    } finally {
        if (decodedContent != null) {
            decodedContent.close();
        }
    }

}
 
开发者ID:OpenSextant,项目名称:Xponents,代码行数:20,代码来源:MessageConverter.java

示例10: decode

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
public static InputStream decode(String contentTransferEncoding, String source) throws UnsupportedEncodingException, MessagingException {
    return MimeUtility.decode(new ByteArrayInputStream(source.getBytes()), contentTransferEncoding);
}
 
开发者ID:BandwidthOnDemand,项目名称:nsi-dds,代码行数:4,代码来源:ContentTransferEncoding.java

示例11: getMessageContent

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
   * Extracts the content of an email message.
   * 
   * Since the content's MIME type varies, the extraction has different ways.
   * 
   * @param fullMessage the full message content
   * @return the extracted content of an email message
   * @throws MessagingException
   * @throws IOException 
   */
  protected EmailContent getMessageContent(Message fullMessage) throws MessagingException, IOException {
//    return new EmailContent(new HtmlContent("test", HtmlContent.ContentType.TEXT), null);
//    System.setProperty("javax.activation.debug", "true");
    HtmlContent content = new HtmlContent();
    List<Attachment> attachments = null;

    Object msg;
    try {
      msg = fullMessage.getContent();
    } catch (UnsupportedEncodingException e) {
      Log.d("yako", "", e);
      HtmlContent hc = new HtmlContent("<span style='color: red;'>Unsupported content encoding</span>",
              HtmlContent.ContentType.TEXT_HTML);
      return new EmailContent(hc, null);
    }

    if (fullMessage.isMimeType("text/*")) {

      if (fullMessage.isMimeType("text/html")) {
        content = new HtmlContent((String) msg, HtmlContent.ContentType.TEXT_HTML);
      } else if (fullMessage.isMimeType("text/plain")) {
        content = new HtmlContent((String) msg, HtmlContent.ContentType.TEXT_PLAIN);
      } else {
        content = new HtmlContent((String) msg, HtmlContent.ContentType.TEXT);
      }

    } else if (fullMessage.isMimeType("multipart/*")) {

      if (msg instanceof Multipart) {
        Multipart mp = (Multipart) msg;
        content = getContentOfMultipartMessage(mp, 0);
        attachments = getAttachmentsOfMultipartMessage(mp, true, 0);

      }

    } else if (msg instanceof IMAPInputStream) {
      IMAPInputStream imapIs = (IMAPInputStream) msg;
      InputStream dis = MimeUtility.decode(imapIs, "binary");

      BufferedReader br = new BufferedReader(new InputStreamReader(dis));
      String line;
      while ((line = br.readLine()) != null) {
        content.getContent().append(line);
      }
    } else {
      System.out.println("Nem tudom 2");
    }
    return new EmailContent(content, attachments);
  }
 
开发者ID:k-kojak,项目名称:yako,代码行数:60,代码来源:SimpleEmailMessageProvider.java

示例12: decode

import javax.mail.internet.MimeUtility; //导入方法依赖的package包/类
/**
 * Decode base64 encoded String
 * 
 * @param b64string
 *            base64 String
 * @return reader the BufferedReader which holds the decoded base64 text
 * @throws MessagingException
 *             get thrown when an error was detected while trying to decode
 *             the String
 */
public static BufferedReader decode(String b64string) throws MessagingException {
    return new BufferedReader(new InputStreamReader(MimeUtility.decode(new ByteArrayInputStream(b64string.getBytes()), "base64")));
}
 
开发者ID:twachan,项目名称:James,代码行数:14,代码来源:Base64.java


注:本文中的javax.mail.internet.MimeUtility.decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。