code: public static ImageFormat getImageFormat(String filename) {
      FileInputStream fileInputStream = null;
      try {
        fileInputStream = new FileInputStream(filename);
        return getImageFormat(fileInputStream);
      } catch (IOException ioe) {
        return ImageFormat.UNKNOWN;
      } finally {
        Closeables.closeQuietly(fileInputStream);
      }
    }
docs: Reads image header from a file indicated by provided filename and determines
  its format. This method does not throw IOException if one occurs. In this case,
  {@link ImageFormat#UNKNOWN} will be returned.
  @param filename
  @return ImageFormat for image stored in filename