branch develop updated (c279638 -> ce5a614)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository nuiton-utils. See http://git.nuiton.org/nuiton-utils.git from c279638 Add a method FileUtil#isGzipFile to test if a file is gzipped (fixes #3770) Merge branch 'feature/3770' into develop new ce5a614 Add also a method to check if an inputStream is GZippped (See #3770) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit ce5a61456f6b577776b84751bcda3cd717e78f20 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Aug 27 10:57:33 2015 +0200 Add also a method to check if an inputStream is GZippped (See #3770) Summary of changes: src/main/java/org/nuiton/util/FileUtil.java | 9 +-------- src/main/java/org/nuiton/util/GZUtil.java | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-utils. See http://git.nuiton.org/nuiton-utils.git commit ce5a61456f6b577776b84751bcda3cd717e78f20 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Aug 27 10:57:33 2015 +0200 Add also a method to check if an inputStream is GZippped (See #3770) --- src/main/java/org/nuiton/util/FileUtil.java | 9 +-------- src/main/java/org/nuiton/util/GZUtil.java | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/nuiton/util/FileUtil.java b/src/main/java/org/nuiton/util/FileUtil.java index 210d96a..ae6c259 100644 --- a/src/main/java/org/nuiton/util/FileUtil.java +++ b/src/main/java/org/nuiton/util/FileUtil.java @@ -58,7 +58,6 @@ import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.zip.GZIPInputStream; /** * Opérations sur des fichiers. Copie, suppression, renommage, @@ -1361,13 +1360,7 @@ public class FileUtil { // FileUtil public static boolean isGzipFile(File file) throws IOException { try (InputStream in = new BufferedInputStream(new FileInputStream(file))) { - in.mark(2); - // read header to see if is compressed file - int b = in.read(); - // redundant cast : int magic = ((int) in.read() << 8) | b; - int magic = in.read() << 8 | b; - in.reset(); - boolean gzip = magic == GZIPInputStream.GZIP_MAGIC; + boolean gzip = GZUtil.isGzipStream(in); return gzip; } } diff --git a/src/main/java/org/nuiton/util/GZUtil.java b/src/main/java/org/nuiton/util/GZUtil.java index 75a3d87..a13fb79 100644 --- a/src/main/java/org/nuiton/util/GZUtil.java +++ b/src/main/java/org/nuiton/util/GZUtil.java @@ -39,6 +39,7 @@ import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.Reader; import java.io.StringReader; import java.util.zip.GZIPInputStream; @@ -46,6 +47,29 @@ import java.util.zip.GZIPOutputStream; public class GZUtil { // GZUtil + /** + * Tests if an inputStream is GZipped. + * + * <b>Note:</b> the stream is not closed and is reset. + * + * @param inputStream inputStream to test + * @return {@code true} if inputStream is gzipped, {@code false} otherwise + * @throws IOException if any io errors while reading inputStream + * @since 3.0 + */ + public static boolean isGzipStream(InputStream inputStream) throws IOException { + + inputStream.mark(2); + // read header to see if is compressed file + int b = inputStream.read(); + // redundant cast : int magic = ((int) in.read() << 8) | b; + int magic = inputStream.read() << 8 | b; + inputStream.reset(); + boolean gzip = magic == GZIPInputStream.GZIP_MAGIC; + return gzip; + + } + /** Retourne la string decompressee */ public static StringBuffer bytesToStringBuffer(byte[] in) { try { -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm