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 ajar:URL using theJARprotocol. AJarURLConnectioninstance 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/
This class has different behavior depending on the
URLConnection.getUseCaches()setting. When caching is enabled the underlyingJarFilereturned fromgetJarFile()is cached and shared between connections. It must not be closed by the caller. Disabling caching usingURLConnection.setUseCaches(boolean)will prevent sharing but in the absence of aJarURLConnection.disconnect()method the only way to close the underlyingJarFileis to callgetJarFile().close()orgetInputStream().close(). For uncached connections, closing theJarFilecan prevent various otherURLConnectionmethods from working.
-
-
Field Summary
Fields Modifier and Type Field Description protected URLConnectionjarFileURLConnectionThe location part of the represented URL.-
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJarURLConnection(URL url)Constructs an instance ofJarURLConnectionthat refers to the specified URL.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description AttributesgetAttributes()Returns all attributes of theJarEntryreferenced by thisJarURLConnection.Certificate[]getCertificates()Returns all certificates of theJarEntryreferenced by thisJarURLConnectioninstance.StringgetEntryName()Gets the name of the entry referenced by thisJarURLConnection.JarEntrygetJarEntry()Gets theJarEntryobject of the entry referenced by thisJarURLConnection.abstract JarFilegetJarFile()Gets theJarFileobject referenced by thisJarURLConnection.URLgetJarFileURL()Gets the URL to the JAR-file referenced by thisJarURLConnection.AttributesgetMainAttributes()Gets all attributes of the manifest file referenced by thisJarURLConnection.ManifestgetManifest()Gets the manifest file associated with this JAR-URL.-
Methods inherited from class java.net.URLConnection
addRequestProperty, connect, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getOutputStream, getPermission, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
-
-
-
-
Field Detail
-
jarFileURLConnection
protected URLConnection jarFileURLConnection
The location part of the represented URL.
-
-
Constructor Detail
-
JarURLConnection
protected JarURLConnection(URL url) throws MalformedURLException
Constructs an instance ofJarURLConnectionthat 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 Detail
-
getAttributes
public Attributes getAttributes() throws IOException
Returns all attributes of theJarEntryreferenced by thisJarURLConnection.- 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 theJarEntryreferenced by thisJarURLConnectioninstance. This method will returnnulluntil theInputStreamhas been completely verified.- Returns:
- the certificates of the
JarEntryas an array. - Throws:
IOException- if there is an I/O exception occurs while getting theJarEntry.
-
getEntryName
public String getEntryName()
Gets the name of the entry referenced by thisJarURLConnection. The return value will benullif this instance refers to a JAR file rather than an JAR file entry.- Returns:
- the
JarEntryname this instance refers to.
-
getJarEntry
public JarEntry getJarEntry() throws IOException
Gets theJarEntryobject of the entry referenced by thisJarURLConnection.- Returns:
- the referenced
JarEntryobject ornullif 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 theJarFileobject referenced by thisJarURLConnection.- 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 thisJarURLConnection.- Returns:
- the URL to the JAR-file or
nullif there was an error retrieving the URL.
-
getMainAttributes
public Attributes getMainAttributes() throws IOException
Gets all attributes of the manifest file referenced by thisJarURLConnection. If this instance refers to a JAR-file rather than a JAR-file entry,nullwill be returned.- Returns:
- the attributes of the manifest file or
null. - Throws:
IOException- if an I/O exception occurs while retrieving theJarFile.
-
-