changeset 483:26ae3267bb32 3.0.3

Merged
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 07 May 2013 11:46:31 +0200
parents dd412faf7b4d (diff) 6f6a5b229a7a (current diff)
children 64557fa4d432
files
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	Mon May 06 16:36:07 2013 +0200
+++ b/artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/FileTools.java	Tue May 07 11:46:31 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