mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 02:25:41 +01:00
Now using apache commons for file operations. Hopefully we will get more success with deleting and copying stuff. May fix Inventories test failures.
This commit is contained in:
parent
2b827a1fae
commit
72a14719ac
28
pom.xml
28
pom.xml
@ -220,12 +220,40 @@
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>apache-commons-io</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>org.apache.commons:commons-io</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.apache.commons</pattern>
|
||||
<shadedPattern>org.apache.commons.multiverse</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Bukkit Dependency -->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
|
@ -7,13 +7,10 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -31,16 +28,11 @@ public class FileUtils {
|
||||
* @return true if the folder was successfully deleted.
|
||||
*/
|
||||
public static boolean deleteFolder(File file) {
|
||||
if (file.exists()) {
|
||||
boolean ret = true;
|
||||
// If the file exists, and it has more than one file in it.
|
||||
if (file.isDirectory()) {
|
||||
for (File f : file.listFiles()) {
|
||||
ret = ret && deleteFolder(f);
|
||||
}
|
||||
}
|
||||
return ret && file.delete();
|
||||
} else {
|
||||
try {
|
||||
org.apache.commons.io.FileUtils.deleteDirectory(file);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Logging.warning(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -52,16 +44,11 @@ public class FileUtils {
|
||||
* @return true if the contents were successfully deleted
|
||||
*/
|
||||
public static boolean deleteFolderContents(File file) {
|
||||
if (file.exists()) {
|
||||
boolean ret = true;
|
||||
// If the file exists, and it has more than one file in it.
|
||||
if (file.isDirectory()) {
|
||||
for (File f : file.listFiles()) {
|
||||
ret = ret && deleteFolder(f);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
try {
|
||||
org.apache.commons.io.FileUtils.cleanDirectory(file);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Logging.warning(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -77,46 +64,12 @@ public class FileUtils {
|
||||
* @return 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[COPY_BLOCK_SIZE];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
}
|
||||
org.apache.commons.io.FileUtils.copyDirectory(source, target);
|
||||
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) { }
|
||||
}
|
||||
log.warning(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user