* use NIO2 Files.move() on JRE7

This commit is contained in:
Reinhard Pointner 2011-11-20 21:32:24 +00:00
parent 4424fc4daa
commit 0f05b47109
2 changed files with 19 additions and 7 deletions

View File

@ -23,7 +23,6 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
@ -80,7 +79,7 @@ class RenameAction extends AbstractAction {
}
} catch (Exception e) {
// could not rename one of the files, revert all changes
UILogger.warning(e.getMessage());
UILogger.log(Level.WARNING, e.getMessage(), e);
}
window.setCursor(Cursor.getDefaultCursor());
@ -224,10 +223,8 @@ class RenameAction extends AbstractAction {
protected void done() {
try {
get(); // check exceptions
} catch (CancellationException e) {
// ignore
} catch (Exception e) {
UILogger.log(Level.SEVERE, e.getMessage(), e);
// ignore
}
// collect renamed types

View File

@ -14,6 +14,7 @@ import java.io.Reader;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@ -45,14 +46,28 @@ public final class FileUtilities {
throw new IOException("Failed to create folder: " + destinationFolder);
}
if (!source.renameTo(destination)) {
throw new IOException("Failed to rename file: " + source.getName());
try {
renameFileNIO2(source, destination);
} catch (LinkageError e) {
renameFileIO(source, destination);
}
return destination;
}
private static void renameFileNIO2(File source, File destination) throws IOException {
Files.move(source.toPath(), destination.toPath());
}
private static void renameFileIO(File source, File destination) throws IOException {
if (!source.renameTo(destination)) {
throw new IOException("Failed to rename file: " + source.getName());
}
}
public static byte[] readFile(File source) throws IOException {
InputStream in = new FileInputStream(source);