diff --git a/source/net/filebot/gio/PlatformGVFS.java b/source/net/filebot/gio/PlatformGVFS.java index 11490d86..0401b05b 100644 --- a/source/net/filebot/gio/PlatformGVFS.java +++ b/source/net/filebot/gio/PlatformGVFS.java @@ -1,8 +1,12 @@ package net.filebot.gio; +import static java.util.Arrays.*; +import static java.util.stream.Collectors.*; + import java.io.File; import java.net.URI; +import java.util.List; public class PlatformGVFS implements GVFS { @@ -13,7 +17,7 @@ public class PlatformGVFS implements GVFS { } public File getPathForURI(URI uri) { - return Protocol.valueOf(uri.getScheme().toUpperCase()).getFile(gvfs, uri); + return Protocol.forName(uri.getScheme()).getFile(gvfs, uri); } public static enum Protocol { @@ -82,6 +86,20 @@ public class PlatformGVFS implements GVFS { return new File(gvfs, getPath(uri)); } + public static List names() { + return stream(values()).map(Enum::name).collect(toList()); + } + + public static Protocol forName(String name) { + for (Protocol protocol : values()) { + if (protocol.name().equalsIgnoreCase(name)) { + return protocol; + } + } + + throw new IllegalArgumentException(String.format("%s not in %s", name, names())); + } + } } diff --git a/source/net/filebot/ui/transfer/FileTransferable.java b/source/net/filebot/ui/transfer/FileTransferable.java index 5078c68d..4442608c 100644 --- a/source/net/filebot/ui/transfer/FileTransferable.java +++ b/source/net/filebot/ui/transfer/FileTransferable.java @@ -92,20 +92,21 @@ public class FileTransferable implements Transferable { if (useGVFS()) { if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) { // file URI list flavor (Linux) - try { - Readable transferData = (Readable) tr.getTransferData(FileTransferable.uriListFlavor); - try (Scanner scanner = new Scanner(transferData)) { - List files = new ArrayList(); + Readable transferData = (Readable) tr.getTransferData(FileTransferable.uriListFlavor); - while (scanner.hasNextLine()) { - String line = scanner.nextLine(); + try (Scanner scanner = new Scanner(transferData)) { + List files = new ArrayList(); - if (line.startsWith("#")) { - // the line is a comment (as per RFC 2483) - continue; - } + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (line.startsWith("#")) { + // the line is a comment (as per RFC 2483) + continue; + } + + try { File file = GVFS.getDefaultVFS().getPathForURI(new URI(line)); if (file != null && file.exists()) { @@ -113,13 +114,12 @@ public class FileTransferable implements Transferable { } else { debug.warning(format("GVFS: %s => %s", line, file)); } - + } catch (Throwable e) { + debug.warning(format("GVFS: %s => %s", line, e)); } - - return files; } - } catch (Throwable e) { - debug.warning(cause(e)); + + return files; } } }