Example usage for org.springframework.util MimeType valueOf

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

Introduction

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

Prototype

public static MimeType valueOf(String value) 

Source Link

Document

Parse the given String value into a MimeType object, with this method name following the 'valueOf' naming convention (as supported by org.springframework.core.convert.ConversionService .

Usage

From source file:net.pkhsolutions.pecsapp.entity.PictureDescriptor.java

@NotNull
public MimeType getMimeType() {
    return MimeType.valueOf(mimeType);
}

From source file:net.acesinc.convergentui.BaseFilter.java

protected MimeType getMimeType(RequestContext context) {
    List<Pair<String, String>> headers = context.getZuulResponseHeaders();
    String contentType = null;/*from  w w  w  .  j  a v a2  s  .  c  om*/
    for (Pair<String, String> pair : headers) {
        if ("content-type".equalsIgnoreCase(pair.first())) {
            contentType = pair.second();
            break;
        }
    }

    if (contentType != null) {
        MimeType type = MimeType.valueOf(contentType);
        return type;
    }
    return null;
}

From source file:net.pkhsolutions.pecsapp.ui.components.PictureLayout.java

private boolean isSupportedFile(Html5File file) {
    return model.isSupportedType(MimeType.valueOf(file.getType())); // TODO also check max size
}

From source file:net.pkhsolutions.pecsapp.ui.components.PictureLayout.java

private void uploadFile(Html5File file) {
    final MimeType mimeType = MimeType.valueOf(file.getType());
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final StreamVariable streamVariable = new StreamVariable() {
        @Override//from w  w  w. j  a  v a2s. c  o m
        public OutputStream getOutputStream() {
            return baos;
        }

        @Override
        public boolean listenProgress() {
            return false;
        }

        @Override
        public void onProgress(StreamingProgressEvent event) {
        }

        @Override
        public void streamingStarted(StreamingStartEvent event) {
        }

        @Override
        public void streamingFinished(StreamingEndEvent event) {
            hideProgressBar();
            model.upload(new ByteArrayInputStream(baos.toByteArray()), mimeType);
        }

        @Override
        public void streamingFailed(StreamingErrorEvent event) {
            hideProgressBar();
        }

        @Override
        public boolean isInterrupted() {
            return false;
        }
    };
    showProgressBar();
    file.setStreamVariable(streamVariable);
}

From source file:com.thoughtworks.go.api.ApiController.java

protected boolean isJsonContentType(Request request) {
    String mime = request.headers("Content-Type");
    if (isBlank(mime)) {
        return false;
    }//from w  w w. j  av  a2 s  . c  o m
    try {
        MimeType mimeType = MimeType.valueOf(mime);
        return "application".equals(mimeType.getType()) && "json".equals(mimeType.getSubtype());
    } catch (InvalidMimeTypeException e) {
        return false;
    }
}

From source file:com.thoughtworks.go.http.mocks.MockHttpServletResponseAssert.java

public SELF hasContentType(String mimeType) {
    String contentType = actual.getHeader("content-type");
    try {//from   w  w  w  . j a va2 s  .  c  om
        if (!(isNotBlank(contentType)
                && MimeType.valueOf(contentType).isCompatibleWith(MimeType.valueOf(mimeType)))) {
            failWithMessage("Expected content type <%s> but was <%s>", mimeType, contentType);
        }
    } catch (InvalidMimeTypeException e) {
        failWithMessage("Actual content type <%s> could not be parsed", contentType);
    }
    return myself;
}

From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverter.java

private static Map<String, Object> getMessageAttributesAsMessageHeaders(JsonNode message) {
    Map<String, Object> messageHeaders = new HashMap<>();
    Iterator<String> fieldNames = message.fieldNames();
    while (fieldNames.hasNext()) {
        String attributeName = fieldNames.next();
        String attributeValue = message.get(attributeName).get("Value").asText();
        String attributeType = message.get(attributeName).get("Type").asText();
        if (MessageHeaders.CONTENT_TYPE.equals(attributeName)) {
            messageHeaders.put(MessageHeaders.CONTENT_TYPE, MimeType.valueOf(attributeValue));
        } else if (MessageHeaders.ID.equals(attributeName)) {
            messageHeaders.put(MessageHeaders.ID, UUID.fromString(attributeValue));
        } else {/*www. java  2s.  c o  m*/
            if (MessageAttributeDataTypes.STRING.equals(attributeType)) {
                messageHeaders.put(attributeName, attributeValue);
            } else if (attributeType.startsWith(MessageAttributeDataTypes.NUMBER)) {
                Object numberValue = getNumberValue(attributeType, attributeValue);
                if (numberValue != null) {
                    messageHeaders.put(attributeName, numberValue);
                }
            } else if (MessageAttributeDataTypes.BINARY.equals(attributeName)) {
                messageHeaders.put(attributeName, ByteBuffer.wrap(attributeType.getBytes()));
            }
        }
    }

    return messageHeaders;
}

From source file:org.springframework.cloud.stream.app.log.sink.LogSinkApplicationTests.java

@Test
public void testTextContentType() {
    Message<byte[]> message = MessageBuilder.withPayload("{\"foo\":\"bar\"}".getBytes())
            .setHeader("contentType", MimeType.valueOf("text/plain")).build();
    this.testMessage(message, "{\"foo\":\"bar\"}");
}

From source file:org.springframework.xd.dirt.plugins.stream.ModuleTypeConversionPlugin.java

private MimeType resolveContentType(String type, Module module) throws ClassNotFoundException, LinkageError {
    if (!type.contains("/")) {
        Class<?> javaType = resolveJavaType(type, module);
        return MessageConverterUtils.javaObjectMimeType(javaType);
    }//  w  ww.  j a  v a 2  s  . c o  m
    return MimeType.valueOf(type);
}

From source file:org.springframework.xd.dirt.plugins.stream.ModuleTypeConversionSupport.java

/**
 * Resolve the {@link org.springframework.util.MimeType} to use for the given content type
 * specified for the module input/output.
 *
 * @param type the content type/* ww  w  .  j  a  v a2  s  .c  o m*/
 * @param module the underlying module
 * @return the MimeType
 * @throws ClassNotFoundException
 * @throws LinkageError
 */
public static MimeType resolveContentType(String type, Module module)
        throws ClassNotFoundException, LinkageError {
    if (!type.contains("/")) {
        Class<?> javaType = resolveJavaType(type, module);
        return MessageConverterUtils.javaObjectMimeType(javaType);
    }
    return MimeType.valueOf(type);
}