1 17 package org.apache.geronimo.kernel.classloader; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.net.JarURLConnection ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.net.URLConnection ; 26 import java.net.URLStreamHandler ; 27 import java.security.Permission ; 28 import java.security.cert.Certificate ; 29 import java.util.jar.Attributes ; 30 import java.util.jar.JarEntry ; 31 import java.util.jar.JarFile ; 32 import java.util.jar.Manifest ; 33 34 37 public class JarFileUrlConnection extends JarURLConnection { 38 public static final URL DUMMY_JAR_URL; 39 static { 40 try { 41 DUMMY_JAR_URL = new URL ("jar", "", -1, "file:dummy!/", new URLStreamHandler () { 42 protected URLConnection openConnection(URL u) { 43 throw new UnsupportedOperationException (); 44 } 45 }); 46 } catch (Exception e) { 47 throw new ExceptionInInitializerError (e); 48 } 49 } 50 51 private final URL url; 52 private final JarFile jarFile; 53 private final JarEntry jarEntry; 54 private final URL jarFileUrl; 55 56 public JarFileUrlConnection(URL url, JarFile jarFile, JarEntry jarEntry) throws MalformedURLException { 57 super(DUMMY_JAR_URL); 58 59 if (url == null) throw new NullPointerException ("url is null"); 60 if (jarFile == null) throw new NullPointerException ("jarFile is null"); 61 if (jarEntry == null) throw new NullPointerException ("jarEntry is null"); 62 63 this.url = url; 64 this.jarFile = jarFile; 65 this.jarEntry = jarEntry; 66 jarFileUrl = new File (jarFile.getName()).toURL(); 67 } 68 69 public JarFile getJarFile() throws IOException { 70 return jarFile; 71 } 72 73 public synchronized void connect() { 74 } 75 76 public URL getJarFileURL() { 77 return jarFileUrl; 78 } 79 80 public String getEntryName() { 81 return getJarEntry().getName(); 82 } 83 84 public Manifest getManifest() throws IOException { 85 return jarFile.getManifest(); 86 } 87 88 public JarEntry getJarEntry() { 89 return jarEntry; 90 } 91 92 public Attributes getAttributes() throws IOException { 93 return getJarEntry().getAttributes(); 94 } 95 96 public Attributes getMainAttributes() throws IOException { 97 return getManifest().getMainAttributes(); 98 } 99 100 public Certificate [] getCertificates() throws IOException { 101 return getJarEntry().getCertificates(); 102 } 103 104 public URL getURL() { 105 return url; 106 } 107 108 public int getContentLength() { 109 long size = getJarEntry().getSize(); 110 if (size > Integer.MAX_VALUE) { 111 return -1; 112 } 113 return (int) size; 114 } 115 116 public long getLastModified() { 117 return getJarEntry().getTime(); 118 } 119 120 public synchronized InputStream getInputStream() throws IOException { 121 return jarFile.getInputStream(jarEntry); 122 } 123 124 public Permission getPermission() throws IOException { 125 URL jarFileUrl = new File (jarFile.getName()).toURL(); 126 return jarFileUrl.openConnection().getPermission(); 127 } 128 129 public String toString() { 130 return JarFileUrlConnection.class.getName() + ":" + url; 131 } 132 } 133 | Popular Tags |