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


Java ContentType类代码示例

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


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

示例1: getContent

import javax.mail.internet.ContentType; //导入依赖的package包/类
private Object getContent(final Part part, final ContentType contentType) throws MessagingException, IOException {
    try {
        return part.getContent();
    } catch (IOException e) {
        if (isPlainText(contentType)) {
            final InputStream rawInputStream;
            if (part instanceof MimeMessage) {
                rawInputStream = ((MimeMessage) part).getRawInputStream();
            } else if (part instanceof MimeBodyPart) {
                rawInputStream = ((MimeBodyPart) part).getRawInputStream();
            } else {
                throw new ParseException("Unexpected part: " + part);
            }

            return new String(ByteStreams.toByteArray(rawInputStream), getCharset(contentType));
        }
    }

    throw new ParseException("No content");
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:21,代码来源:MessageParser.java

示例2: getRegularPartContentType

import javax.mail.internet.ContentType; //导入依赖的package包/类
/**
 * Get the content type of a regular part
 *
 * @param partIndex
 *            the index of the regular part
 * @return the content type as string
 * @throws PackageException
 */
@PublicAtsApi
public String getRegularPartContentType(
                                         int partIndex ) throws PackageException {

    // first check if there is part at this position at all
    if (partIndex >= regularPartIndices.size()) {
        throw new NoSuchMimePartException("No regular part at position '" + partIndex + "'");
    }

    try {
        MimePart part = getPart(regularPartIndices.get(partIndex));

        // get the content type header
        ContentType contentType = new ContentType(part.getContentType());
        return contentType.getBaseType();
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:28,代码来源:MimePackage.java

示例3: getRegularPartCharset

import javax.mail.internet.ContentType; //导入依赖的package包/类
/**
 * Get the character set of a regular part
 *
 * @param partIndex
 *            the index of the part
 * @return the charset
 * @throws PackageException
 */
@PublicAtsApi
public String getRegularPartCharset(
                                     int partIndex ) throws PackageException {

    // first check if there is part at this position at all
    if (partIndex >= regularPartIndices.size()) {
        throw new NoSuchMimePartException("No regular part at position '" + partIndex + "'");
    }

    try {
        MimePart part = getPart(regularPartIndices.get(partIndex));

        // get the content type header
        ContentType contentType = new ContentType(part.getContentType());
        return contentType.getParameter("charset");
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:28,代码来源:MimePackage.java

示例4: getAttachmentContentType

import javax.mail.internet.ContentType; //导入依赖的package包/类
/**
 * Get the attachment content type
 *
 * @param partIndex
 * @return
 * @throws PackageException
 */
@PublicAtsApi
public String getAttachmentContentType(
                                        int partIndex ) throws PackageException {

    // first check if there is part at this position at all
    if (partIndex >= attachmentPartIndices.size()) {
        throw new NoSuchMimePartException("No attachment at position '" + partIndex + "'");
    }

    try {
        MimePart part = getPart(attachmentPartIndices.get(partIndex));

        // get the content type header
        ContentType contentType = new ContentType(part.getContentType());
        return contentType.getBaseType();
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:27,代码来源:MimePackage.java

示例5: getAttachmentCharset

import javax.mail.internet.ContentType; //导入依赖的package包/类
/**
 * Get the attachment character set
 *
 * @param partIndex
 *            the index of the attachment
 * @return the character set for this attachment, null if there is no such
 * @throws PackageException
 */
@PublicAtsApi
public String getAttachmentCharset(
                                    int partIndex ) throws PackageException {

    // first check if there is part at this position at all
    if (partIndex >= attachmentPartIndices.size()) {
        throw new NoSuchMimePartException("No attachment at position '" + partIndex + "'");
    }

    try {
        MimePart part = getPart(attachmentPartIndices.get(partIndex));

        // get the content type header
        ContentType contentType = new ContentType(part.getContentType());
        return contentType.getParameter("charset");
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:28,代码来源:MimePackage.java

示例6: applyTo

import javax.mail.internet.ContentType; //导入依赖的package包/类
@Override
public void applyTo(final HTTPRequest httpRequest) {
    if (httpRequest.getMethod() != HTTPRequest.Method.GET)
        throw new SerializeException("The HTTP request method must be GET");

    ContentType ct = httpRequest.getContentType();
    if (ct == null)
        throw new SerializeException("Missing HTTP Content-Type header");

    if (! ct.match(CommonContentTypes.APPLICATION_URLENCODED))
        throw new SerializeException("The HTTP Content-Type header must be "
        + CommonContentTypes.APPLICATION_URLENCODED);

    Map<String,String> params = httpRequest.getQueryParameters();
    params.putAll(toParameters());
    String queryString = URLUtils.serializeParameters(params);
    httpRequest.setQuery(queryString);
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:19,代码来源:ClientSecretGet.java

示例7: getTextFromMimeMultipart

import javax.mail.internet.ContentType; //导入依赖的package包/类
private String getTextFromMimeMultipart( MimeMultipart mimeMultipart ) throws IOException, MessagingException
{

    int count = mimeMultipart.getCount();
    if ( count == 0 )
        throw new MessagingException( "Multipart with no body parts not supported." );

    boolean multipartAlt = new ContentType( mimeMultipart.getContentType() ).match( "multipart/alternative" );
    if ( multipartAlt )
        return getTextFromBodyPart( mimeMultipart.getBodyPart( count - 1 ) );

    String result = "";
    for ( int i = 0; i < count; i++ )
    {
        BodyPart bodyPart = mimeMultipart.getBodyPart( i );
        result += getTextFromBodyPart( bodyPart );
    }
    return result;
}
 
开发者ID:xframium,项目名称:xframium-java,代码行数:20,代码来源:DefaultReceiveEmailProvider.java

示例8: printAllTextPlainMessages

import javax.mail.internet.ContentType; //导入依赖的package包/类
public static void printAllTextPlainMessages(final Folder folder) throws MessagingException, IOException {
	for (final Message m : folder.getMessages()) {
		System.out.println("\nNachricht:");
		System.out.println("Von: " + Arrays.toString(m.getFrom()));
		System.out.println("Betreff: " + m.getSubject());
		System.out.println("Gesendet am: " + m.getSentDate());
		System.out.println("Content-Type: " + new ContentType(m.getContentType()));

		if (m.isMimeType("text/plain")) {
			System.out.println(m.getContent());
		}
	}
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:14,代码来源:EmailUtils.java

示例9: cleanContentType

import javax.mail.internet.ContentType; //导入依赖的package包/类
/**
 * Attempt to repair the given contentType if broken.
 * @param mp Mimepart holding the contentType
 * @param contentType ContentType
 * @return fixed contentType String
 * @throws MessagingException
 */
public static String cleanContentType(MimePart mp, String contentType) throws MessagingException {
	ContentType ct = parseContentType(contentType);

	if (ct == null) {
		ct = getParsableContentType(contentType);
	}

	if (ct.getBaseType().equalsIgnoreCase("text/plain") || ct.getBaseType().equalsIgnoreCase("text/html")) {
		Charset charset = parseCharset(ct);
		if (charset == null) {
			Logger.debug("Charset of the ContentType could not be read, try to decode the contentType as quoted-printable");

			ContentType ctTmp = decodeContentTypeAsQuotedPrintable(contentType);
			if (parseCharset(ctTmp) != null) {
				ct = ctTmp;
			} else {
				ct.setParameter("charset", ContentTypeCleaner.DEFAULT_CHARSET);
			}
		}
	}

	return ct.toString();
}
 
开发者ID:nickrussler,项目名称:eml-to-pdf-converter,代码行数:31,代码来源:ContentTypeCleaner.java

示例10: processDocument

import javax.mail.internet.ContentType; //导入依赖的package包/类
public OMElement processDocument(Reader reader, String contentType,
                                 MessageContext messageContext) throws AxisFault {
    String charset;
    try {
        ContentType ct = new ContentType(contentType);
        charset = ct.getParameter("charset");
    } catch (ParseException ex) {
        charset = null;
    }
    if (charset == null) {
        charset = MessageContext.DEFAULT_CHAR_SET_ENCODING;
    }
    messageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charset);        
    return processDocument(new ReaderInputStream(reader, charset), contentType,
            messageContext);
}
 
开发者ID:wso2,项目名称:wso2-axis2-transports,代码行数:17,代码来源:TextMessageBuilderAdapter.java

示例11: decode

import javax.mail.internet.ContentType; //导入依赖的package包/类
public XMLMessage decode(ContentType contentType, AxisMessage message) throws Exception {
        Attachments attachments = message.getAttachments();
        XMLMessage.Type type;
        if (attachments != null) {
            type = XMLMessage.Type.SWA;
        } else {
            type = null;
            for (XMLMessage.Type candidate : XMLMessage.Type.values()) {
                if (candidate.getContentType().equals(message.getMessageType())) {
                    type = candidate;
                    break;
                }
            }
            if (type == null) {
                // TODO: make this an error later
                type = XMLMessage.Type.POX;
//                throw new UnsupportedOperationException("Content type " + message.getMessageType() + " not supported");
            }
        }
        return new XMLMessage(message.getEnvelope().getBody().getFirstElement(), type, attachments);
    }
 
开发者ID:wso2,项目名称:wso2-axis2-transports,代码行数:22,代码来源:MessageDecoder.java

示例12: MessageTestCase

import javax.mail.internet.ContentType; //导入依赖的package包/类
public MessageTestCase(TestClient client, ContentType contentType, String charset, Object... resources) {
    super(resources);
    if (client instanceof Adapter) {
        addResource(((Adapter)client).getTarget());
    } else {
        addResource(client);
    }
    this.contentType = contentType;
    try {
        options = new ClientOptions(client, contentType, charset);
    } catch (Exception ex) {
        // TODO: handle this in a better way
        throw new Error(ex);
    }
    addResource(options);
    addResource(this);
}
 
开发者ID:wso2,项目名称:wso2-axis2-transports,代码行数:18,代码来源:MessageTestCase.java

示例13: getTextContent

import javax.mail.internet.ContentType; //导入依赖的package包/类
/**
 * Extract the text content for a {@link BodyPart}, assuming the default
 * encoding.
 */
public static String getTextContent(BodyPart part) throws MessagingException, IOException {
  ContentType contentType = new ContentType(part.getContentType());
  String charset = contentType.getParameter("charset");
  if (charset == null) {
    // N.B.(schwardo): The MIME spec doesn't seem to provide a
    // default charset, but the default charset for HTTP is
    // ISO-8859-1.  That seems like a reasonable default.
    charset = "ISO-8859-1";
  }

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  ByteStreams.copy(part.getInputStream(), baos);
  try {
    return new String(baos.toByteArray(), charset);
  } catch (UnsupportedEncodingException ex) {
    return new String(baos.toByteArray());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:23,代码来源:MultipartMimeUtils.java

示例14: createMultiPartEntity

import javax.mail.internet.ContentType; //导入依赖的package包/类
/**
 * Helper function to create multi-part MIME
 *
 * @param entity         the body of a request
 * @param entityContentType content type of the body
 * @param query          a query part of a request
 *
 * @return a ByteString that represents a multi-part encoded entity that contains both
 */
private static MimeMultipart createMultiPartEntity(ByteString entity, String entityContentType, String query)
    throws MessagingException
{
  MimeMultipart multi = new MimeMultipart(MIXED);

  // Create current entity with the associated type
  MimeBodyPart dataPart = new MimeBodyPart();

  ContentType contentType = new ContentType(entityContentType);
  dataPart.setContent(entity.copyBytes(), contentType.getBaseType());
  dataPart.setHeader(HEADER_CONTENT_TYPE, entityContentType);

  // Encode query params as form-urlencoded
  MimeBodyPart argPart = new MimeBodyPart();
  argPart.setContent(query, FORM_URL_ENCODED);
  argPart.setHeader(HEADER_CONTENT_TYPE, FORM_URL_ENCODED);

  multi.addBodyPart(argPart);
  multi.addBodyPart(dataPart);
  return multi;
}
 
开发者ID:ppdai,项目名称:rest4j,代码行数:31,代码来源:QueryTunnelUtil.java

示例15: updateContentType

import javax.mail.internet.ContentType; //导入依赖的package包/类
private void updateContentType(boolean cleanDefaultRoot) throws MessagingException {
    BodyPart part = null;
    if (rootId == null) {
        part = getBodyPart(0);
    } else {
        part = getBodyPart(rootId);
        if (part == null) {
            if (cleanDefaultRoot)
                rootId = null;
            else
                throw new MessagingException("Can not set root: " + rootId + ": not found");
        }
    }
    if (part != null) {
        String primaryType = baseContentTypeObject.getPrimaryType();
        String subType = baseContentTypeObject.getSubType();
        ParameterList params = baseContentTypeObject.getParameterList();
        ContentType newContentType = new ContentType(primaryType, subType, params);
        ContentType rootContentType = new ContentType(part.getDataHandler().getContentType());
        newContentType.setParameter("type", rootContentType.getBaseType());
        if (rootId != null)
            newContentType.setParameter("start", stripBrackets(rootId));
        contentType = newContentType.toString();
    }
}
 
开发者ID:sviperll,项目名称:chicory,代码行数:26,代码来源:MimeMultipartRelated.java


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