From 085c7a1cccdde1e8a06f2024c46bd8502df58adb Mon Sep 17 00:00:00 2001 From: Jeremy Wood Date: Thu, 19 Jul 2012 21:08:39 -0400 Subject: [PATCH] Migrated Multiverse-Adventure's copyFolder() into core. --- .../MultiverseCore/utils/FileUtils.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/FileUtils.java b/src/main/java/com/onarandombox/MultiverseCore/utils/FileUtils.java index 5047d845..f04e9745 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/FileUtils.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/FileUtils.java @@ -8,6 +8,13 @@ package com.onarandombox.MultiverseCore.utils; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.logging.Logger; /** * File-utilities. @@ -37,4 +44,57 @@ public class FileUtils { return false; } } + + /** + * Helper method to copy the world-folder + * + * @returns if it had success + */ + public static boolean copyFolder(File source, File target, Logger log) { + InputStream in = null; + OutputStream out = null; + try { + if (source.isDirectory()) { + + if (!target.exists()) + target.mkdir(); + + String[] children = source.list(); + // for (int i=0; i 0) { + out.write(buf, 0, len); + } + } + return true; + } + catch (FileNotFoundException e) { + log.warning("Exception while copying file: " + e.getMessage()); + } + catch (IOException e) { + log.warning("Exception while copying file: " + e.getMessage()); + } + finally { + if (in != null) { + try { + in.close(); + } catch (IOException ignore) { } + } + if (out != null) { + try { + out.close(); + } catch (IOException ignore) { } + } + } + return false; + } }