Guava MediaType - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava MediaType class.

This code example shows how to use the following methods:toString
      MediaType mediaType,
      Request baseRequest, 
      HttpServletResponse response,
      int status)
      throws IOException {
    response.setContentType(mediaType.toString());
    response.setStatus(status);
 
    response.getWriter().write(content);
 
    response.flushBuffer();
    baseRequest.setHandled(true); 
  } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
            partSize);
 
      try { 
         assertEquals(api.execute("container", new BlobBuilderImpl().name("foo").payload(bytes)
            .contentDisposition("inline; filename=foo.mp4") 
            .contentType(MediaType.MP4_VIDEO.toString())
            .build()), "fff"); 
      } finally { 
 
         RecordedRequest initiate = server.takeRequest();
         assertEquals(initiate.getRequestLine(), "POST /container/foo?uploads HTTP/1.1");
         assertEquals(initiate.getHeader("Content-Length"), "0");
         assertEquals(initiate.getHeader(HttpHeaders.CONTENT_TYPE), MediaType.MP4_VIDEO.toString());
         assertEquals(initiate.getHeader(HttpHeaders.CONTENT_DISPOSITION), "inline; filename=foo.mp4");
 
         RecordedRequest part1 = server.takeRequest();
         assertEquals(part1.getRequestLine(), "PUT /container/foo?partNumber=1&uploadId=upload-id HTTP/1.1");
         assertEquals(part1.getHeader("Content-Length"), String.valueOf(partSize));
         assertEquals(new String(part1.getBody()), "01234567");
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
    } 
 
 
    public static ListMultimap<String, String> contentType(MediaType type)
    { 
        return ImmutableListMultimap.of(HttpHeaders.CONTENT_TYPE, type.toString());
    } 
 
    public static Response mockResponse(HttpStatus status)
    { 
        return new TestingResponse(status, ImmutableListMultimap.<String, String>of(), new byte[0]);
    } 
 
    public static Response mockResponse(HttpStatus status, MediaType type, String content)
    { 
        return new TestingResponse(status, contentType(type), content.getBytes(Charsets.UTF_8));
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
    } 
 
 
    public static ListMultimap<String, String> contentType(MediaType type)
    { 
        return ImmutableListMultimap.of(HttpHeaders.CONTENT_TYPE, type.toString());
    } 
 
    public static Response mockResponse(HttpStatus status, MediaType type, String content)
    { 
        return new TestingResponse(status, contentType(type), content.getBytes(Charsets.UTF_8));
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:subtype, type
 
    public DateTime get(MediaType mimeType, Path path) {
        if (!production) {
            return null; 
        } 
        Long expires = settings.getLong("expires." + mimeType.type() + '/' + mimeType.subtype());
        if (expires != null) {
            return DateTime.now().plus(Duration.millis(expires));
        } 
        if ("image".equals(mimeType.type())) {
            return DateTime.now().plus(Duration.standardDays(30)); 
        } 
        return null; 
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
        super(MediaType.class, HttpHeaders.Names.CONTENT_TYPE);
    } 
 
    @Override 
    public String toString(MediaType value) {
        return value.toString();
    } 
 
    @Override 
    public MediaType toValue(String value) {
        try { 
            return MediaType.parse(value);
        } catch (IllegalArgumentException e) {
            Logger.getLogger(MediaTypeHeader.class.getName()).log(Level.WARNING, "Bad media type {0}", value);
            return null; 
        } 
    } 
 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
  protected void configure() { 
    Registration.registerHttpAsset( 
        binder(), 
        "/js/jquery.min.js", 
        Resources.getResource(JQueryModule.class, "js/jquery-1.8.2.min.js"),
        MediaType.JAVASCRIPT_UTF_8.toString(),
        true); 
  } 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:withoutParameters
    } 
 
    @Override 
    public MediaType put( final String ext, final MediaType value )
    { 
        return super.put( ext, value.withoutParameters() );
    } 
 
    public static MediaTypes instance() 
    { 
        return INSTANCE;
    } 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:is
    @Override 
    public JsonResponse<T> handle(Request request, Response response) 
    { 
        byte[] bytes = readResponseBytes(response);
        String contentType = response.getHeader(CONTENT_TYPE);
        if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) {
            return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes);
        } 
        return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes);
    } 
 
    private static byte[] readResponseBytes(Response response) 
    { 
        try { 
            return ByteStreams.toByteArray(response.getInputStream());
        } 
        catch (IOException e) {
            throw new RuntimeException("Error reading response from server", e);
        } 
    } 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:withCharset
 
    public final void add(String ext, MediaType tp, boolean charset) {
        ext = ext.toLowerCase();
         
        if (charset) {
            tp=tp.withCharset(this.charset);
        } 
        m.put(ext.toLowerCase(), tp);
    } 
 
    public MediaType get(String fileName) {
        String ext;
        int off;
        if ((off = fileName.lastIndexOf('.')) >= 0) {
            ext = fileName.substring(off + 1);
        } else { 
            ext = fileName;
        } 
        MediaType result = m.get(ext.toLowerCase());
//        System.out.println("Mime type for " + fileName + " is " + result); 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Guava MediaType Methods: