Here you can find the source of isImage(InputStream is)
public static final boolean isImage(InputStream is)
//package com.java2s; //License from project: Open Source License import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; public class Main { public static final boolean isImage(InputStream is) { boolean ret = false; try {/*from w w w . j a v a2 s . co m*/ BufferedImage bufreader = ImageIO.read(is); int width = bufreader.getWidth(); int height = bufreader.getHeight(); if (width == 0 || height == 0) { ret = false; } else { ret = true; } } catch (IOException e) { ret = false; } catch (Exception e) { ret = false; } return ret; } }