< prev index next >

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

Print this page

 70         if (pathSep == -1) {
 71             // No trailing resource path. This can never "connect" or return a
 72             // resource (see JEP 220 for details).
 73             this.module = urlPath.substring(1);
 74             this.path = null;
 75         } else {
 76             this.module = urlPath.substring(1, pathSep);
 77             this.path = percentDecode(urlPath.substring(pathSep + 1));
 78         }
 79     }
 80 
 81     /**
 82      * Finds and caches the resource node associated with this URL and marks the
 83      * connection as "connected".
 84      */
 85     private synchronized Node connectResourceNode() throws IOException {
 86         if (resourceNode == null) {
 87             if (module.isEmpty() || path == null) {
 88                 throw new IOException("cannot connect to jrt:/" + module);
 89             }
 90             Node node = READER.findNode("/modules/" + module + "/" + path);
 91             if (node == null || !node.isResource()) {
 92                 throw new IOException(module + "/" + path + " not found");
 93             }
 94             this.resourceNode = node;
 95             super.connected = true;
 96         }
 97         return resourceNode;
 98     }
 99 
100     @Override
101     public void connect() throws IOException {
102         connectResourceNode();
103     }
104 
105     @Override
106     public InputStream getInputStream() throws IOException {
107         return new ByteArrayInputStream(READER.getResource(connectResourceNode()));
108     }
109 
110     @Override
111     public long getContentLengthLong() {

 70         if (pathSep == -1) {
 71             // No trailing resource path. This can never "connect" or return a
 72             // resource (see JEP 220 for details).
 73             this.module = urlPath.substring(1);
 74             this.path = null;
 75         } else {
 76             this.module = urlPath.substring(1, pathSep);
 77             this.path = percentDecode(urlPath.substring(pathSep + 1));
 78         }
 79     }
 80 
 81     /**
 82      * Finds and caches the resource node associated with this URL and marks the
 83      * connection as "connected".
 84      */
 85     private synchronized Node connectResourceNode() throws IOException {
 86         if (resourceNode == null) {
 87             if (module.isEmpty() || path == null) {
 88                 throw new IOException("cannot connect to jrt:/" + module);
 89             }
 90             Node node = READER.findResourceNode(module, path);
 91             if (node == null) {
 92                 throw new IOException(module + "/" + path + " not found");
 93             }
 94             this.resourceNode = node;
 95             super.connected = true;
 96         }
 97         return resourceNode;
 98     }
 99 
100     @Override
101     public void connect() throws IOException {
102         connectResourceNode();
103     }
104 
105     @Override
106     public InputStream getInputStream() throws IOException {
107         return new ByteArrayInputStream(READER.getResource(connectResourceNode()));
108     }
109 
110     @Override
111     public long getContentLengthLong() {
< prev index next >