package com.bonus.system.file.util;

public class IDUtils {
    private static byte[] lock = new byte[0];

    // 位数，默认是8位
    private final static long w = 100000000;

    /**
     * 传入文件 名称
     * @param fileName
     * @return
     */
    public static String getSuffix(String fileName){
        return  fileName.substring(fileName.lastIndexOf('.'));
    }

    public static void main(String[] args) {
        System.err.println(createID());
    }

    /**
     * 获取id
     * @return
     */
    public static String createID() {
        long r = 0;
        synchronized (lock) {
            r = (long) ((Math.random() + 1) * w);
        }

        return System.currentTimeMillis() + String.valueOf(r).substring(1);
    }

    /**
     * 是否是文件/图片
     * @param name
     * @return
     */
    public static String isImageFileExtension(String  name) {
        name=name.toLowerCase();
        String[] imageFormats = {"jpg", "jpeg", "png", "gif", "bmp", "tiff"};
        for (String format : imageFormats) {
            if (format.equals(name)) { // 判断扩展名
                return "1";
            }
        }
        return "2"; // 不是支持的图片格式
    }


}
