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

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

Introduction

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

Prototype

MediaType ANY_IMAGE_TYPE

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

Click Source Link

Usage

From source file:de.ks.strudel.fileupload.Fileupload.java

public static void main(final String[] args) {
    Strudel strudel = Strudel.create();/*from  www . jav  a  2  s. c  o m*/
    strudel.classpathLocation("/WEB-INF/fileupload/", "/form");
    strudel.get("/", (request, response) -> response.redirect("/form/form.html"));
    strudel.post("/post", (request, response) -> {
        Path path = request.formDataFile("file");
        if (path == null) {
            return "No file given";
        } else {
            response.contentType(MediaType.ANY_IMAGE_TYPE.type());
            return Files.readAllBytes(path);
        }
    });
    strudel.start();
}

From source file:helper.ThumbnailGenerator.java

private static File generateMimeTypeImage(MediaType contentType, int size, String name) {
    File result = null;//from  ww w.  j  a v  a2  s  .  c o m
    try {
        if (contentType.is(MediaType.ANY_AUDIO_TYPE)) {
            result = generateThumbnailFromImage(Play.application().resourceAsStream(AUDIO_PIC), size, "png",
                    name);
        } else if (contentType.is(MediaType.ANY_IMAGE_TYPE)) {
            result = generateThumbnailFromImage(Play.application().resourceAsStream(IMAGE_PIC), size, "png",
                    name);
        } else if (contentType.is(MediaType.ANY_TEXT_TYPE) || contentType.is(MediaType.OOXML_DOCUMENT)
                || contentType.is(MediaType.MICROSOFT_WORD)) {
            result = generateThumbnailFromImage(Play.application().resourceAsStream(TEXT_PIC), size, "png",
                    name);
        } else if (contentType.is(MediaType.ANY_VIDEO_TYPE)) {
            result = generateThumbnailFromImage(Play.application().resourceAsStream(VIDEO_PIC), size, "png",
                    name);
        } else if (contentType.is(MediaType.ZIP)) {
            result = generateThumbnailFromImage(Play.application().resourceAsStream(ZIP_PIC), size, "png",
                    name);
        } else if (contentType.is(MediaType.PDF)) {
            result = generateThumbnailFromImage(Play.application().resourceAsStream(PDF_PIC), size, "png",
                    name);
        } else {
            result = generateThumbnailFromImage(Play.application().resourceAsStream(MIMETYPE_NOT_FOUND_PIC),
                    size, "png", name);
        }
    } catch (Throwable e) {
        play.Logger.warn("", e);
        result = generateThumbnailFromImage(Play.application().resourceAsStream(EXCEPTION_ON_APPLY_MIMETYPE),
                size, "png", name);
    }
    return result;
}

From source file:de.ks.idnadrev.category.create.CreateCategoryController.java

protected void selectImage(File newFile) throws IOException {
    MediaType mediaType = MediaType.parse(Files.probeContentType(newFile.toPath()));
    if (mediaType.is(MediaType.ANY_IMAGE_TYPE)) {
        loadImage(newFile);/*w w  w  .j a  va 2s  .  c om*/
        fileStoreReference = fileStore.getReference(newFile);
        this.file = newFile;
    }
}

From source file:com.lumata.lib.lupa.internal.ImageServiceImpl.java

/**
 * @param contentType/*from  www  .j  ava  2  s.co m*/
 * @return
 */
private boolean isImageMimeType(ReadableResource readableResource) {
    if (!readableResource.getContentType().isPresent()) {
        return false;
    }
    return readableResource.getContentType().get().is(MediaType.ANY_IMAGE_TYPE);
}

From source file:com.andrewreitz.encryptedcamera.externalstoreage.ExternalStorageManagerImpl.java

protected File getMediaFile(MediaType type, File mediaStorageDir) {
    String timeStamp = dateFormat.format(new Date());
    File mediaFile;/*from  w  ww  .  ja v  a2 s. c  o m*/
    if (type.is(MediaType.ANY_IMAGE_TYPE)) {
        mediaFile = new File(getFileName(type, mediaStorageDir, IMAGE_FILENAME_PREFIX, timeStamp));
    } else if (type.is(MediaType.ANY_VIDEO_TYPE)) {
        mediaFile = new File(getFileName(type, mediaStorageDir, VIDEO_FILENAME_PREFIX, timeStamp));
    } else if (type.is(MediaType.ANY_TYPE)) {
        mediaFile = new File(mediaStorageDir.getPath());
    } else {
        throw new IllegalArgumentException(String.format("Unknown File Type %s", type));
    }
    return mediaFile;
}

From source file:nl.tricode.magnolia.blogs.dialog.action.BlogPostImageImporter.java

private boolean isImageMediaType(String mediaType) {
    return MediaType.parse(mediaType).is(MediaType.ANY_IMAGE_TYPE);
}

From source file:spdxedit.SpdxLogic.java

public static FileType[] getTypesForFile(Path path) {
    String extension = StringUtils
            .lowerCase(StringUtils.substringAfterLast(path.getFileName().toString(), "."));
    ArrayList<FileType> fileTypes = new ArrayList<>();
    if (sourceFileExtensions.contains(extension)) {
        fileTypes.add(SpdxFile.FileType.fileType_source);
    }/*from  w  ww.  ja  v a2  s. c  o  m*/
    if (binaryFileExtensions.contains(extension)) {
        fileTypes.add(FileType.fileType_binary);
    }
    if (textFileExtensions.contains(extension)) {
        fileTypes.add(FileType.fileType_text);
    }
    if (archiveFileExtensions.contains(extension)) {
        fileTypes.add(FileType.fileType_archive);
    }
    if ("spdx".equals(extension)) {
        fileTypes.add(FileType.fileType_spdx);
    }
    try {
        String mimeType = Files.probeContentType(path);
        if (StringUtils.startsWith(mimeType, MediaType.ANY_AUDIO_TYPE.type())) {
            fileTypes.add(FileType.fileType_audio);
        }
        if (StringUtils.startsWith(mimeType, MediaType.ANY_IMAGE_TYPE.type())) {
            fileTypes.add(FileType.fileType_image);
        }
        if (StringUtils.startsWith(mimeType, MediaType.ANY_APPLICATION_TYPE.type())) {
            fileTypes.add(FileType.fileType_application);
        }

    } catch (IOException ioe) {
        logger.warn("Unable to access file " + path.toString() + " to determine its type.", ioe);
    }
    return fileTypes.toArray(new FileType[] {});
}

From source file:org.ctoolkit.services.upload.appengine.DataUploadHandlerServlet.java

private boolean isAnyImageContentType(FileInfo info) {
    String contentType = info.getContentType();
    return contentType != null && contentType.toLowerCase().startsWith(MediaType.ANY_IMAGE_TYPE.type());
}

From source file:org.waveprotocol.box.server.rpc.AttachmentServlet.java

/**
 * Check if mime type is suitable to be deliver as an inline content
 * or as a file./*from  w  ww  .j a v  a 2s.c  o  m*/
 * @param mimeType
 * @return
 */
private static boolean isWebContent(String mimeType) {
    boolean isWebContent = false;
    try {
        MediaType mt = MediaType.parse(mimeType);
        isWebContent = mt.is(MediaType.ANY_IMAGE_TYPE) || mt.is(MediaType.ANY_VIDEO_TYPE);
    } catch (IllegalArgumentException e) {
        LOG.warning("Unable to decode mime type " + mimeType != null ? mimeType : "null");
    }

    return isWebContent;
}

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

/**
 * Validate HTTP URI./*from w w w  . j a  v a  2s. c  o  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;
    }
}