Search in sources :

Example 6 with MediaType

use of com.google.common.net.MediaType in project guava by hceylan.

the class MediaTypeTest method testGetCharset_illegalCharset.

public void testGetCharset_illegalCharset() {
    MediaType mediaType = MediaType.parse("text/plain; charset=\"!@#$%^&*()\"");
    try {
        mediaType.charset();
        fail();
    } catch (IllegalCharsetNameException expected) {
    }
}
Also used : IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) MediaType(com.google.common.net.MediaType)

Example 7 with MediaType

use of com.google.common.net.MediaType in project ddf by codice.

the class VideoThumbnailPlugin method isVideo.

private boolean isVideo(final ContentItem contentItem) {
    final MimeType createdMimeType = contentItem.getMimeType();
    final MediaType createdMediaType = MediaType.create(createdMimeType.getPrimaryType(), createdMimeType.getSubType());
    return createdMediaType.is(MediaType.ANY_VIDEO_TYPE);
}
Also used : MediaType(com.google.common.net.MediaType) MimeType(javax.activation.MimeType)

Example 8 with MediaType

use of com.google.common.net.MediaType in project moco by dreamhead.

the class FileContentType method getContentType.

public MediaType getContentType() {
    Optional<MediaType> optionalType = toContentType(Files.getFileExtension(filename));
    Optional<Charset> targetCharset = toCharset(optionalType);
    MediaType type = optionalType.or(DEFAULT_CONTENT_TYPE_WITH_CHARSET);
    if (targetCharset.isPresent() && !type.charset().equals(targetCharset)) {
        return type.withCharset(targetCharset.get());
    }
    return type;
}
Also used : MediaType(com.google.common.net.MediaType) Charset(java.nio.charset.Charset)

Example 9 with MediaType

use of com.google.common.net.MediaType in project moco by dreamhead.

the class MocoRestTest method checkJsonResponse.

private HttpEntity checkJsonResponse(final HttpResponse response) {
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    HttpEntity entity = response.getEntity();
    MediaType mediaType = MediaType.parse(entity.getContentType().getValue());
    assertThat(mediaType.type(), is("application"));
    assertThat(mediaType.subtype(), is("json"));
    return entity;
}
Also used : HttpEntity(org.apache.http.HttpEntity) MediaType(com.google.common.net.MediaType)

Example 10 with MediaType

use of com.google.common.net.MediaType in project moco by dreamhead.

the class MocoRestStandaloneTest method asPlain.

private Plain asPlain(org.apache.http.HttpResponse response) throws IOException {
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    HttpEntity entity = response.getEntity();
    MediaType mediaType = MediaType.parse(entity.getContentType().getValue());
    assertThat(mediaType.type(), is("application"));
    assertThat(mediaType.subtype(), is("json"));
    return Jsons.toObject(entity.getContent(), Plain.class);
}
Also used : HttpEntity(org.apache.http.HttpEntity) MediaType(com.google.common.net.MediaType)

Aggregations

MediaType (com.google.common.net.MediaType)18 HttpEntity (org.apache.http.HttpEntity)3 ServletOutputStream (javax.servlet.ServletOutputStream)2 ByteSource (com.google.common.io.ByteSource)1 OutputStream (java.io.OutputStream)1 URISyntaxException (java.net.URISyntaxException)1 Charset (java.nio.charset.Charset)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 MimeType (javax.activation.MimeType)1 HttpResponse (org.apache.http.HttpResponse)1 Test (org.junit.Test)1