]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Using non default charset for uncompressing zip files. 23/4623/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 8 Dec 2020 10:08:15 +0000 (12:08 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 8 Dec 2020 10:08:15 +0000 (12:08 +0200)
gitlab #656

Change-Id: I945522e99824f81e1755dae392d74c6b4b0e379e

bundles/org.simantics.utils/src/org/simantics/utils/FileUtils.java

index 44a3dfcf5731b9ff2c9334959a66e3463416f283..c887126c29396ca21c802b2e1f5443d8b1597fad 100644 (file)
@@ -28,6 +28,7 @@ import java.net.URI;
 import java.net.URL;
 import java.nio.channels.FileChannel;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -848,7 +849,14 @@ public class FileUtils {
             extractZip(fis, dst);
         }
     }
-
+    
+    public static void extractZip(File zipFile, File dst, Charset charset) throws IOException {
+        if (LOGGER.isTraceEnabled())
+            LOGGER.trace("Extracting zip "+zipFile);
+        try (FileInputStream fis = new FileInputStream(zipFile)) {
+            extractZip(fis, dst, charset);
+        }
+    }
     /**
      * Extract a zip file into a directory
      * 
@@ -857,8 +865,12 @@ public class FileUtils {
      * @throws IOException
      */
     public static void extractZip(InputStream zipInput, File dst) throws IOException {
+       extractZip(zipInput, dst, StandardCharsets.UTF_8);
+    }
+    
+    public static void extractZip(InputStream zipInput, File dst, Charset charset) throws IOException {
         byte[] buf = new byte[8192];
-        ZipInputStream zis = new ZipInputStream(zipInput);
+        ZipInputStream zis = new ZipInputStream(zipInput, charset);
         ZipEntry entry;
 
         entry = zis.getNextEntry();