Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/utils/FileUtils.java @ 5076:cc50e1b9fc60 mapgenfix
Work on ArtifactMapfileGenerator.createUserShapefileLayer()
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Wed, 20 Feb 2013 21:00:33 +0100 |
parents | a9243df307b1 |
children |
line wrap: on
line source
package de.intevation.flys.utils; import de.intevation.artifacts.common.utils.FileTools; import de.intevation.flys.artifacts.states.FloodMapState; import java.io.File; import java.io.IOException; /** * Various utility methods for handling of files and directories. * @author <a href="mailto:christian.lins@intevation.de">Christian Lins</a> */ public class FileUtils { public static boolean extractZipfile(File archive, File dir) { try { File tmpDir = new File(dir, "usr_tmp"); FileTools.extractArchive(archive, tmpDir); FileUtils.moveFiles(tmpDir, dir); return true; } catch (IOException ioe) { FloodMapState.logger.warn("Zip archive " + dir + "/" + FloodMapState.WSPLGEN_USER_ZIP + " could not be extracted."); return false; } } public static void moveFiles(File source, final File target) throws IOException { if (!source.exists()) { return; } if (!target.exists()) { target.mkdir(); } FileTools.walkTree(source, new FileTools.FileVisitor() { @Override public boolean visit(File file) { if (!file.isDirectory()) { String name = file.getName(); String suffix = ""; int pos = name.lastIndexOf('.'); if (pos > 0 && pos < name.length() - 1) { suffix = name.substring(pos + 1); } else { return true; } try { FileTools.copyFile(file, new File(target, FloodMapState.WSPLGEN_USER_FILENAME + "." + suffix)); } catch (IOException ioe) { FloodMapState.logger.warn ("Error while copying file " + file.getName()); return true; } } return true; } }); FileTools.deleteRecursive(source); } }