< prev index next >

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

Print this page
rev 51919 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: dfuchs, alanb


  49  */
  50 public class JavaRuntimeURLConnection extends URLConnection {
  51 
  52     // ImageReader to access resources in jimage
  53     private static final ImageReader reader;
  54     static {
  55         PrivilegedAction<ImageReader> pa = ImageReaderFactory::getImageReader;
  56         reader = AccessController.doPrivileged(pa);
  57     }
  58 
  59     // the module and resource name in the URL
  60     private final String module;
  61     private final String name;
  62 
  63     // the Resource when connected
  64     private volatile Resource resource;
  65 
  66     JavaRuntimeURLConnection(URL url) throws IOException {
  67         super(url);
  68         String path = url.getPath();
  69         if (path.length() == 0 || path.charAt(0) != '/')
  70             throw new MalformedURLException(url + " missing path or /");
  71         if (path.length() == 1) {
  72             this.module = null;
  73             this.name = null;
  74         } else {
  75             int pos = path.indexOf('/', 1);
  76             if (pos == -1) {
  77                 this.module = path.substring(1);
  78                 this.name = null;
  79             } else {
  80                 this.module = path.substring(1, pos);
  81                 this.name = ParseUtil.decode(path.substring(pos+1));
  82             }
  83         }
  84     }
  85 
  86     /**
  87      * Finds a resource in a module, returning {@code null} if the resource
  88      * is not found.
  89      */




  49  */
  50 public class JavaRuntimeURLConnection extends URLConnection {
  51 
  52     // ImageReader to access resources in jimage
  53     private static final ImageReader reader;
  54     static {
  55         PrivilegedAction<ImageReader> pa = ImageReaderFactory::getImageReader;
  56         reader = AccessController.doPrivileged(pa);
  57     }
  58 
  59     // the module and resource name in the URL
  60     private final String module;
  61     private final String name;
  62 
  63     // the Resource when connected
  64     private volatile Resource resource;
  65 
  66     JavaRuntimeURLConnection(URL url) throws IOException {
  67         super(url);
  68         String path = url.getPath();
  69         if (path.isEmpty() || path.charAt(0) != '/')
  70             throw new MalformedURLException(url + " missing path or /");
  71         if (path.length() == 1) {
  72             this.module = null;
  73             this.name = null;
  74         } else {
  75             int pos = path.indexOf('/', 1);
  76             if (pos == -1) {
  77                 this.module = path.substring(1);
  78                 this.name = null;
  79             } else {
  80                 this.module = path.substring(1, pos);
  81                 this.name = ParseUtil.decode(path.substring(pos+1));
  82             }
  83         }
  84     }
  85 
  86     /**
  87      * Finds a resource in a module, returning {@code null} if the resource
  88      * is not found.
  89      */


< prev index next >