From ee84ce09d77acb59700cd27c43b17661105dfcad Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Tue, 7 Feb 2017 11:42:27 -0600 Subject: [PATCH] Allow openFileURLStream(URL) to open jars This is related to #23020. There are some cases for where this method might be called with a URL to a file inside a jar. This commit allows this method to read URLs with a protocol of 'jar:/'. --- .../java/org/elasticsearch/common/io/FileSystemUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java b/core/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java index dc7e902fb60..3aefc58177a 100644 --- a/core/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java +++ b/core/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java @@ -117,12 +117,12 @@ public final class FileSystemUtils { } /** - * Returns an InputStream the given url if the url has a protocol of 'file', no host, and no port. + * Returns an InputStream the given url if the url has a protocol of 'file' or 'jar', no host, and no port. */ public static InputStream openFileURLStream(URL url) throws IOException { String protocol = url.getProtocol(); - if ("file".equals(protocol) == false) { - throw new IllegalArgumentException("Invalid protocol [" + protocol + "], must be [file]"); + if ("file".equals(protocol) == false && "jar".equals(protocol) == false) { + throw new IllegalArgumentException("Invalid protocol [" + protocol + "], must be [file] or [jar]"); } if (Strings.isEmpty(url.getHost()) == false) { throw new IllegalArgumentException("URL cannot have host. Found: [" + url.getHost() + ']');