* remove some Java 6 compatibility hacks
This commit is contained in:
parent
33ca22c1bb
commit
89c1744fd3
|
@ -14,6 +14,7 @@ import java.io.StringWriter;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.AtomicMoveNotSupportedException;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -50,21 +51,11 @@ public final class FileUtilities {
|
||||||
// move folder
|
// move folder
|
||||||
org.apache.commons.io.FileUtils.moveDirectory(source, destination);
|
org.apache.commons.io.FileUtils.moveDirectory(source, destination);
|
||||||
} else {
|
} else {
|
||||||
// move file
|
// on Windows ATOMIC_MOVE allows us to rename files even if only lower/upper-case changes (without ATOMIC_MOVE the operation would be ignored)
|
||||||
try {
|
try {
|
||||||
// * On Windows ATOMIC_MOVE allows us to rename files even if only lower/upper-case changes (without ATOMIC_MOVE the operation would be ignored)
|
java.nio.file.Files.move(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
|
||||||
try {
|
} catch (AtomicMoveNotSupportedException e) {
|
||||||
java.nio.file.Files.move(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
|
java.nio.file.Files.move(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
} catch (IOException e) {
|
|
||||||
// HACK to keep things working on Java 6
|
|
||||||
if (e.getClass().getName().contains("AtomicMoveNotSupported")) {
|
|
||||||
java.nio.file.Files.move(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (LinkageError e) {
|
|
||||||
org.apache.commons.io.FileUtils.moveFile(source, destination); // use "copy and delete" as fallback if standard rename fails
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,11 +71,7 @@ public final class FileUtilities {
|
||||||
org.apache.commons.io.FileUtils.copyDirectory(source, destination);
|
org.apache.commons.io.FileUtils.copyDirectory(source, destination);
|
||||||
} else {
|
} else {
|
||||||
// copy file
|
// copy file
|
||||||
try {
|
java.nio.file.Files.copy(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
java.nio.file.Files.copy(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
} catch (LinkageError e) {
|
|
||||||
org.apache.commons.io.FileUtils.copyFile(source, destination);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return destination;
|
return destination;
|
||||||
|
|
Loading…
Reference in New Issue