changeset 482:dd412faf7b4d

Framework: Added FileFilter to ZIP file creation.
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 07 May 2013 11:45:47 +0200 (2013-05-07)
parents b8067c6f67f6
children 26ae3267bb32
files artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/FileTools.java
diffstat 1 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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()) {

http://dive4elements.wald.intevation.org