Team LiB
Previous Section Next Section

JarURLConnectionjava.net

Java 1.2

This class is a specialized URLConnection that represents a connection to a jar: URL. A jar: URL is a compound URL that includes the URL of a JAR archive and, optionally, a reference to a file or directory within the JAR archive. The jar: URL syntax uses the ! character to separate the pathname of the JAR archive from the filename within the JAR archive. Note that a jar: URL contains a subprotocol that specifies the protocol that retrieves the JAR file itself. For example:

jar:http://my.jar.com/my.jar!/       // The whole archive
jar:file:/usr/java/lib/my.jar!/com/jar/          // A directory of the archive
jar:ftp://ftp.jar.com/pub/my.jar!/com/jar/Jar.class // A file in the archive

To obtain a JarURLConnection, define a URL object for a jar: URL, open a connection to it with openConnection( ), and cast the returned URLConnection object to a JarURLConnection. The various methods defined by JarURLConnection allow you to read the manifest file of the JAR archive and look up attributes from that manifest for the archive as a whole or for individual entries in the archive. These methods make use of various classes from the java.util.jar package.

Figure 12-10. java.net.JarURLConnection


public abstract class JarURLConnection extends URLConnection {
// Protected Constructors
     protected JarURLConnection(URL url) throws MalformedURLException;  
// Public Instance Methods
     public java.util.jar.Attributes getAttributes( ) throws java.io.IOException;  
     public java.security.cert.Certificate[ ] getCertificates( ) 
throws java.io.IOException;  
     public String getEntryName( );  
     public java.util.jar.JarEntry getJarEntry( ) throws java.io.IOException;  
     public abstract java.util.jar.JarFile getJarFile( ) 
throws java.io.IOException;  
     public URL getJarFileURL( );  
     public java.util.jar.Attributes getMainAttributes( ) 
throws java.io.IOException;  
     public java.util.jar.Manifest getManifest( ) throws java.io.IOException;  
// Protected Instance Fields
     protected URLConnection jarFileURLConnection;  
}

    Team LiB
    Previous Section Next Section