From 57283ecd9904109f2e31aaf0643d25050ecf132a Mon Sep 17 00:00:00 2001 From: 1 <1@qq> Date: Wed, 10 Apr 2019 20:32:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8IOUtils.zip=E5=8E=8B=E7=BC=A9=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/FileEntityBuilder.java | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java index 85d8e40ce..e9eec71b8 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java @@ -18,14 +18,12 @@ import com.fr.third.org.apache.http.entity.mime.content.FileBody; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; -import java.util.zip.ZipEntry; /** * @author alex sung @@ -83,24 +81,9 @@ public class FileEntityBuilder { public File generateZipFile(String pathName) { File zipFile = null; try { - File file = new File(pathName); zipFile = new File(pathName + ".zip"); - InputStream input = null; - java.util.zip.ZipOutputStream zipOut = null; - zipOut = new java.util.zip.ZipOutputStream(new FileOutputStream(zipFile)); - int temp = 0; - if (file.isDirectory()) { - File lists[] = file.listFiles(); - for (int i = 0; i < lists.length; i++) { - input = new FileInputStream(lists[i]); - zipOut.putNextEntry(new ZipEntry(file.getName() - + File.separator + lists[i].getName())); - while ((temp = input.read()) != -1) { - zipOut.write(temp); - } - input.close(); - } - } + java.util.zip.ZipOutputStream zipOut = new java.util.zip.ZipOutputStream(new FileOutputStream(zipFile)); + IOUtils.zip(zipOut, new File(pathName)); zipOut.close(); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); @@ -159,7 +142,7 @@ public class FileEntityBuilder { return data.optString("url"); } } catch (JSONException e) { - FineLoggerFactory.getLogger().error("Illegal response text."); + FineLoggerFactory.getLogger().error("Illegal response text."+e, e.getMessage()); } return null; }