Skip to content

Commit

Permalink
Fix issue with reading resources containing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Apr 28, 2020
1 parent b914d58 commit abf245c
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystem;
Expand Down Expand Up @@ -174,7 +175,13 @@ public static void consumeStream(URL url, Consumer<InputStream> consumer) throws
*/
public static <R> R readStream(URL url, Function<InputStream, R> function) throws IOException {
if (JAR.equals(url.getProtocol())) {
final String file = url.getFile();
final URI uri;
try {
uri = new URI(url.toString());
} catch (URISyntaxException e) {
throw new IOException(e);
}
final String file = uri.getSchemeSpecificPart();
final int exclam = file.lastIndexOf('!');
final Path jar = toLocalPath(exclam >= 0 ? new URL(file.substring(0, exclam)) : url);
try (FileSystem jarFs = FileSystems.newFileSystem(jar, (ClassLoader) null)) {
Expand Down

0 comments on commit abf245c

Please sign in to comment.