Java ImageIO Supported Writer isImage(String fileName)

Here you can find the source of isImage(String fileName)

Description

is Image

License

Open Source License

Declaration

public static boolean isImage(String fileName) 

Method Source Code

//package com.java2s;
/*//  w  ww  .java2s .c om
 * Aipo is a groupware program developed by Aimluck,Inc.
 * Copyright (C) 2004-2011 Aimluck,Inc.
 * http://www.aipo.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import javax.imageio.ImageIO;

public class Main {

    public static boolean isImage(String fileName) {
        if (fileName == null || "".equals(fileName)) {
            return false;
        }

        int index = fileName.lastIndexOf(".");
        if (index < 1) {
            return false;
        }

        String fileType = getFileTypeName(fileName);

        String[] format = ImageIO.getWriterFormatNames();
        int len = format.length;
        for (int i = 0; i < len; i++) {
            if (format[i].equals(fileType)) {
                return true;
            }
        }
        return false;
    }

    public static String getFileTypeName(String fileName) {
        if (fileName == null || "".equals(fileName)) {
            return null;
        }

        int index = fileName.lastIndexOf(".");
        if (index < 1) {
            return null;
        }

        return fileName.substring(index + 1, fileName.length());
    }
}

Related

  1. getImageFormats()
  2. isImg(String format)
  3. printImageFormatNames()
  4. supportedSendTypes()