Example usage for org.springframework.util MimeType equals

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

Introduction

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

Prototype

@Override
    public boolean equals(@Nullable Object other) 

Source Link

Usage

From source file:net.pkhsolutions.pecsapp.boundary.PictureServiceBean.java

@Override
public boolean isSupportedMimeType(@NotNull MimeType mimeType) {
    return mimeType.equals(MimeTypeUtils.IMAGE_JPEG) || mimeType.equals(MimeTypeUtils.IMAGE_PNG)
            || mimeType.equals(MimeTypeUtils.IMAGE_GIF);
}

From source file:org.springframework.integration.x.bus.MessageBusSupport.java

private Object deserializePayload(byte[] bytes, MimeType contentType) {
    Class<?> targetType = null;
    try {//from   w  w w  .j  a  v  a2 s  . co  m
        if (contentType.equals(TEXT_PLAIN)) {
            return new String(bytes, "UTF-8");
        }
        targetType = Class.forName(contentType.getParameter("type"));

        return codec.deserialize(bytes, targetType);
    } catch (ClassNotFoundException e) {
        throw new SerializationException("unable to deserialize [" + targetType + "]. Class not found.", e);
    } catch (IOException e) {
        throw new SerializationException("unable to deserialize [" + targetType + "]", e);
    }

}

From source file:org.springframework.xd.dirt.integration.bus.MessageBusSupport.java

protected final Message<?> serializePayloadIfNecessary(Message<?> message, MimeType to) {
    Object originalPayload = message.getPayload();
    Object originalContentType = message.getHeaders().get(MessageHeaders.CONTENT_TYPE);
    Object contentType = originalContentType;
    if (to.equals(ALL)) {
        return message;
    } else if (to.equals(APPLICATION_OCTET_STREAM)) {
        //Pass content type as String since some transport adapters will exclude CONTENT_TYPE Header otherwise
        contentType = JavaClassMimeTypeConversion.mimeTypeFromObject(originalPayload).toString();
        Object payload = serializePayloadIfNecessary(originalPayload);
        MessageBuilder<Object> messageBuilder = MessageBuilder.withPayload(payload)
                .copyHeaders(message.getHeaders()).setHeader(MessageHeaders.CONTENT_TYPE, contentType);
        if (originalContentType != null) {
            messageBuilder.setHeader(XdHeaders.XD_ORIGINAL_CONTENT_TYPE, originalContentType);
        }/*  w ww  . j a v  a 2 s  . c o m*/
        return messageBuilder.build();
    } else {
        throw new IllegalArgumentException("'to' can only be 'ALL' or 'APPLICATION_OCTET_STREAM'");
    }
}

From source file:org.springframework.xd.dirt.integration.bus.MessageBusSupport.java

private Object deserializePayload(byte[] bytes, MimeType contentType) {
    Class<?> targetType = null;
    try {//from www  .j  a v a 2s .  c o m
        if (contentType.equals(TEXT_PLAIN)) {
            return new String(bytes, "UTF-8");
        }
        String className = JavaClassMimeTypeConversion.classNameFromMimeType(contentType);
        targetType = Class.forName(className);

        return codec.deserialize(bytes, targetType);
    } catch (ClassNotFoundException e) {
        throw new SerializationException("unable to deserialize [" + targetType + "]. Class not found.", e);
    } catch (IOException e) {
        throw new SerializationException("unable to deserialize [" + targetType + "]", e);
    }

}