public static boolean isImage( final InputStream stream )
    {
        try
        {
            // This attempts to read the bytes as an image, returning null if it cannot parse the bytes as an image.
            return null != ImageIO.read( stream );
        }
        catch ( IOException e )
        {
            Log.debug( "An exception occurred while determining if data represents an image.", e );
            return false;
        }
    }
Checks if the provided input stream represents an image.

@param stream The data to be parsed. Cannot be null.
@return true if the provided data is successfully identified as an image, otherwise false.
xmppserver/src/main/java/org/jivesoftware/util/GraphicsUtils.java