From 41e661c57a6011a25c3aaf6647d20a03df7c17a3 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 20 十月 2022 16:03:10 +0800
Subject: [PATCH] 添加zip包处理工具

---
 src/main/java/com/lf/server/config/InitConfig.java |    9 ++-
 src/main/java/com/lf/server/helper/ZipHelper.java  |  130 +++++++++++++++++++++++++++++++++++++++++++
 data/menu-执行.xls                                   |    0 
 说明.txt                                             |    1 
 4 files changed, 137 insertions(+), 3 deletions(-)

diff --git "a/data/menu-\346\211\247\350\241\214.xls" "b/data/menu-\346\211\247\350\241\214.xls"
index c9cb580..2f0f578 100644
--- "a/data/menu-\346\211\247\350\241\214.xls"
+++ "b/data/menu-\346\211\247\350\241\214.xls"
Binary files differ
diff --git a/src/main/java/com/lf/server/config/InitConfig.java b/src/main/java/com/lf/server/config/InitConfig.java
index dbd08ce..66f5f24 100644
--- a/src/main/java/com/lf/server/config/InitConfig.java
+++ b/src/main/java/com/lf/server/config/InitConfig.java
@@ -6,6 +6,7 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.lf.server.entity.bd.DlgAgnpEntity;
 import com.lf.server.helper.PathHelper;
+import com.lf.server.helper.ZipHelper;
 import com.lf.server.mapper.bd.DlgAgnpMapper;
 import com.lf.server.service.sys.ArgsService;
 import org.apache.commons.logging.Log;
@@ -41,17 +42,19 @@
     public void run(ApplicationArguments args) {
         // noinspection AlibabaRemoveCommentedCode
         try {
-            // "E:\\data\\7.Insar\\insartest.tif","E:\\data\\6.楂樺厜璋盶\GF5_Cut_1.img","E:\\data\\22.tif\\110.747 sq km.tif","E:\\Test\\Test.gdb"
+            // GDAL娴嬭瘯锛�"E:\\data\\7.Insar\\insartest.tif","E:\\data\\6.楂樺厜璋盶\GF5_Cut_1.img","E:\\data\\22.tif\\110.747 sq km.tif","E:\\Test\\Test.gdb"
             //GdalHelper.readTif("E:\\data\\7.Insar\\insartest.tif")
             //GdalHelper.readShp("E:\\data\\13.cppe\\shps\\addr.shp");
             //GdalHelper.readGdb("E:\\Test\\addr.gdb");
 
             //com.lf.server.helper.RsaHelper.generate();
-
             //testMybatisPlus();
 
-            pathHelper.init();
+            //boolean f1 = ZipHelper.unzip("D:\\LF\\data\\resources.zip", "D:\\LF\\data\\unzip");
+            boolean f2 = ZipHelper.zip("D:\\LF\\data\\res.zip", "D:\\LF\\data\\unzip\\resources");
 
+            // 鍒濆鍖�
+            pathHelper.init();
             argsService.initSettingData();
 
             log.info("***************** 绯荤粺鍚姩瀹屾瘯 *****************" + "\n");
diff --git a/src/main/java/com/lf/server/helper/ZipHelper.java b/src/main/java/com/lf/server/helper/ZipHelper.java
new file mode 100644
index 0000000..0b21fe2
--- /dev/null
+++ b/src/main/java/com/lf/server/helper/ZipHelper.java
@@ -0,0 +1,130 @@
+package com.lf.server.helper;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.*;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * Zip甯姪绫�
+ * @author WWW
+ */
+public class ZipHelper {
+    private final static int BUFFER_SIZE = 1024;
+
+    private final static byte[] BUFFER = new byte[1024];
+
+    private final static Log log = LogFactory.getLog(ZipHelper.class);
+
+    /**
+     * 瑙e帇缂�
+     *
+     * @param filePath zip鏂囦欢
+     * @param zipDir   瑙e帇璺緞
+     * @return 鎴愬姛鏄�/鍚�
+     */
+    public static boolean unzip(String filePath, String zipDir) {
+        try {
+            int count;
+            ZipFile zipfile = new ZipFile(filePath);
+
+            Enumeration e = zipfile.entries();
+            while (e.hasMoreElements()) {
+                ZipEntry entry = (ZipEntry) e.nextElement();
+                if (entry.isDirectory()) {
+                    File f = new File(zipDir + File.separator + entry.getName());
+                    if (!f.exists()) {
+                        f.mkdirs();
+                    }
+                    continue;
+                }
+
+                BufferedInputStream is = new BufferedInputStream(zipfile.getInputStream(entry));
+                FileOutputStream fos = new FileOutputStream(zipDir + File.separator + entry.getName());
+                BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE);
+
+                while ((count = is.read(BUFFER, 0, BUFFER_SIZE)) != -1) {
+                    dest.write(BUFFER, 0, count);
+                }
+                dest.flush();
+                dest.close();
+                is.close();
+            }
+
+            return true;
+        } catch (Exception ex) {
+            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
+            return false;
+        }
+    }
+
+    /**
+     * Zip鍘嬬缉
+     *
+     * @param zipFile   Zip婧愭枃浠�
+     * @param sourceDir 婧愭枃浠跺す
+     * @return 鎴愬姛鏄�/鍚�
+     */
+    public static boolean zip(String zipFile, String sourceDir) {
+        ZipOutputStream zos = null;
+        try {
+            FileOutputStream fileOutputStream = new FileOutputStream(zipFile);
+            zos = new ZipOutputStream(fileOutputStream);
+
+            File sourceFile = new File(sourceDir);
+            compress(sourceFile, zos, sourceFile.getName());
+
+            return true;
+        } catch (Exception ex) {
+            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
+            return false;
+        } finally {
+            try {
+                if (zos != null) {
+                    zos.close();
+                }
+            } catch (Exception e) {
+                log.error(e.getMessage() + e.getStackTrace() + "\n");
+            }
+        }
+    }
+
+    /**
+     * Zip鍘嬬缉
+     *
+     * @param sourceFile Zip婧愭枃浠�
+     * @param zos        Zip杈撳嚭娴�
+     * @param name       Zip鏂囦欢鍚嶇О
+     * @throws Exception
+     */
+    public static void compress(File sourceFile, ZipOutputStream zos, String name) throws Exception {
+        if (sourceFile.isFile()) {
+            // 鍚憐ip杈撳嚭娴佷腑娣诲姞涓�涓獄ip瀹炰綋锛屾瀯閫犲櫒涓璶ame涓簔ip瀹炰綋鐨勬枃浠剁殑鍚嶅瓧
+            zos.putNextEntry(new ZipEntry(name));
+
+            // copy鏂囦欢鍒皕ip杈撳嚭娴佷腑
+            int len;
+            FileInputStream in = new FileInputStream(sourceFile);
+            while ((len = in.read(BUFFER)) != -1) {
+                zos.write(BUFFER, 0, len);
+            }
+            zos.closeEntry();
+            in.close();
+        } else {
+            File[] listFiles = sourceFile.listFiles();
+            if (listFiles == null || listFiles.length == 0) {
+                // 绌烘枃浠跺す鐨勫鐞嗭細娌℃湁鏂囦欢锛屼笉闇�瑕佹枃浠剁殑copy
+                zos.putNextEntry(new ZipEntry(name + "/"));
+                zos.closeEntry();
+            } else {
+                for (File file : listFiles) {
+                    compress(file, zos, name + "/" + file.getName());
+                }
+            }
+        }
+    }
+}
diff --git "a/\350\257\264\346\230\216.txt" "b/\350\257\264\346\230\216.txt"
index c05e803..f74cc80 100644
--- "a/\350\257\264\346\230\216.txt"
+++ "b/\350\257\264\346\230\216.txt"
@@ -22,6 +22,7 @@
 .淇敼鎵�鏈夌殑鎵归噺鏂板銆佸垹闄ゃ�佷慨鏀规帴鍙�
 .寮�鍙戝ぇ鏂囦欢涓婁紶鎺ュ彛
 .瑙e喅涓婁紶鏂囦欢鏃跺疄浣撶被鏄犲皠寮傚父
+.寮�鍙戝湴鍚嶅湴鍧�鍒嗛〉鏌ヨ鎺ュ彛
 
 -----------------------------------------------
 1.涓婁紶鏂囦欢锛坈ommons-fileupload锛� *

--
Gitblit v1.9.3