[Dive4elements-commits] [PATCH 1 of 2] Framework: Added FileFilter to ZIP file creation

Wald Commits scm-commit at wald.intevation.org
Tue May 7 11:46:38 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1367919947 -7200
# Node ID dd412faf7b4d98cf36492c3018a2884f168d0680
# Parent  b8067c6f67f641bf267c48a37db29fc572380510
Framework: Added FileFilter to ZIP file creation.

diff -r b8067c6f67f6 -r dd412faf7b4d artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/FileTools.java
--- a/artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/FileTools.java	Thu Apr 25 19:25:10 2013 +0200
+++ b/artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/FileTools.java	Tue May 07 11:45:47 2013 +0200
@@ -9,6 +9,7 @@
 
 import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileFilter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.FileInputStream;
@@ -313,6 +314,21 @@
 
         return file.delete();
     }
+    public static final FileFilter ACCEPT_ALL = new FileFilter() {
+        @Override
+        public boolean accept(File file) {
+            return true;
+        }
+    };
+
+    public static void createZipArchive(
+        File         file,
+        OutputStream outputStream
+    )
+    throws IOException
+    {
+        createZipArchive(file, outputStream, ACCEPT_ALL);
+    }
 
     /**
      * Put the given file or directory into a zip archive.
@@ -324,13 +340,14 @@
      */
     public static void createZipArchive(
         File         file,
-        OutputStream outputStream
+        OutputStream outputStream,
+        FileFilter   filter
     )
     throws IOException
     {
         ZipOutputStream out = new ZipOutputStream(outputStream);
 
-        if (file.isFile()) {
+        if (filter.accept(file) && file.isFile()) {
             copyFileToZip("", file, out);
         }
         else if (file.isDirectory()) {
@@ -345,7 +362,7 @@
                 out.putNextEntry(dirEntry);
                 out.closeEntry();
 
-                File [] files = pd.dir.listFiles();
+                File [] files = pd.dir.listFiles(filter);
                 if (files != null) {
                     for (File sub: files) {
                         if (sub.isDirectory()) {


More information about the Dive4elements-commits mailing list