< prev index next >

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

Print this page




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.www.protocol.jrt;
  27 
  28 import java.io.ByteArrayInputStream;
  29 import java.io.File;
  30 import java.io.FilePermission;
  31 import java.io.IOException;
  32 import java.io.InputStream;
  33 import java.net.MalformedURLException;
  34 import java.net.URL;

  35 import java.security.Permission;

  36 
  37 import jdk.internal.jimage.ImageLocation;
  38 import jdk.internal.jimage.ImageReader;
  39 import jdk.internal.jimage.ImageReaderFactory;
  40 
  41 import jdk.internal.loader.URLClassPath;
  42 import jdk.internal.loader.Resource;
  43 import sun.net.www.ParseUtil;
  44 import sun.net.www.URLConnection;
  45 import sun.security.action.GetPropertyAction;
  46 
  47 /**
  48  * URLConnection implementation that can be used to connect to resources
  49  * contained in the runtime image.
  50  */
  51 public class JavaRuntimeURLConnection extends URLConnection {
  52 
  53     // ImageReader to access resources in jimage
  54     private static final ImageReader reader = ImageReaderFactory.getImageReader();




  55 
  56     // the module and resource name in the URL
  57     private final String module;
  58     private final String name;
  59 
  60     // the Resource when connected
  61     private volatile Resource resource;
  62 
  63     // the permission to access resources in the runtime image, created lazily
  64     private static volatile Permission permission;
  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 {




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.net.www.protocol.jrt;
  27 
  28 import java.io.ByteArrayInputStream;
  29 import java.io.File;
  30 import java.io.FilePermission;
  31 import java.io.IOException;
  32 import java.io.InputStream;
  33 import java.net.MalformedURLException;
  34 import java.net.URL;
  35 import java.security.AccessController;
  36 import java.security.Permission;
  37 import java.security.PrivilegedAction;
  38 
  39 import jdk.internal.jimage.ImageLocation;
  40 import jdk.internal.jimage.ImageReader;
  41 import jdk.internal.jimage.ImageReaderFactory;
  42 
  43 import jdk.internal.loader.URLClassPath;
  44 import jdk.internal.loader.Resource;
  45 import sun.net.www.ParseUtil;
  46 import sun.net.www.URLConnection;
  47 import sun.security.action.GetPropertyAction;
  48 
  49 /**
  50  * URLConnection implementation that can be used to connect to resources
  51  * contained in the runtime image.
  52  */
  53 public class JavaRuntimeURLConnection extends URLConnection {
  54 
  55     // ImageReader to access resources in jimage
  56     private static final ImageReader reader;
  57     static {
  58         PrivilegedAction<ImageReader> pa = ImageReaderFactory::getImageReader;
  59         reader = AccessController.doPrivileged(pa);
  60     }
  61 
  62     // the module and resource name in the URL
  63     private final String module;
  64     private final String name;
  65 
  66     // the Resource when connected
  67     private volatile Resource resource;
  68 
  69     // the permission to access resources in the runtime image, created lazily
  70     private static volatile Permission permission;
  71 
  72     JavaRuntimeURLConnection(URL url) throws IOException {
  73         super(url);
  74         String path = url.getPath();
  75         if (path.length() == 0 || path.charAt(0) != '/')
  76             throw new MalformedURLException(url + " missing path or /");
  77         if (path.length() == 1) {
  78             this.module = null;
  79             this.name = null;
  80         } else {


< prev index next >