|
@@ -1,5 +1,9 @@
|
|
|
package com.hssx.cloudmodel.util;
|
|
|
|
|
|
+import net.lingala.zip4j.core.ZipFile;
|
|
|
+import net.lingala.zip4j.exception.ZipException;
|
|
|
+import net.lingala.zip4j.model.ZipParameters;
|
|
|
+import net.lingala.zip4j.util.Zip4jConstants;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.util.DigestUtils;
|
|
|
|
|
@@ -23,82 +27,115 @@ import java.util.zip.ZipOutputStream;
|
|
|
*/
|
|
|
public class MD5Util {
|
|
|
|
|
|
- public static String getPassword(String password){
|
|
|
+ public static String getPassword(String password) {
|
|
|
return DigestUtils.md5DigestAsHex(password.getBytes());
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) throws ParseException {
|
|
|
+ zip4jDemo();
|
|
|
|
|
|
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
//// LocalDateTime parse = LocalDateTime.parse("2019-07-31T16:00:00.000Z", formatter);
|
|
|
// System.out.println(parse);
|
|
|
|
|
|
- String start = "2019-07-31T16:00:00.000Z".replace("Z", " UTC");//是空格+UTC
|
|
|
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
|
|
|
- Date date1 = df.parse(start);
|
|
|
- SimpleDateFormat df1 = new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
|
|
|
- Date startDate = df1.parse(date1.toString());
|
|
|
- System.out.println("date1.toString()"+date1.toString()+"=====startDate"+startDate);
|
|
|
- String substring = "D:/mould/upload/".substring(0, "D:/mould/upload/".length() - "/upload/".length());
|
|
|
- System.out.println("substring"+substring);
|
|
|
- List<Integer>ids = new ArrayList<>();
|
|
|
- ids.add(-1);
|
|
|
- List<String> list1 = new ArrayList<String>();
|
|
|
- List<String> list2 = new ArrayList<String>();
|
|
|
- list1.add("g");
|
|
|
- list1.add("s");
|
|
|
- list1.add("a");
|
|
|
- list1.add("f");
|
|
|
- list2.add("g");
|
|
|
- list2.add("c");
|
|
|
- list2.add("b");
|
|
|
- list2.add("a");
|
|
|
- list1.retainAll(list2);
|
|
|
- System.out.print(list1);
|
|
|
+// String start = "2019-07-31T16:00:00.000Z".replace("Z", " UTC");//是空格+UTC
|
|
|
+// DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
|
|
|
+// Date date1 = df.parse(start);
|
|
|
+// SimpleDateFormat df1 = new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
|
|
|
+// Date startDate = df1.parse(date1.toString());
|
|
|
+// System.out.println("date1.toString()"+date1.toString()+"=====startDate"+startDate);
|
|
|
+// String substring = "D:/mould/upload/".substring(0, "D:/mould/upload/".length() - "/upload/".length());
|
|
|
+// System.out.println("substring"+substring);
|
|
|
+// List<Integer>ids = new ArrayList<>();
|
|
|
+// ids.add(-1);
|
|
|
+// List<String> list1 = new ArrayList<String>();
|
|
|
+// List<String> list2 = new ArrayList<String>();
|
|
|
+// list1.add("g");
|
|
|
+// list1.add("s");
|
|
|
+// list1.add("a");
|
|
|
+// list1.add("f");
|
|
|
+// list2.add("g");
|
|
|
+// list2.add("c");
|
|
|
+// list2.add("b");
|
|
|
+// list2.add("a");
|
|
|
+// list1.retainAll(list2);
|
|
|
+// System.out.print(list1);
|
|
|
// String password = "000000";
|
|
|
// System.out.println(MD5Util.getPassword(password));
|
|
|
// System.out.println(UUID.randomUUID().toString().replaceAll("-", ""));;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void zipDemo() {
|
|
|
//需要压缩的文件--包括文件地址和文件名
|
|
|
-// String [] path ={"D:\\666\\1.jpg","D:\\666\\MouldFileMapper.xml"};
|
|
|
-// // 要生成的压缩文件地址和文件名称
|
|
|
-// String desPath = "D:\\666\\new.zip";
|
|
|
-// File zipFile = new File(desPath);
|
|
|
-// ZipOutputStream zipStream = null;
|
|
|
-// FileInputStream zipSource = null;
|
|
|
-// BufferedInputStream bufferStream = null;
|
|
|
-// try {
|
|
|
-// //构造最终压缩包的输出流
|
|
|
-// zipStream = new ZipOutputStream(new FileOutputStream(zipFile));
|
|
|
-// for(int i =1;i<path.length;i++){
|
|
|
-// File file = new File(path[i]);
|
|
|
-// //将需要压缩的文件格式化为输入流
|
|
|
-// zipSource = new FileInputStream(file);
|
|
|
-// //压缩条目不是具体独立的文件,而是压缩包文件列表中的列表项,称为条目,就像索引一样
|
|
|
-// ZipEntry zipEntry = new ZipEntry("2222.jpg");
|
|
|
-// //定位该压缩条目位置,开始写入文件到压缩包中
|
|
|
-// zipStream.putNextEntry(zipEntry);
|
|
|
-// //输入缓冲流
|
|
|
-// bufferStream = new BufferedInputStream(zipSource, 1024 * 10);
|
|
|
-// int read = 0;
|
|
|
-// //创建读写缓冲区
|
|
|
-// byte[] buf = new byte[1024 * 10];
|
|
|
-// while((read = bufferStream.read(buf, 0, 1024 * 10)) != -1)
|
|
|
-// {
|
|
|
-// zipStream.write(buf, 0, read);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// } finally {
|
|
|
-// //关闭流
|
|
|
-// try {
|
|
|
-// if(null != bufferStream) bufferStream.close();
|
|
|
-// if(null != zipStream) zipStream.close();
|
|
|
-// if(null != zipSource) zipSource.close();
|
|
|
-// } catch (IOException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
+ String[] path = {"D:\\666.jpg", "D:\\777.jpg"};
|
|
|
+ // 要生成的压缩文件地址和文件名称
|
|
|
+ String desPath = "D:\\new.zip";
|
|
|
+ File zipFile = new File(desPath);
|
|
|
+ ZipOutputStream zipStream = null;
|
|
|
+ FileInputStream zipSource = null;
|
|
|
+ BufferedInputStream bufferStream = null;
|
|
|
+ try {
|
|
|
+ //构造最终压缩包的输出流
|
|
|
+ zipStream = new ZipOutputStream(new FileOutputStream(zipFile));
|
|
|
+ for (int i = 0; i < path.length; i++) {
|
|
|
+ File file = new File(path[i]);
|
|
|
+ //将需要压缩的文件格式化为输入流
|
|
|
+ zipSource = new FileInputStream(file);
|
|
|
+ //压缩条目不是具体独立的文件,而是压缩包文件列表中的列表项,称为条目,就像索引一样
|
|
|
+ ZipEntry zipEntry = new ZipEntry(i + "2222.jpg");//"2222.jpg"是添加到压缩包里的源文件的名字加i是防止名字相同出错
|
|
|
+ //定位该压缩条目位置,开始写入文件到压缩包中
|
|
|
+ zipStream.putNextEntry(zipEntry);
|
|
|
+ //输入缓冲流
|
|
|
+ bufferStream = new BufferedInputStream(zipSource, 1024 * 10);
|
|
|
+ int read = 0;
|
|
|
+ //创建读写缓冲区
|
|
|
+ byte[] buf = new byte[1024 * 10];
|
|
|
+ while ((read = bufferStream.read(buf, 0, 1024 * 10)) != -1) {
|
|
|
+ zipStream.write(buf, 0, read);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ //关闭流
|
|
|
+ try {
|
|
|
+ if (null != bufferStream) bufferStream.close();
|
|
|
+ if (null != zipStream) zipStream.close();
|
|
|
+ if (null != zipSource) zipSource.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void zip4jDemo(){
|
|
|
+// 生成的压缩文件
|
|
|
+ ZipFile zipFile = null;
|
|
|
+ try {
|
|
|
+ zipFile = new ZipFile("D:\\aa.zip");
|
|
|
+
|
|
|
+ ZipParameters parameters = new ZipParameters();
|
|
|
+ // 压缩方式
|
|
|
+ parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
|
|
|
+ // 压缩级别
|
|
|
+ parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
|
|
|
+ // 要打包的文件夹
|
|
|
+ File currentFile = new File("D:\\666");
|
|
|
+ File[] fs = currentFile.listFiles();
|
|
|
+ // 遍历test文件夹下所有的文件、文件夹
|
|
|
+ for (File f : fs) {
|
|
|
+ if (f.isDirectory()) {
|
|
|
+ zipFile.addFolder(f.getPath(), parameters);
|
|
|
+ } else {
|
|
|
+ zipFile.addFile(f, parameters);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ zipFile.addFolder("D:\\666", parameters);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|