| | |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.context.support.ClassPathXmlApplicationContext; |
| | | |
| | | import java.io.*; |
| | | import java.net.URL; |
| | | import java.net.URLDecoder; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.channels.FileChannel; |
| | | import java.nio.charset.StandardCharsets; |
| | |
| | | // 所以表示成 16 进制需要 32 个字符,表示转换结果中对应的字符位置 |
| | | int k = 0; |
| | | // 从第一个字节开始,对 MD5 的每一个字节 |
| | | for (int i = 0; i < StaticData.SIXTEEN; i++) { |
| | | for (int i = 0; i < StaticData.I16; i++) { |
| | | // 转换成 16 进制字符的转换 |
| | | byte byte0 = tmp[i]; |
| | | // 取字节中高 4 位的数字转换 |
| | |
| | | /** |
| | | * 根据路径获取文件 |
| | | */ |
| | | public static void getFilesByPath(List<File> list, String path) { |
| | | public static void getFilesByPath(List<String> list, String path) { |
| | | File file = new File(path); |
| | | if (file.isDirectory()) { |
| | | File[] files = file.listFiles(); |
| | |
| | | if (f.isDirectory()) { |
| | | getFilesByPath(list, f.getPath()); |
| | | } else { |
| | | list.add(f); |
| | | list.add(f.getPath()); |
| | | } |
| | | } |
| | | } else { |
| | | list.add(file); |
| | | list.add(file.getPath()); |
| | | } |
| | | } |
| | | |
| | |
| | | is.close(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 过滤输入字符串, 剔除多行注释以及替换掉反斜杠 |
| | | */ |
| | | public static String filter(String str) { |
| | | return str.replaceAll("/\\*[\\s\\S]*?\\*/", ""); |
| | | } |
| | | |
| | | /** |
| | | * 解码 |
| | | */ |
| | | public static String decode(String str) { |
| | | try { |
| | | return URLDecoder.decode(str, "UTF-8"); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取ClassPath-jar |
| | | */ |
| | | public static String getClassPathForJar() { |
| | | URL resource = ClassLoader.getSystemResource(""); |
| | | if (null == resource) { |
| | | return null; |
| | | } |
| | | |
| | | return decode(filter(resource.getPath())); |
| | | } |
| | | |
| | | /** |
| | | * 获取ClassPath-war |
| | | */ |
| | | public static String getClassPathForWar() throws IOException { |
| | | ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); |
| | | |
| | | return context.getResource("").getFile().getAbsolutePath(); |
| | | } |
| | | } |