package com.mooctest.util;

import com.mooctest.image.FingerPrint;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ImageUtil {

    public static final String IMAGE_PATH = "/Users/major/Desktop/data/";

    public static File checkFileExist(String filePath) {
        File f1 = new File(filePath);
        return f1.exists() ? f1 : null;
    }

    public static FingerPrint readImgFingerPrint(File img) {
        FileInputStream fis1;
        FingerPrint fp = null;
        try {
            byte[] b1 = new byte[(int) img.length()];
            fis1 = new FileInputStream(img);
            fis1.read(b1);
            fp = new FingerPrint(b1);
            fis1.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return fp;
    }

    public static String genImagePath(String taskId, String bugId, int idx) {
        return IMAGE_PATH + taskId + "/" + bugId + "_" + idx;
    }
}
