Improved GVFS error logging: GVFS: %s => %s

This commit is contained in:
Reinhard Pointner 2017-02-25 22:43:31 +08:00
parent b1ade214bc
commit 9f5867f295
2 changed files with 34 additions and 16 deletions

View File

@ -1,8 +1,12 @@
package net.filebot.gio; package net.filebot.gio;
import static java.util.Arrays.*;
import static java.util.stream.Collectors.*;
import java.io.File; import java.io.File;
import java.net.URI; import java.net.URI;
import java.util.List;
public class PlatformGVFS implements GVFS { public class PlatformGVFS implements GVFS {
@ -13,7 +17,7 @@ public class PlatformGVFS implements GVFS {
} }
public File getPathForURI(URI uri) { 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 { public static enum Protocol {
@ -82,6 +86,20 @@ public class PlatformGVFS implements GVFS {
return new File(gvfs, getPath(uri)); return new File(gvfs, getPath(uri));
} }
public static List<String> 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()));
}
} }
} }

View File

@ -92,20 +92,21 @@ public class FileTransferable implements Transferable {
if (useGVFS()) { if (useGVFS()) {
if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) { if (tr.isDataFlavorSupported(FileTransferable.uriListFlavor)) {
// file URI list flavor (Linux) // file URI list flavor (Linux)
try {
Readable transferData = (Readable) tr.getTransferData(FileTransferable.uriListFlavor);
try (Scanner scanner = new Scanner(transferData)) { Readable transferData = (Readable) tr.getTransferData(FileTransferable.uriListFlavor);
List<File> files = new ArrayList<File>();
while (scanner.hasNextLine()) { try (Scanner scanner = new Scanner(transferData)) {
String line = scanner.nextLine(); List<File> files = new ArrayList<File>();
if (line.startsWith("#")) { while (scanner.hasNextLine()) {
// the line is a comment (as per RFC 2483) String line = scanner.nextLine();
continue;
}
if (line.startsWith("#")) {
// the line is a comment (as per RFC 2483)
continue;
}
try {
File file = GVFS.getDefaultVFS().getPathForURI(new URI(line)); File file = GVFS.getDefaultVFS().getPathForURI(new URI(line));
if (file != null && file.exists()) { if (file != null && file.exists()) {
@ -113,13 +114,12 @@ public class FileTransferable implements Transferable {
} else { } else {
debug.warning(format("GVFS: %s => %s", line, file)); 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;
} }
} }
} }