< prev index next >

src/java.base/share/classes/sun/net/www/protocol/jrt/JavaRuntimeURLConnection.java

Print this page
@@ -32,11 +32,11 @@
  import java.net.MalformedURLException;
  import java.net.URL;
  
  import jdk.internal.jimage.ImageReader;
  import jdk.internal.jimage.ImageReader.Node;
- import jdk.internal.jimage.ImageReaderFactory;
+ import jdk.internal.jimage.SystemImageReader;
  
  import sun.net.www.ParseUtil;
  import sun.net.www.URLConnection;
  
  /**

@@ -46,11 +46,11 @@
   * JEP 220</a>.
   */
  public class JavaRuntimeURLConnection extends URLConnection {
  
      // ImageReader to access resources in jimage.
-     private static final ImageReader READER = ImageReaderFactory.getImageReader();
+     private static final ImageReader READER = SystemImageReader.get();
  
      // The module and resource name in the URL (i.e. "jrt:/[$MODULE[/$PATH]]").
      //
      // The module name is not percent-decoded, and can be empty.
      private final String module;

@@ -107,13 +107,15 @@
          return new ByteArrayInputStream(READER.getResource(connectResourceNode()));
      }
  
      @Override
      public long getContentLengthLong() {
+         // Note: UncheckedIOException is thrown by the Node subclass in
+         // ExplodedImage (this not obvious, so worth calling out).
          try {
              return connectResourceNode().size();
-         } catch (IOException ioe) {
+         } catch (IOException | UncheckedIOException ioe) {
              return -1L;
          }
      }
  
      @Override

@@ -122,10 +124,14 @@
          return len > Integer.MAX_VALUE ? -1 : (int)len;
      }
  
      // Perform percent decoding of the resource name/path from the URL.
      private static String percentDecode(String path) throws MalformedURLException {
+         if (path.indexOf('%') == -1) {
+             // Nothing to decode (overwhelmingly common case).
+             return path;
+         }
          // Any additional special case decoding logic should go here.
          try {
              return ParseUtil.decode(path);
          } catch (IllegalArgumentException e) {
              throw new MalformedURLException(e.getMessage());
< prev index next >