| | |
| | | package com.lf.server.helper; |
| | | |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.twmacinta.util.MD5; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.apache.commons.logging.Log; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取文件 MD5 码 |
| | | * 获取文件MD5码(JDK) |
| | | */ |
| | | public static String getFileMd5(String filePath) throws IOException { |
| | | public static String getMd5ByJdk(String filePath) throws IOException { |
| | | FileInputStream fileStream = new FileInputStream(filePath); |
| | | String md5 = DigestUtils.md5Hex(fileStream); |
| | | fileStream.close(); |
| | |
| | | /** |
| | | * 删除文件 |
| | | */ |
| | | public static void deleteFiles(List<MetaFileEntity> list) { |
| | | public static void deleteFiles(List<MetaEntity> list) { |
| | | try { |
| | | for (MetaFileEntity mf : list) { |
| | | for (MetaEntity mf : list) { |
| | | File f = new File(mf.getPath()); |
| | | if (f.exists()) { |
| | | f.delete(); |
| | |
| | | |
| | | /** |
| | | * 获取文件的MD5 |
| | | * @param file |
| | | * @param filePath |
| | | * @return |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | public static String getFileMd5(File file) { |
| | | public static String getFileMd5(String filePath) { |
| | | FileInputStream fis = null; |
| | | try { |
| | | MessageDigest md = MessageDigest.getInstance("MD5"); |
| | | |
| | | fis = new FileInputStream(file); |
| | | fis = new FileInputStream(new File(filePath)); |
| | | FileChannel fChannel = fis.getChannel(); |
| | | ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 1024); |
| | | |