From 6aeb1c17992bbefb3a4469cf8d70d1488baf87bd Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期六, 22 七月 2023 16:04:46 +0800 Subject: [PATCH] 修改代理服务、zip解压 --- src/main/java/com/moon/server/helper/ZipHelper.java | 74 +++++++++++++++++++++++++------------ 1 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/moon/server/helper/ZipHelper.java b/src/main/java/com/moon/server/helper/ZipHelper.java index 9a56595..9b1ce99 100644 --- a/src/main/java/com/moon/server/helper/ZipHelper.java +++ b/src/main/java/com/moon/server/helper/ZipHelper.java @@ -36,31 +36,9 @@ dir.mkdirs(); } - int count; zipFile = new ZipFile(filePath, Charset.forName("GBK")); - 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(); - fos.close(); - is.close(); - } + createDirs(zipFile, zipDir); + writeFiles(zipFile, zipDir); return true; } catch (Exception ex) { @@ -78,6 +56,54 @@ } /** + * 鍒涘缓鐩綍 + */ + private static void createDirs(ZipFile zipFile, String zipDir) { + 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(); + } + } + } + } + + /** + * 鍐欐枃浠� + */ + private static void writeFiles(ZipFile zipFile, String zipDir) throws IOException { + Enumeration<?> e = zipFile.entries(); + while (e.hasMoreElements()) { + ZipEntry entry = (ZipEntry) e.nextElement(); + if (!entry.isDirectory()) { + writeFile(zipFile, entry, zipDir); + } + } + } + + /** + * 鍐欐枃浠� + */ + private static void writeFile(ZipFile zipFile, ZipEntry entry, String zipDir) throws IOException { + int count; + + 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(); + fos.close(); + is.close(); + } + + /** * Zip鍘嬬缉 * * @param zipFile zip婧愭枃浠� -- Gitblit v1.9.3