From f9c92088503b6a24a270a74f13db0dceb3cfd9a2 Mon Sep 17 00:00:00 2001 From: LexManos Date: Mon, 8 Jan 2024 12:06:21 -0800 Subject: [PATCH] More URL normalization and better error messages. --- .../nio/pathfs/PathFileSystemProvider.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/filesystems/src/main/java/net/minecraftforge/jarjar/nio/pathfs/PathFileSystemProvider.java b/filesystems/src/main/java/net/minecraftforge/jarjar/nio/pathfs/PathFileSystemProvider.java index f75f16d..d9ce531 100644 --- a/filesystems/src/main/java/net/minecraftforge/jarjar/nio/pathfs/PathFileSystemProvider.java +++ b/filesystems/src/main/java/net/minecraftforge/jarjar/nio/pathfs/PathFileSystemProvider.java @@ -14,7 +14,10 @@ import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileAttributeView; import java.nio.file.spi.FileSystemProvider; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -120,10 +123,23 @@ public Path getPath(final URI uri) { } @Override - public FileSystem getFileSystem(final URI uri) { - final String[] parts = uri.getRawSchemeSpecificPart().split(COMPONENT_SEPERATOR); - if (!fileSystems.containsKey(parts[0])) throw new FileSystemNotFoundException(); - return fileSystems.get(parts[0]); + public FileSystem getFileSystem(URI uri) { + String key = makeKey(uri); + String owner = key.split(COMPONENT_SEPERATOR)[0]; + FileSystem fs = fileSystems.get(owner); + + if (fs == null) { + StringBuilder buf = new StringBuilder(); + buf.append("Unknown FileSystem: ").append(uri); + buf.append('\n').append("\tOwner: ").append(owner); + List sorted = new ArrayList<>(fileSystems.keySet()); + Collections.sort(sorted); + for (String known : sorted) + buf.append('\n').append("\tKnown: ").append(known); + throw new FileSystemNotFoundException(buf.toString()); + } + + return fs; } @Override