FileDocCategorySizeDatePackage
JarURLConnection.javaAPI DocAndroid 1.5 API7216Wed May 06 22:41:04 BST 2009java.net

JarURLConnection

public abstract class JarURLConnection extends URLConnection
This class establishes a connection to a {@code jar:} URL using the {@code JAR} protocol. A {@code JarURLConnection} instance can refer to either a JAR archive file or to an entry of such a file. {@code 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: {@code jar:http://www.example.com/applets/archive.jar!/}
  • File Entry: {@code jar:http://www.example.com/applets/archive.jar!/test.class}
  • Directory Entry: {@code jar:http://www.example.com/applets/archive.jar!/applets/}
  • since
    Android 1.0

    Fields Summary
    protected URLConnection
    jarFileURLConnection
    The location part of the represented URL.
    private String
    entryName
    private URL
    fileURL
    private String
    file
    Constructors Summary
    protected JarURLConnection(URL url)
    Constructs an instance of {@code JarURLConnection} that refers to the specified URL.

    param
    url the URL that contains the location to connect to.
    throws
    MalformedURLException if an invalid URL has been entered.
    since
    Android 1.0

            super(url);
            file = url.getFile();
            int sepIdx;
            if ((sepIdx = file.indexOf("!/")) < 0) { //$NON-NLS-1$
                throw new MalformedURLException();
            }
            if (file.length() == sepIdx + 2) {
                return;
            }
            entryName = file.substring(sepIdx + 2, file.length());
            if (null != url.getRef()) {
                entryName += "#" + url.getRef(); //$NON-NLS-1$
            }
        
    Methods Summary
    public java.util.jar.AttributesgetAttributes()
    Returns all attributes of the {@code JarEntry} referenced by this {@code JarURLConnection}.

    return
    the attributes of the referenced {@code JarEntry}.
    exception
    IOException if an I/O exception occurs while retrieving the JAR-entries.
    since
    Android 1.0

            JarEntry jEntry = getJarEntry();
            return (jEntry == null) ? null : jEntry.getAttributes();
        
    public java.security.cert.Certificate[]getCertificates()
    Returns all certificates of the {@code JarEntry} referenced by this {@code JarURLConnection} instance. This method will return {@code null} until the {@code InputStream} has been completely verified.

    return
    the certificates of the {@code JarEntry} as an array.
    exception
    IOException if there is an I/O exception occurs while getting the {@code JarEntry}.
    since
    Android 1.0

            JarEntry jEntry = getJarEntry();
            if (jEntry == null) {
                return null;
            }
    
            return jEntry.getCertificates();
        
    public java.lang.StringgetEntryName()
    Gets the name of the entry referenced by this {@code JarURLConnection}. The return value will be {@code null} if this instance refers to a JAR file rather than an JAR file entry.

    return
    the {@code JarEntry} name this instance refers to.
    since
    Android 1.0

            return entryName;
        
    public java.util.jar.JarEntrygetJarEntry()
    Gets the {@code JarEntry} object of the entry referenced by this {@code JarURLConnection}.

    return
    the referenced {@code JarEntry} object or {@code null} if no entry name is specified.
    throws
    IOException if an error occurs while getting the file or file-entry.
    since
    Android 1.0

            if (!connected) {
                connect();
            }
            if (entryName == null) {
                return null;
            }
            // The entry must exist since the connect succeeded
            return getJarFile().getJarEntry(entryName);
        
    public abstract java.util.jar.JarFilegetJarFile()
    Gets the {@code JarFile} object referenced by this {@code JarURLConnection}.

    return
    the referenced JarFile object.
    exception
    IOException if an I/O exception occurs while retrieving the JAR-file.
    since
    Android 1.0

    public java.net.URLgetJarFileURL()
    Gets the URL to the JAR-file referenced by this {@code JarURLConnection}.

    return
    the URL to the JAR-file or {@code null} if there was an error retrieving the URL.
    since
    Android 1.0

            if (fileURL != null) {
                return fileURL;
            }
            try {
                return fileURL = new URL(url.getFile().substring(0,
                        url.getFile().indexOf("!/"))); //$NON-NLS-1$
            } catch (MalformedURLException e) {
                return null;
            }
        
    public java.util.jar.AttributesgetMainAttributes()
    Gets all attributes of the manifest file referenced by this {@code JarURLConnection}. If this instance refers to a JAR-file rather than a JAR-file entry, {@code null} will be returned.

    return
    the attributes of the manifest file or {@code null}.
    exception
    IOException if an I/O exception occurs while retrieving the {@code JarFile}.
    since
    Android 1.0

            Manifest m = getJarFile().getManifest();
            return (m == null) ? null : m.getMainAttributes();
        
    public java.util.jar.ManifestgetManifest()
    Gets the manifest file associated with this JAR-URL.

    return
    the manifest of the referenced JAR-file.
    throws
    IOException if an error occurs while getting the manifest file.
    since
    Android 1.0

            return getJarFile().getManifest();