Package java.net

Class JarURLConnection

java.lang.Object
java.net.URLConnection
java.net.JarURLConnection
Direct Known Subclasses:
JarURLConnectionImpl

public abstract class JarURLConnection
extends URLConnection
This class establishes a connection to a jar: URL using the JAR protocol. A JarURLConnection instance can refer to either a JAR archive file or to an entry of such a file. jar: URLs are specified as follows: jar:{archive-url}!/{entry} where "!/" is called a separator. This separator is important to determine if an archive or an entry of an archive is referred.

Examples:

  • Archive: jar:http://www.example.com/applets/archive.jar!/
  • File Entry: jar:http://www.example.com/applets/archive.jar!/test.class
  • Directory Entry: jar:http://www.example.com/applets/archive.jar!/applets/
    • Field Details

      • jarFileURLConnection

        protected URLConnection jarFileURLConnection
        The location part of the represented URL.
    • Constructor Details

      • JarURLConnection

        protected JarURLConnection​(URL url) throws MalformedURLException
        Constructs an instance of JarURLConnection that refers to the specified URL.
        Parameters:
        url - the URL that contains the location to connect to.
        Throws:
        MalformedURLException - if an invalid URL has been entered.
    • Method Details

      • getAttributes

        public Attributes getAttributes() throws IOException
        Returns all attributes of the JarEntry referenced by this JarURLConnection.
        Returns:
        the attributes of the referenced JarEntry.
        Throws:
        IOException - if an I/O exception occurs while retrieving the JAR-entries.
      • getCertificates

        public Certificate[] getCertificates() throws IOException
        Returns all certificates of the JarEntry referenced by this JarURLConnection instance. This method will return null until the InputStream has been completely verified.
        Returns:
        the certificates of the JarEntry as an array.
        Throws:
        IOException - if there is an I/O exception occurs while getting the JarEntry.
      • getEntryName

        public String getEntryName()
        Gets the name of the entry referenced by this JarURLConnection. The return value will be null if this instance refers to a JAR file rather than an JAR file entry.
        Returns:
        the JarEntry name this instance refers to.
      • getJarEntry

        public JarEntry getJarEntry() throws IOException
        Gets the JarEntry object of the entry referenced by this JarURLConnection.
        Returns:
        the referenced JarEntry object or null if no entry name is specified.
        Throws:
        IOException - if an error occurs while getting the file or file-entry.
      • getManifest

        public Manifest getManifest() throws IOException
        Gets the manifest file associated with this JAR-URL.
        Returns:
        the manifest of the referenced JAR-file.
        Throws:
        IOException - if an error occurs while getting the manifest file.
      • getJarFile

        public abstract JarFile getJarFile() throws IOException
        Gets the JarFile object referenced by this JarURLConnection.
        Returns:
        the referenced JarFile object.
        Throws:
        IOException - if an I/O exception occurs while retrieving the JAR-file.
      • getJarFileURL

        public URL getJarFileURL()
        Gets the URL to the JAR-file referenced by this JarURLConnection.
        Returns:
        the URL to the JAR-file or null if there was an error retrieving the URL.
      • getMainAttributes

        public Attributes getMainAttributes() throws IOException
        Gets all attributes of the manifest file referenced by this JarURLConnection. If this instance refers to a JAR-file rather than a JAR-file entry, null will be returned.
        Returns:
        the attributes of the manifest file or null.
        Throws:
        IOException - if an I/O exception occurs while retrieving the JarFile.