java.net
Class JarURLConnection

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.net.URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection 
      extended by java.net.JarURLConnection

public abstract class JarURLConnection
extends URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection

A URL Connection to a Java ARchive (JAR) file or an entry in a JAR file.

The syntax of a JAR URL is:

 jar:<url>!/{entry}
 

for example:

jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class

Jar URLs should be used to refer to a JAR file or entries in a JAR file. The example above is a JAR URL which refers to a JAR entry. If the entry name is omitted, the URL refers to the whole JAR file: jar:http://www.foo.com/bar/baz.jar!/

Users should cast the generic URLConnection to a JarURLConnection when they know that the URL they created is a JAR URL, and they need JAR-specific functionality. For example:

 URL url = new URL("jar:file:/home/duke/duke.jar!/");
 JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
 Manifest manifest = jarConnection.getManifest();
 

JarURLConnection instances can only be used to read from JAR files. It is not possible to get a OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream to modify or write to the underlying JAR file using this class.

Examples:

A Jar entry
jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class
A Jar file
jar:http://www.foo.com/bar/baz.jar!/
A Jar directory
jar:http://www.foo.com/bar/baz.jar!/COM/foo/

!/ is refered to as the separator.

When constructing a JAR url via new URL(context, spec), the following rules apply:

Since:
1.2
See Also:
URL sample code for java.net.URL definition code for java.net.URL , URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection , JarFile sample code for java.util.jar.JarFile definition code for java.util.jar.JarFile , JarInputStream sample code for java.util.jar.JarInputStream definition code for java.util.jar.JarInputStream , Manifest sample code for java.util.jar.Manifest definition code for java.util.jar.Manifest , ZipEntry sample code for java.util.zip.ZipEntry definition code for java.util.zip.ZipEntry

Field Summary
protected  URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection jarFileURLConnection sample code for java.net.JarURLConnection.jarFileURLConnection definition code for java.net.JarURLConnection.jarFileURLConnection
          The connection to the JAR file URL, if the connection has been initiated.
 
Fields inherited from class java.net.URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection
allowUserInteraction sample code for java.net.URLConnection.allowUserInteraction definition code for java.net.URLConnection.allowUserInteraction , connected sample code for java.net.URLConnection.connected definition code for java.net.URLConnection.connected , doInput sample code for java.net.URLConnection.doInput definition code for java.net.URLConnection.doInput , doOutput sample code for java.net.URLConnection.doOutput definition code for java.net.URLConnection.doOutput , ifModifiedSince sample code for java.net.URLConnection.ifModifiedSince definition code for java.net.URLConnection.ifModifiedSince , url sample code for java.net.URLConnection.url definition code for java.net.URLConnection.url , useCaches sample code for java.net.URLConnection.useCaches definition code for java.net.URLConnection.useCaches
 
Constructor Summary
protected JarURLConnection sample code for java.net.JarURLConnection.JarURLConnection(java.net.URL) definition code for java.net.JarURLConnection.JarURLConnection(java.net.URL) (URL sample code for java.net.URL definition code for java.net.URL  url)
          Creates the new JarURLConnection to the specified URL.
 
Method Summary
 Attributes sample code for java.util.jar.Attributes definition code for java.util.jar.Attributes getAttributes sample code for java.net.JarURLConnection.getAttributes() definition code for java.net.JarURLConnection.getAttributes() ()
          Return the Attributes object for this connection if the URL for it points to a JAR file entry, null otherwise.
 Certificate sample code for java.security.cert.Certificate definition code for java.security.cert.Certificate [] getCertificates sample code for java.net.JarURLConnection.getCertificates() definition code for java.net.JarURLConnection.getCertificates() ()
          Return the Certificate object for this connection if the URL for it points to a JAR file entry, null otherwise.
 String sample code for java.lang.String definition code for java.lang.String getEntryName sample code for java.net.JarURLConnection.getEntryName() definition code for java.net.JarURLConnection.getEntryName() ()
          Return the entry name for this connection.
 JarEntry sample code for java.util.jar.JarEntry definition code for java.util.jar.JarEntry getJarEntry sample code for java.net.JarURLConnection.getJarEntry() definition code for java.net.JarURLConnection.getJarEntry() ()
          Return the JAR entry object for this connection, if any.
abstract  JarFile sample code for java.util.jar.JarFile definition code for java.util.jar.JarFile getJarFile sample code for java.net.JarURLConnection.getJarFile() definition code for java.net.JarURLConnection.getJarFile() ()
          Return the JAR file for this connection.
 URL sample code for java.net.URL definition code for java.net.URL getJarFileURL sample code for java.net.JarURLConnection.getJarFileURL() definition code for java.net.JarURLConnection.getJarFileURL() ()
          Returns the URL for the Jar file for this connection.
 Attributes sample code for java.util.jar.Attributes definition code for java.util.jar.Attributes getMainAttributes sample code for java.net.JarURLConnection.getMainAttributes() definition code for java.net.JarURLConnection.getMainAttributes() ()
          Returns the main Attributes for the JAR file for this connection.
 Manifest sample code for java.util.jar.Manifest definition code for java.util.jar.Manifest getManifest sample code for java.net.JarURLConnection.getManifest() definition code for java.net.JarURLConnection.getManifest() ()
          Returns the Manifest for this connection, or null if none.
 
Methods inherited from class java.net.URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection
addRequestProperty sample code for java.net.URLConnection.addRequestProperty(java.lang.String, java.lang.String) definition code for java.net.URLConnection.addRequestProperty(java.lang.String, java.lang.String) , connect sample code for java.net.URLConnection.connect() definition code for java.net.URLConnection.connect() , getAllowUserInteraction sample code for java.net.URLConnection.getAllowUserInteraction() definition code for java.net.URLConnection.getAllowUserInteraction() , getConnectTimeout sample code for java.net.URLConnection.getConnectTimeout() definition code for java.net.URLConnection.getConnectTimeout() , getContent sample code for java.net.URLConnection.getContent() definition code for java.net.URLConnection.getContent() , getContent sample code for java.net.URLConnection.getContent(java.lang.Class[]) definition code for java.net.URLConnection.getContent(java.lang.Class[]) , getContentEncoding sample code for java.net.URLConnection.getContentEncoding() definition code for java.net.URLConnection.getContentEncoding() , getContentLength sample code for java.net.URLConnection.getContentLength() definition code for java.net.URLConnection.getContentLength() , getContentType sample code for java.net.URLConnection.getContentType() definition code for java.net.URLConnection.getContentType() , getDate sample code for java.net.URLConnection.getDate() definition code for java.net.URLConnection.getDate() , getDefaultAllowUserInteraction sample code for java.net.URLConnection.getDefaultAllowUserInteraction() definition code for java.net.URLConnection.getDefaultAllowUserInteraction() , getDefaultRequestProperty sample code for java.net.URLConnection.getDefaultRequestProperty(java.lang.String) definition code for java.net.URLConnection.getDefaultRequestProperty(java.lang.String) , getDefaultUseCaches sample code for java.net.URLConnection.getDefaultUseCaches() definition code for java.net.URLConnection.getDefaultUseCaches() , getDoInput sample code for java.net.URLConnection.getDoInput() definition code for java.net.URLConnection.getDoInput() , getDoOutput sample code for java.net.URLConnection.getDoOutput() definition code for java.net.URLConnection.getDoOutput() , getExpiration sample code for java.net.URLConnection.getExpiration() definition code for java.net.URLConnection.getExpiration() , getFileNameMap sample code for java.net.URLConnection.getFileNameMap() definition code for java.net.URLConnection.getFileNameMap() , getHeaderField sample code for java.net.URLConnection.getHeaderField(int) definition code for java.net.URLConnection.getHeaderField(int) , getHeaderField sample code for java.net.URLConnection.getHeaderField(java.lang.String) definition code for java.net.URLConnection.getHeaderField(java.lang.String) , getHeaderFieldDate sample code for java.net.URLConnection.getHeaderFieldDate(java.lang.String, long) definition code for java.net.URLConnection.getHeaderFieldDate(java.lang.String, long) , getHeaderFieldInt sample code for java.net.URLConnection.getHeaderFieldInt(java.lang.String, int) definition code for java.net.URLConnection.getHeaderFieldInt(java.lang.String, int) , getHeaderFieldKey sample code for java.net.URLConnection.getHeaderFieldKey(int) definition code for java.net.URLConnection.getHeaderFieldKey(int) , getHeaderFields sample code for java.net.URLConnection.getHeaderFields() definition code for java.net.URLConnection.getHeaderFields() , getIfModifiedSince sample code for java.net.URLConnection.getIfModifiedSince() definition code for java.net.URLConnection.getIfModifiedSince() , getInputStream sample code for java.net.URLConnection.getInputStream() definition code for java.net.URLConnection.getInputStream() , getLastModified sample code for java.net.URLConnection.getLastModified() definition code for java.net.URLConnection.getLastModified() , getOutputStream sample code for java.net.URLConnection.getOutputStream() definition code for java.net.URLConnection.getOutputStream() , getPermission sample code for java.net.URLConnection.getPermission() definition code for java.net.URLConnection.getPermission() , getReadTimeout sample code for java.net.URLConnection.getReadTimeout() definition code for java.net.URLConnection.getReadTimeout() , getRequestProperties sample code for java.net.URLConnection.getRequestProperties() definition code for java.net.URLConnection.getRequestProperties() , getRequestProperty sample code for java.net.URLConnection.getRequestProperty(java.lang.String) definition code for java.net.URLConnection.getRequestProperty(java.lang.String) , getURL sample code for java.net.URLConnection.getURL() definition code for java.net.URLConnection.getURL() , getUseCaches sample code for java.net.URLConnection.getUseCaches() definition code for java.net.URLConnection.getUseCaches() , guessContentTypeFromName sample code for java.net.URLConnection.guessContentTypeFromName(java.lang.String) definition code for java.net.URLConnection.guessContentTypeFromName(java.lang.String) , guessContentTypeFromStream sample code for java.net.URLConnection.guessContentTypeFromStream(java.io.InputStream) definition code for java.net.URLConnection.guessContentTypeFromStream(java.io.InputStream) , setAllowUserInteraction sample code for java.net.URLConnection.setAllowUserInteraction(boolean) definition code for java.net.URLConnection.setAllowUserInteraction(boolean) , setConnectTimeout sample code for java.net.URLConnection.setConnectTimeout(int) definition code for java.net.URLConnection.setConnectTimeout(int) , setContentHandlerFactory sample code for java.net.URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory) definition code for java.net.URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory) , setDefaultAllowUserInteraction sample code for java.net.URLConnection.setDefaultAllowUserInteraction(boolean) definition code for java.net.URLConnection.setDefaultAllowUserInteraction(boolean) , setDefaultRequestProperty sample code for java.net.URLConnection.setDefaultRequestProperty(java.lang.String, java.lang.String) definition code for java.net.URLConnection.setDefaultRequestProperty(java.lang.String, java.lang.String) , setDefaultUseCaches sample code for java.net.URLConnection.setDefaultUseCaches(boolean) definition code for java.net.URLConnection.setDefaultUseCaches(boolean) , setDoInput sample code for java.net.URLConnection.setDoInput(boolean) definition code for java.net.URLConnection.setDoInput(boolean) , setDoOutput sample code for java.net.URLConnection.setDoOutput(boolean) definition code for java.net.URLConnection.setDoOutput(boolean) , setFileNameMap sample code for java.net.URLConnection.setFileNameMap(java.net.FileNameMap) definition code for java.net.URLConnection.setFileNameMap(java.net.FileNameMap) , setIfModifiedSince sample code for java.net.URLConnection.setIfModifiedSince(long) definition code for java.net.URLConnection.setIfModifiedSince(long) , setReadTimeout sample code for java.net.URLConnection.setReadTimeout(int) definition code for java.net.URLConnection.setReadTimeout(int) , setRequestProperty sample code for java.net.URLConnection.setRequestProperty(java.lang.String, java.lang.String) definition code for java.net.URLConnection.setRequestProperty(java.lang.String, java.lang.String) , setUseCaches sample code for java.net.URLConnection.setUseCaches(boolean) definition code for java.net.URLConnection.setUseCaches(boolean) , toString sample code for java.net.URLConnection.toString() definition code for java.net.URLConnection.toString()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

jarFileURLConnection sample code for java.net.JarURLConnection.jarFileURLConnection

protected URLConnection sample code for java.net.URLConnection definition code for java.net.URLConnection  jarFileURLConnection
The connection to the JAR file URL, if the connection has been initiated. This should be set by connect.

Constructor Detail

JarURLConnection sample code for java.net.JarURLConnection(java.net.URL) definition code for java.net.JarURLConnection(java.net.URL)

protected JarURLConnection(URL sample code for java.net.URL definition code for java.net.URL  url)
                    throws MalformedURLException sample code for java.net.MalformedURLException definition code for java.net.MalformedURLException 
Creates the new JarURLConnection to the specified URL.

Parameters:
url - the URL
Throws:
MalformedURLException sample code for java.net.MalformedURLException definition code for java.net.MalformedURLException - if no legal protocol could be found in a specification string or the string could not be parsed.
Method Detail

getJarFileURL sample code for java.net.JarURLConnection.getJarFileURL() definition code for java.net.JarURLConnection.getJarFileURL()

public URL sample code for java.net.URL definition code for java.net.URL  getJarFileURL()
Returns the URL for the Jar file for this connection.

Returns:
the URL for the Jar file for this connection.

getEntryName sample code for java.net.JarURLConnection.getEntryName() definition code for java.net.JarURLConnection.getEntryName()

public String sample code for java.lang.String definition code for java.lang.String  getEntryName()
Return the entry name for this connection. This method returns null if the JAR file URL corresponding to this connection points to a JAR file and not a JAR file entry.

Returns:
the entry name for this connection, if any.

getJarFile sample code for java.net.JarURLConnection.getJarFile() definition code for java.net.JarURLConnection.getJarFile()

public abstract JarFile sample code for java.util.jar.JarFile definition code for java.util.jar.JarFile  getJarFile()
                            throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Return the JAR file for this connection.

Returns:
the JAR file for this connection. If the connection is a connection to an entry of a JAR file, the JAR file object is returned
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an IOException occurs while trying to connect to the JAR file for this connection.
See Also:
URLConnection.connect() sample code for java.net.URLConnection.connect() definition code for java.net.URLConnection.connect()

getManifest sample code for java.net.JarURLConnection.getManifest() definition code for java.net.JarURLConnection.getManifest()

public Manifest sample code for java.util.jar.Manifest definition code for java.util.jar.Manifest  getManifest()
                     throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Returns the Manifest for this connection, or null if none.

Returns:
the manifest object corresponding to the JAR file object for this connection.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if getting the JAR file for this connection causes an IOException to be trown.
See Also:
getJarFile() sample code for java.net.JarURLConnection.getJarFile() definition code for java.net.JarURLConnection.getJarFile()

getJarEntry sample code for java.net.JarURLConnection.getJarEntry() definition code for java.net.JarURLConnection.getJarEntry()

public JarEntry sample code for java.util.jar.JarEntry definition code for java.util.jar.JarEntry  getJarEntry()
                     throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Return the JAR entry object for this connection, if any. This method returns null if the JAR file URL corresponding to this connection points to a JAR file and not a JAR file entry.

Returns:
the JAR entry object for this connection, or null if the JAR URL for this connection points to a JAR file.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if getting the JAR file for this connection causes an IOException to be trown.
See Also:
getJarFile() sample code for java.net.JarURLConnection.getJarFile() definition code for java.net.JarURLConnection.getJarFile() , getJarEntry() sample code for java.net.JarURLConnection.getJarEntry() definition code for java.net.JarURLConnection.getJarEntry()

getAttributes sample code for java.net.JarURLConnection.getAttributes() definition code for java.net.JarURLConnection.getAttributes()

public Attributes sample code for java.util.jar.Attributes definition code for java.util.jar.Attributes  getAttributes()
                         throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Return the Attributes object for this connection if the URL for it points to a JAR file entry, null otherwise.

Returns:
the Attributes object for this connection if the URL for it points to a JAR file entry, null otherwise.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if getting the JAR entry causes an IOException to be thrown.
See Also:
getJarEntry() sample code for java.net.JarURLConnection.getJarEntry() definition code for java.net.JarURLConnection.getJarEntry()

getMainAttributes sample code for java.net.JarURLConnection.getMainAttributes() definition code for java.net.JarURLConnection.getMainAttributes()

public Attributes sample code for java.util.jar.Attributes definition code for java.util.jar.Attributes  getMainAttributes()
                             throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Returns the main Attributes for the JAR file for this connection.

Returns:
the main Attributes for the JAR file for this connection.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if getting the manifest causes an IOException to be thrown.
See Also:
getJarFile() sample code for java.net.JarURLConnection.getJarFile() definition code for java.net.JarURLConnection.getJarFile() , getManifest() sample code for java.net.JarURLConnection.getManifest() definition code for java.net.JarURLConnection.getManifest()

getCertificates sample code for java.net.JarURLConnection.getCertificates() definition code for java.net.JarURLConnection.getCertificates()

public Certificate sample code for java.security.cert.Certificate definition code for java.security.cert.Certificate [] getCertificates()
                              throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Return the Certificate object for this connection if the URL for it points to a JAR file entry, null otherwise. This method can only be called once the connection has been completely verified by reading from the input stream until the end of the stream has been reached. Otherwise, this method will return null

Returns:
the Certificate object for this connection if the URL for it points to a JAR file entry, null otherwise.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if getting the JAR entry causes an IOException to be thrown.
See Also:
getJarEntry() sample code for java.net.JarURLConnection.getJarEntry() definition code for java.net.JarURLConnection.getJarEntry()