changeset 1234:c5c48f52dc7b

Removed FileTools that has been moved to artifacts-common module. flys-backend/trunk@2585 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 25 Aug 2011 14:41:39 +0000
parents 5a3109b8475f
children 47ce1fab8464
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/AnnotationsParser.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/HYKParser.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/InfoGewParser.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/PRFParser.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/PegelGltParser.java flys-backend/src/main/java/de/intevation/flys/utils/FileTools.java
diffstat 9 files changed, 25 insertions(+), 231 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Thu Aug 25 10:19:21 2011 +0000
+++ b/flys-backend/ChangeLog	Thu Aug 25 14:41:39 2011 +0000
@@ -1,3 +1,17 @@
+2011-08-25  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/utils/FileTools.java: Moved to
+	  artifacts-common module.
+
+	* src/main/java/de/intevation/flys/importer/parsers/PegelGltParser.java,
+	  src/main/java/de/intevation/flys/importer/parsers/PRFParser.java,
+	  src/main/java/de/intevation/flys/importer/parsers/HYKParser.java,
+	  src/main/java/de/intevation/flys/importer/parsers/AnnotationsParser.java,
+	  src/main/java/de/intevation/flys/importer/parsers/InfoGewParser.java,
+	  src/main/java/de/intevation/flys/importer/ImportRiver.java,
+	  src/main/java/de/intevation/flys/importer/ImportGauge.java: Adjusted
+	  imports of FileTools.
+
 2011-08-25  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/model/Gauge.java (getMainValues)
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java	Thu Aug 25 10:19:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java	Thu Aug 25 14:41:39 2011 +0000
@@ -7,11 +7,11 @@
 
 import java.math.BigDecimal;
 
+import de.intevation.artifacts.common.utils.FileTools;
+
 import de.intevation.flys.model.River;
 import de.intevation.flys.model.Gauge;
 
-import de.intevation.flys.utils.FileTools;
-
 import org.hibernate.Session;
 import org.hibernate.Query;
 
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Thu Aug 25 10:19:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Thu Aug 25 14:41:39 2011 +0000
@@ -15,10 +15,10 @@
 
 import org.apache.log4j.Logger;
 
-import de.intevation.flys.model.River;
+import de.intevation.artifacts.common.utils.FileTools;
+import de.intevation.artifacts.common.utils.FileTools.HashedFile;
 
-import de.intevation.flys.utils.FileTools;
-import de.intevation.flys.utils.FileTools.HashedFile;
+import de.intevation.flys.model.River;
 
 import de.intevation.flys.importer.parsers.PRFParser;
 import de.intevation.flys.importer.parsers.HYKParser;
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/AnnotationsParser.java	Thu Aug 25 10:19:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/AnnotationsParser.java	Thu Aug 25 14:41:39 2011 +0000
@@ -15,7 +15,7 @@
 
 import org.apache.log4j.Logger;
 
-import de.intevation.flys.utils.FileTools;
+import de.intevation.artifacts.common.utils.FileTools;
 
 import de.intevation.flys.importer.ImportAnnotation;
 import de.intevation.flys.importer.ImportRange;
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/HYKParser.java	Thu Aug 25 10:19:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/HYKParser.java	Thu Aug 25 14:41:39 2011 +0000
@@ -1,5 +1,7 @@
 package de.intevation.flys.importer.parsers;
 
+import de.intevation.artifacts.common.utils.FileTools;
+
 import de.intevation.flys.importer.ImportHYK;
 import de.intevation.flys.importer.ImportHYKEntry;
 import de.intevation.flys.importer.ImportHYKFormation;
@@ -21,8 +23,6 @@
 
 import org.apache.log4j.Logger;
 
-import de.intevation.flys.utils.FileTools;
-
 public class HYKParser
 {
     private static Logger log = Logger.getLogger(HYKParser.class);
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/InfoGewParser.java	Thu Aug 25 10:19:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/InfoGewParser.java	Thu Aug 25 14:41:39 2011 +0000
@@ -15,7 +15,7 @@
 
 import org.apache.log4j.Logger;
 
-import de.intevation.flys.utils.FileTools;
+import de.intevation.artifacts.common.utils.FileTools;
 
 import de.intevation.flys.importer.ImportRiver;
 
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/PRFParser.java	Thu Aug 25 10:19:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/PRFParser.java	Thu Aug 25 14:41:39 2011 +0000
@@ -19,7 +19,7 @@
 
 import de.intevation.flys.importer.XY;
 
-import de.intevation.flys.utils.FileTools;
+import de.intevation.artifacts.common.utils.FileTools;
 
 public class PRFParser
 {
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/PegelGltParser.java	Thu Aug 25 10:19:21 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/PegelGltParser.java	Thu Aug 25 14:41:39 2011 +0000
@@ -14,7 +14,7 @@
 
 import org.apache.log4j.Logger;
 
-import de.intevation.flys.utils.FileTools;
+import de.intevation.artifacts.common.utils.FileTools;
 
 import de.intevation.flys.importer.ImportGauge;
 import de.intevation.flys.importer.ImportRange;
--- a/flys-backend/src/main/java/de/intevation/flys/utils/FileTools.java	Thu Aug 25 10:19:21 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,220 +0,0 @@
-package de.intevation.flys.utils;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.FileInputStream;
-
-import java.util.Stack;
-import java.util.List;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.ArrayList;
-
-import org.apache.log4j.Logger;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-public class FileTools
-{
-    private static Logger log = Logger.getLogger(FileTools.class);
-
-    public static final String DIGEST =
-        System.getProperty("flys.backend.file.cmp.digest", "MD5");
-
-    private FileTools() {
-    }
-
-    public static File repair(File file) {
-        file = file.getAbsoluteFile();
-        if (file.exists()) {
-            return file;
-        }
-        Stack<String> parts = new Stack<String>();
-        File curr = file;
-        while (curr != null) {
-            String name = curr.getName();
-            if (name.length() > 0) {
-                parts.push(curr.getName());
-            }
-            curr = curr.getParentFile();
-        }
-
-        curr = null;
-        OUTER: while (!parts.isEmpty()) {
-            String f = parts.pop();
-            log.debug("fixing: '" + f + "'");
-            if (curr == null) {
-                // XXX: Not totaly correct because there
-                // more than one root on none unix systems.
-                for (File root: File.listRoots()) {
-                    File [] files = root.listFiles();
-                    if (files == null) {
-                        log.warn("cannot list '" + root);
-                        continue;
-                    }
-                    for (File candidate: files) {
-                        if (candidate.getName().equalsIgnoreCase(f)) {
-                            curr = new File(root, candidate.getName());
-                            continue OUTER;
-                        }
-                    }
-                }
-                break;
-            }
-            else {
-                File [] files = curr.listFiles();
-                if (files == null) {
-                    log.warn("cannot list: '" + curr + "'");
-                    return file;
-                }
-                for (File candidate: files) {
-                    if (candidate.getName().equalsIgnoreCase(f)) {
-                        curr = new File(curr, candidate.getName());
-                        continue OUTER;
-                    }
-                }
-                curr = null;
-                break;
-            }
-        }
-
-        if (curr == null) {
-            log.warn("cannot repair path '" + file + "'");
-            return file;
-        }
-
-        return curr;
-    }
-
-    public static class HashedFile 
-    implements Comparable<HashedFile>
-    {
-        protected File    file;
-        protected long    length;
-        protected byte [] hash;
-
-        public HashedFile(File file) {
-            this.file = file;
-            length = file.length();
-        }
-
-        public File getFile() {
-            return file;
-        }
-
-        protected byte [] getHash() {
-            if (hash == null) {
-                InputStream in = null;
-
-                try {
-                    in = new FileInputStream(file);
-
-                    MessageDigest digest = MessageDigest.getInstance(DIGEST);
-
-                    byte [] buf = new byte[40*1024];
-                    int r;
-
-                    while ((r = in.read(buf)) >= 0) {
-                        digest.update(buf, 0, r);
-                    }
-
-                    hash = digest.digest();
-                }
-                catch (IOException ioe) {
-                    log.error(ioe);
-                    hash = new byte[0];
-                }
-                catch (NoSuchAlgorithmException nsae) {
-                    log.error(nsae);
-                    hash = new byte[0];
-                }
-                finally {
-                    if (in != null) {
-                        try {
-                            in.close();
-                        }
-                        catch (IOException ioe) {
-                            log.error(ioe);
-                        }
-                    }
-                }
-            }
-            return hash;
-        }
-
-        @Override
-        public int compareTo(HashedFile other) {
-            if (length < other.length) return -1;
-            if (length > other.length) return +1;
-            return compare(getHash(), other.getHash());
-        }
-
-        private static int compare(byte [] a, byte [] b) {
-            if (a.length < b.length) return -1;
-            if (a.length > b.length) return +1;
-            for (int i = 0; i < a.length; ++i) {
-                int x = a[i] & 0xff;
-                int y = b[i] & 0xff;
-                if (x < y) return -1;
-                if (x > y) return +1;
-            }
-            return 0;
-        }
-
-        @Override
-        public boolean equals(Object other) {
-            return other instanceof HashedFile 
-                && ((HashedFile)other).compareTo(this) == 0;
-        }
-
-        @Override
-        public int hashCode() {
-            return (int)(length ^ (length >>> 32));
-        }
-    } // class HashedFile
-
-    public static List<File> uniqueFiles(List<File> files) {
-
-        Set<HashedFile> set = new HashSet<HashedFile>();
-
-        for (File file: files) {
-            if (!set.add(new HashedFile(file))) {
-                log.warn("file '" + file + "' is a duplicate.");
-            }
-        }
-
-        ArrayList<File> out = new ArrayList<File>(set.size());
-        for (HashedFile hf: set) {
-            out.add(hf.file);
-        }
-
-        return out;
-    }
-
-    public interface FileVisitor {
-        boolean visit(File file);
-    } // Visitor
-
-    public static void walkTree(File root, FileVisitor visitor) {
-
-        Stack<File> stack = new Stack<File>();
-
-        stack.push(root);
-
-        while (!stack.isEmpty()) {
-            File current = stack.pop();
-            if (!visitor.visit(current)) break;
-            if (current.isDirectory()) {
-                File [] subs = current.listFiles();
-                if (subs != null) {
-                    for (File f: subs) {
-                        stack.push(f);
-                    }
-                }
-            }
-        }
-    }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org