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

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

Introduction

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

Prototype

public static MediaType parse(String input) 

Source Link

Document

Parses a media type from its string representation.

Usage

From source file:org.inakirj.imagerulette.utils.ImageUtils.java

/**
 * Validate HTTP URI.//from   w  ww  .  j a  v a 2s .co m
 *
 * @param uri
 *            the URI
 * @return true, if given URI is an static image
 */
public static boolean isValidImageURI(String uri) {
    HttpURLConnection con;
    try {
        URL obj = new URL(uri);
        con = (HttpURLConnection) obj.openConnection();
        String contentType = con.getContentType();
        MediaType mt = MediaType.parse(contentType);
        return mt.is(MediaType.ANY_IMAGE_TYPE);
    } catch (Exception e) {
        return false;
    }
}