< prev index next >

src/java.base/share/classes/sun/net/www/protocol/jar/JarURLConnection.java

Print this page
rev 13123 : 8132734: JDK 9 runtime changes to support multi-release jar files
Summary: JEP 238 Multi-Release JAR Files runtime support
Contributed-by: steve.drach@oracle.com
rev 12142 : 8081517: minor cleanup for docs
Summary: fix some tidy and javadoc warnings/errors
Reviewed-by: lancea, rriggs
rev 10469 : 8054834: Modular Source Code
Reviewed-by: alanb, chegar, ihse, mduigou
Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com


  59     /* the permission to get this JAR file. This is the actual, ultimate,
  60      * permission, returned by the jar file factory.
  61      */
  62     private Permission permission;
  63 
  64     /* the url connection for the JAR file */
  65     private URLConnection jarFileURLConnection;
  66 
  67     /* the entry name, if any */
  68     private String entryName;
  69 
  70     /* the JarEntry */
  71     private JarEntry jarEntry;
  72 
  73     /* the jar file corresponding to this connection */
  74     private JarFile jarFile;
  75 
  76     /* the content type for this connection */
  77     private String contentType;
  78 



  79     public JarURLConnection(URL url, Handler handler)
  80     throws MalformedURLException, IOException {
  81         super(url);
  82 
  83         jarFileURL = getJarFileURL();
  84         jarFileURLConnection = jarFileURL.openConnection();
  85         entryName = getEntryName();


  86     }
  87 
  88     public JarFile getJarFile() throws IOException {
  89         connect();
  90         return jarFile;
  91     }
  92 
  93     public JarEntry getJarEntry() throws IOException {
  94         connect();
  95         return jarEntry;
  96     }
  97 
  98     public Permission getPermission() throws IOException {
  99         return jarFileURLConnection.getPermission();
 100     }
 101 
 102     class JarURLInputStream extends java.io.FilterInputStream {
 103         JarURLInputStream (InputStream src) {
 104             super (src);
 105         }
 106         public void close () throws IOException {
 107             try {
 108                 super.close();
 109             } finally {
 110                 if (!getUseCaches()) {
 111                     jarFile.close();
 112                 }
 113             }
 114         }
 115     }
 116 
 117 
 118 
 119     public void connect() throws IOException {
 120         if (!connected) {
 121             /* the factory call will do the security checks */
 122             jarFile = factory.get(getJarFileURL(), getUseCaches());
 123 
 124             /* we also ask the factory the permission that was required
 125              * to get the jarFile, and set it as our permission.
 126              */
 127             if (getUseCaches()) {
 128                 jarFileURLConnection = factory.getConnection(jarFile);
 129             }
 130 
 131             if ((entryName != null)) {
 132                 jarEntry = (JarEntry)jarFile.getEntry(entryName);


 133                 if (jarEntry == null) {
 134                     try {
 135                         if (!getUseCaches()) {
 136                             jarFile.close();
 137                         }
 138                     } catch (Exception e) {
 139                     }
 140                     throw new FileNotFoundException("JAR entry " + entryName +
 141                                                     " not found in " +
 142                                                     jarFile.getName());
 143                 }
 144             }
 145             connected = true;
 146         }
 147     }
 148 
 149     public InputStream getInputStream() throws IOException {
 150         connect();
 151 
 152         InputStream result = null;




  59     /* the permission to get this JAR file. This is the actual, ultimate,
  60      * permission, returned by the jar file factory.
  61      */
  62     private Permission permission;
  63 
  64     /* the url connection for the JAR file */
  65     private URLConnection jarFileURLConnection;
  66 
  67     /* the entry name, if any */
  68     private String entryName;
  69 
  70     /* the JarEntry */
  71     private JarEntry jarEntry;
  72 
  73     /* the jar file corresponding to this connection */
  74     private JarFile jarFile;
  75 
  76     /* the content type for this connection */
  77     private String contentType;
  78 
  79     /* should multi-release jar runtime version processing be used */
  80     private boolean runtimeVersioned;
  81 
  82     public JarURLConnection(URL url, Handler handler)
  83     throws MalformedURLException, IOException {
  84         super(url);
  85 
  86         jarFileURL = getJarFileURL();
  87         jarFileURLConnection = jarFileURL.openConnection();
  88         entryName = getEntryName();
  89         String ref = url.getRef();
  90         runtimeVersioned = ref == null ? false : ref.equals("runtime");
  91     }
  92 
  93     public JarFile getJarFile() throws IOException {
  94         connect();
  95         return jarFile;
  96     }
  97 
  98     public JarEntry getJarEntry() throws IOException {
  99         connect();
 100         return jarEntry;
 101     }
 102 
 103     public Permission getPermission() throws IOException {
 104         return jarFileURLConnection.getPermission();
 105     }
 106 
 107     class JarURLInputStream extends java.io.FilterInputStream {
 108         JarURLInputStream (InputStream src) {
 109             super (src);
 110         }
 111         public void close () throws IOException {
 112             try {
 113                 super.close();
 114             } finally {
 115                 if (!getUseCaches()) {
 116                     jarFile.close();
 117                 }
 118             }
 119         }
 120     }
 121 


 122     public void connect() throws IOException {
 123         if (!connected) {
 124             /* the factory call will do the security checks */
 125             jarFile = factory.get(getJarFileURL(), getUseCaches());
 126 
 127             /* we also ask the factory the permission that was required
 128              * to get the jarFile, and set it as our permission.
 129              */
 130             if (getUseCaches()) {
 131                 jarFileURLConnection = factory.getConnection(jarFile);
 132             }
 133 
 134             if ((entryName != null)) {
 135                 jarEntry = runtimeVersioned
 136                         ? jarFile.getRuntimeVersionedEntry(entryName)
 137                         : (JarEntry)jarFile.getEntry(entryName);
 138                 if (jarEntry == null) {
 139                     try {
 140                         if (!getUseCaches()) {
 141                             jarFile.close();
 142                         }
 143                     } catch (Exception e) {
 144                     }
 145                     throw new FileNotFoundException("JAR entry " + entryName +
 146                                                     " not found in " +
 147                                                     jarFile.getName());
 148                 }
 149             }
 150             connected = true;
 151         }
 152     }
 153 
 154     public InputStream getInputStream() throws IOException {
 155         connect();
 156 
 157         InputStream result = null;


< prev index next >