mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 18:47:20 +01:00
Migrated Multiverse-Adventure's copyFolder() into core.
This commit is contained in:
parent
3e7841afc9
commit
085c7a1ccc
@ -8,6 +8,13 @@
|
|||||||
package com.onarandombox.MultiverseCore.utils;
|
package com.onarandombox.MultiverseCore.utils;
|
||||||
|
|
||||||
import java.io.File;
|
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.
|
* File-utilities.
|
||||||
@ -37,4 +44,57 @@ public class FileUtils {
|
|||||||
return false;
|
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<children.length; i++) {
|
||||||
|
for (String child : children) {
|
||||||
|
copyFolder(new File(source, child), new File(target, child), log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
in = new FileInputStream(source);
|
||||||
|
out = new FileOutputStream(target);
|
||||||
|
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = in.read(buf)) > 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user