13693261870
昨天 32eb942e25aa366563b7f40b05a382c0c462213c
se-common/src/main/java/com/terra/common/helper/FileHelper.java
ÎļþÃû´Ó se-system/src/main/java/com/terra/system/helper/FileHelper.java ÐÞ¸Ä
@@ -1,9 +1,8 @@
package com.terra.system.helper;
package com.terra.common.helper;
import com.terra.common.entity.all.StaticData;
import com.terra.system.entity.data.MetaFileEntity;
//import com.twmacinta.util.MD5;
import org.apache.commons.codec.digest.DigestUtils;
//import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -11,6 +10,7 @@
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.util.List;
@@ -236,43 +236,27 @@
    /**
     * 3.获取文件MD5码(JDK)
     */
    public static String getMd5ByJdk(String filePath) throws IOException {
    /*public static String getMd5ByJdk(String filePath) throws IOException {
        FileInputStream fileStream = new FileInputStream(filePath);
        String md5 = DigestUtils.md5Hex(fileStream);
        fileStream.close();
        return md5;
    }
    }*/
    /**
     * 2.获取快速 MD5 ç 
     */
    public static String getFastMd5(String filePath) throws IOException {
        /*String hash = MD5.asHex(MD5.getHash(new File(filePath)));
    /*public static String getFastMd5(String filePath) throws IOException {
        String hash = MD5.asHex(MD5.getHash(new File(filePath)));
        MD5 md5 = new MD5();
        md5.Update(hash, null);
        return md5.asHex();*/
        return md5.asHex();
        return null;
    }
    /**
     * åˆ é™¤æ–‡ä»¶
     */
    public static void deleteFiles(List<MetaFileEntity> list) {
        try {
            for (MetaFileEntity mf : list) {
                File f = new File(mf.getPath());
                if (f.exists()) {
                    f.delete();
                }
            }
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
    }*/
    /**
     * åˆ é™¤æ–‡ä»¶å¤¹
@@ -366,7 +350,7 @@
            return byteToHexString(b);
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error(ex.getMessage(), ex);
            return null;
        } finally {
            try {
@@ -374,7 +358,7 @@
                    fis.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
                log.error(ex.getMessage(), ex);
            }
        }
    }
@@ -453,8 +437,8 @@
        InputStream is = null;
        OutputStream os = null;
        try {
            is = new FileInputStream(src);
            os = new FileOutputStream(dest);
            is = Files.newInputStream(src.toPath());
            os = Files.newOutputStream(dest.toPath());
            byte[] buffer = new byte[1024];
@@ -463,8 +447,8 @@
                os.write(buffer, 0, length);
            }
        } finally {
            os.close();
            is.close();
            if (os != null) os.close();
            if (is != null) is.close();
        }
    }
}