branch develop updated (d80d9cc -> c279638)
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 d80d9cc Fix target type (See #3769) new 1bbeedc Add method to test if a file is GZipped (See #3770) new c279638 Add a method FileUtil#isGzipFile to test if a file is gzipped (fixes #3770) Merge branch 'feature/3770' into develop The 2 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 c27963827b1510fa059b98fef0f5b505737c4c83 Merge: d80d9cc 1bbeedc Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Aug 27 09:34:02 2015 +0200 Add a method FileUtil#isGzipFile to test if a file is gzipped (fixes #3770) Merge branch 'feature/3770' into develop commit 1bbeedc6f2d3c9e6da0297bcef0441ec2a52e145 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Aug 27 09:34:00 2015 +0200 Add method to test if a file is GZipped (See #3770) Summary of changes: src/main/java/org/nuiton/util/FileUtil.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) -- 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 1bbeedc6f2d3c9e6da0297bcef0441ec2a52e145 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Aug 27 09:34:00 2015 +0200 Add method to test if a file is GZipped (See #3770) --- src/main/java/org/nuiton/util/FileUtil.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/org/nuiton/util/FileUtil.java b/src/main/java/org/nuiton/util/FileUtil.java index b07ffa6..210d96a 100644 --- a/src/main/java/org/nuiton/util/FileUtil.java +++ b/src/main/java/org/nuiton/util/FileUtil.java @@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFactory; import javax.swing.JFileChooser; import java.awt.Component; +import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -57,6 +58,7 @@ 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, @@ -1348,4 +1350,26 @@ public class FileUtil { // FileUtil return databaseFile; } + /** + * Tests if a file is GZipped. + * + * @param file file to test + * @return {@code true} if file is gzipped, {@code false} otherwise + * @throws IOException if any io errors while reading file + * @since 3.0 + */ + 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; + return gzip; + } + } + } // FileUtil -- 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 c27963827b1510fa059b98fef0f5b505737c4c83 Merge: d80d9cc 1bbeedc Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Aug 27 09:34:02 2015 +0200 Add a method FileUtil#isGzipFile to test if a file is gzipped (fixes #3770) Merge branch 'feature/3770' into develop src/main/java/org/nuiton/util/FileUtil.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm