mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-17 23:05:03 -05:00
* use NIO2 Files.move() on JRE7
This commit is contained in:
parent
4424fc4daa
commit
0f05b47109
@ -23,7 +23,6 @@ import java.util.Set;
|
|||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
import java.util.AbstractMap.SimpleEntry;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.CancellationException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -80,7 +79,7 @@ class RenameAction extends AbstractAction {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// could not rename one of the files, revert all changes
|
// 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());
|
window.setCursor(Cursor.getDefaultCursor());
|
||||||
@ -224,10 +223,8 @@ class RenameAction extends AbstractAction {
|
|||||||
protected void done() {
|
protected void done() {
|
||||||
try {
|
try {
|
||||||
get(); // check exceptions
|
get(); // check exceptions
|
||||||
} catch (CancellationException e) {
|
|
||||||
// ignore
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
UILogger.log(Level.SEVERE, e.getMessage(), e);
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect renamed types
|
// collect renamed types
|
||||||
|
@ -14,6 +14,7 @@ import java.io.Reader;
|
|||||||
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.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -45,14 +46,28 @@ public final class FileUtilities {
|
|||||||
throw new IOException("Failed to create folder: " + destinationFolder);
|
throw new IOException("Failed to create folder: " + destinationFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!source.renameTo(destination)) {
|
try {
|
||||||
throw new IOException("Failed to rename file: " + source.getName());
|
renameFileNIO2(source, destination);
|
||||||
|
} catch (LinkageError e) {
|
||||||
|
renameFileIO(source, destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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 {
|
public static byte[] readFile(File source) throws IOException {
|
||||||
InputStream in = new FileInputStream(source);
|
InputStream in = new FileInputStream(source);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user