Search in sources :

Example 1 with GIFImageReader

use of com.sun.imageio.plugins.gif.GIFImageReader in project twitter-2-weibo by rjyo.

the class ImageItem method getContentType.

public static String getContentType(byte[] mapObj) throws IOException {
    String type = "";
    ByteArrayInputStream bais = null;
    MemoryCacheImageInputStream mcis = null;
    try {
        bais = new ByteArrayInputStream(mapObj);
        mcis = new MemoryCacheImageInputStream(bais);
        Iterator itr = ImageIO.getImageReaders(mcis);
        while (itr.hasNext()) {
            ImageReader reader = (ImageReader) itr.next();
            if (reader instanceof GIFImageReader) {
                type = "image/gif";
            } else if (reader instanceof JPEGImageReader) {
                type = "image/jpeg";
            } else if (reader instanceof PNGImageReader) {
                type = "image/png";
            } else if (reader instanceof BMPImageReader) {
                type = "application/x-bmp";
            }
        }
    } finally {
        if (bais != null) {
            try {
                bais.close();
            } catch (IOException ioe) {
            }
        }
        if (mcis != null) {
            try {
                mcis.close();
            } catch (IOException ioe) {
            }
        }
    }
    return type;
}
Also used : JPEGImageReader(com.sun.imageio.plugins.jpeg.JPEGImageReader) BMPImageReader(com.sun.imageio.plugins.bmp.BMPImageReader) ByteArrayInputStream(java.io.ByteArrayInputStream) PNGImageReader(com.sun.imageio.plugins.png.PNGImageReader) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) Iterator(java.util.Iterator) IOException(java.io.IOException) GIFImageReader(com.sun.imageio.plugins.gif.GIFImageReader) ImageReader(javax.imageio.ImageReader) JPEGImageReader(com.sun.imageio.plugins.jpeg.JPEGImageReader) BMPImageReader(com.sun.imageio.plugins.bmp.BMPImageReader) PNGImageReader(com.sun.imageio.plugins.png.PNGImageReader) GIFImageReader(com.sun.imageio.plugins.gif.GIFImageReader)

Example 2 with GIFImageReader

use of com.sun.imageio.plugins.gif.GIFImageReader in project jdk8u_jdk by JetBrains.

the class AllowSearch method main.

public static void main(String[] args) throws IOException {
    ImageReader gifReader = new GIFImageReader(null);
    ImageReader jpegReader = new JPEGImageReader(null);
    ImageReader pngReader = new PNGImageReader(null);
    test(gifReader, "GIF");
    test(jpegReader, "JPEG");
    test(pngReader, "PNG");
}
Also used : JPEGImageReader(com.sun.imageio.plugins.jpeg.JPEGImageReader) PNGImageReader(com.sun.imageio.plugins.png.PNGImageReader) GIFImageReader(com.sun.imageio.plugins.gif.GIFImageReader) ImageReader(javax.imageio.ImageReader) JPEGImageReader(com.sun.imageio.plugins.jpeg.JPEGImageReader) PNGImageReader(com.sun.imageio.plugins.png.PNGImageReader) GIFImageReader(com.sun.imageio.plugins.gif.GIFImageReader)

Aggregations

GIFImageReader (com.sun.imageio.plugins.gif.GIFImageReader)2 JPEGImageReader (com.sun.imageio.plugins.jpeg.JPEGImageReader)2 PNGImageReader (com.sun.imageio.plugins.png.PNGImageReader)2 ImageReader (javax.imageio.ImageReader)2 BMPImageReader (com.sun.imageio.plugins.bmp.BMPImageReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)1