Example usage for com.google.common.net MediaType GIF

List of usage examples for com.google.common.net MediaType GIF

Introduction

In this page you can find the example usage for com.google.common.net MediaType GIF.

Prototype

MediaType GIF

To view the source code for com.google.common.net MediaType GIF.

Click Source Link

Usage

From source file:helper.ThumbnailGenerator.java

/**
 * @param ts//from   w w  w. j ava  2 s  . co  m
 *            the actual content to create a thumbnail from
 * @param contentType
 *            the MediaType for the content
 * @param size
 *            acually the width
 * @param name 
 * @return a thumbnail file
 */
public static File createThumbnail(InputStream ts, MediaType contentType, int size, String name) {
    File result = null;
    try {

        if (contentType.is(MediaType.JPEG)) {
            result = generateThumbnailFromImage(ts, size, "jpeg", name);
        } else if (contentType.is(MediaType.PNG)) {
            result = generateThumbnailFromImage(ts, size, "png", name);
        } else if (contentType.is(MediaType.GIF)) {
            result = generateThumbnailFromImage(ts, size, "gif", name);
        } else if (contentType.is(MediaType.PDF)) {
            result = generateThumbnailFromPdf(ts, size, name);
        } else {
            result = generateMimeTypeImage(contentType, size, name);
        }
    } catch (Throwable e) {
        play.Logger.warn("", e);
        result = generateThumbnailFromImage(Play.application().resourceAsStream(THUMBNAIL_EXCEPTION_PIC), size,
                "png", name);
    }
    return result;
}

From source file:com.mastfrog.acteur.ClasspathResourcePage.java

protected MediaType getContentType(Path path) {
    MediaType type = responseHeaders.getContentType();
    if (type != null) {
        return type;
    }//from  ww w .  j  a  v a2  s .  c o  m
    String pth = path.toString();
    if (pth.endsWith("svg")) {
        return MediaType.SVG_UTF_8;
    } else if (pth.endsWith("css")) {
        return MediaType.CSS_UTF_8;
    } else if (pth.endsWith("html")) {
        return MediaType.HTML_UTF_8;
    } else if (pth.endsWith("json")) {
        return MediaType.JSON_UTF_8;
    } else if (pth.endsWith("js")) {
        return MediaType.JAVASCRIPT_UTF_8;
    } else if (pth.endsWith("gif")) {
        return MediaType.GIF;
    } else if (pth.endsWith("jpg")) {
        return MediaType.JPEG;
    } else if (pth.endsWith("png")) {
        return MediaType.PNG;
    }
    return null;
}