Example usage for org.springframework.util MimeType includes

List of usage examples for org.springframework.util MimeType includes

Introduction

In this page you can find the example usage for org.springframework.util MimeType includes.

Prototype

public boolean includes(@Nullable MimeType other) 

Source Link

Document

Indicate whether this MIME Type includes the given MIME Type.

Usage

From source file:com.codeabovelab.dm.mail.service.MailUtils.java

/**
 * Convert message body to text if possible, otherwise throw exception.
 * @param body//from w w  w.  j  a v a 2 s .  c  om
 * @return
 */
public static String toPlainText(MailBody body) throws MailBadMessageException {
    MimeType mimeType = body.getMimeType();
    boolean containsMime = false;
    for (MimeType type : mimeTypeSet) {
        containsMime = containsMime || type.includes(mimeType);
    }
    if (!containsMime) {
        throw new MailBadMessageException("Message contains body with unsupported contentType: " + mimeType);
    }
    try (Reader r = body.getReader()) {
        return IOUtils.toString(r);
    } catch (IOException e) {
        throw new MailBadMessageException(e);
    }
}

From source file:org.springframework.cloud.stream.converter.AbstractFromMessageConverter.java

public boolean supportsTargetMimeType(MimeType mimeType) {
    for (MimeType targetMimeType : targetMimeTypes) {
        if (targetMimeType.includes(mimeType)) {
            return true;
        }// w  w  w. j  av  a2  s.c  o m
    }
    return false;
}

From source file:org.springframework.cloud.stream.converter.CompositeMessageConverterFactory.java

/**
 * Creation method.//  w  w  w .  java2s  .c o  m
 * @param mimeType the target MIME type
 * @return a converter for the target MIME type
 */
public MessageConverter getMessageConverterForType(MimeType mimeType) {
    List<MessageConverter> converters = new ArrayList<>();
    for (MessageConverter converter : this.converters) {
        if (converter instanceof AbstractMessageConverter) {
            for (MimeType type : ((AbstractMessageConverter) converter).getSupportedMimeTypes()) {
                if (type.includes(mimeType)) {
                    converters.add(converter);
                }
            }
        } else {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Ommitted " + converter + " of type " + converter.getClass().toString()
                        + " for '" + mimeType.toString() + "' as it is not an AbstractMessageConverter");
            }
        }
    }
    if (CollectionUtils.isEmpty(converters)) {
        throw new ConversionException("No message converter is registered for " + mimeType.toString());
    }
    if (converters.size() > 1) {
        return new CompositeMessageConverter(converters);
    } else {
        return converters.get(0);
    }
}

From source file:org.springframework.messaging.support.MessageHeaderAccessor.java

protected boolean isReadableContentType() {
    for (MimeType mimeType : READABLE_MIME_TYPES) {
        if (mimeType.includes(getContentType())) {
            return true;
        }// w ww .j a  v a2  s  .  c  o m
    }
    return false;
}