From: Marko Luukkainen Date: Tue, 8 Dec 2020 10:08:15 +0000 (+0200) Subject: Using non default charset for uncompressing zip files. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F23%2F4623%2F1;p=simantics%2Fplatform.git Using non default charset for uncompressing zip files. gitlab #656 Change-Id: I945522e99824f81e1755dae392d74c6b4b0e379e --- diff --git a/bundles/org.simantics.utils/src/org/simantics/utils/FileUtils.java b/bundles/org.simantics.utils/src/org/simantics/utils/FileUtils.java index 44a3dfcf5..c887126c2 100644 --- a/bundles/org.simantics.utils/src/org/simantics/utils/FileUtils.java +++ b/bundles/org.simantics.utils/src/org/simantics/utils/FileUtils.java @@ -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();