Package com.portal.pfc.util.nestedjars
Class NestedJarURLConnection
java.lang.Object
java.net.URLConnection
com.portal.pfc.util.nestedjars.NestedJarURLConnection
NestedJarURLConnection is a subclass of the URLConnection. It supports
opening a connection to a file that is packaged in a JAR file, which in turn
is inside another JAR file. There is support for a single level of nesting.
It is expected that the outer JAR is available on the local filesystem and accessible via standard java.io.File operations.
This class knows how to handle URLs using a custom nestedjar protocol. The URL should be of the form:
nestedjar://file:/C:/TEMP/apps.jar!/innerapps.jar!/myapp/nested.gif
The different parts of the URL are:nestedjar:// | Custom protocol for loading resources from nested jar files. |
/C:/TEMP/ | Path to the toplevel jar file. Should be accessible via standard java.io.File. |
apps.jar | Outer jar file. This jar file is on the classpath. It contains nested jar file(s). |
innerapps.jar | Jar file nested inside the outer jar file. This Jar file contains the actual resources. |
myapp/nested.gif | Resource in the inner jar file that is to be loaded |
!/ | Separator. Separates a jar file and the components it contains. |
- Author:
- Max Spivak
-
Field Summary
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
connect()
Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.Determine the content type of the resourceReturns an input stream that reads from this open connection.Methods inherited from class java.net.URLConnection
addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentLengthLong, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHeaderFieldLong, getHeaderFields, getIfModifiedSince, getLastModified, getOutputStream, getPermission, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
-
Constructor Details
-
NestedJarURLConnection
Constructor. See class comment regarding URL structure this class knows how to handle.
-
-
Method Details
-
connect
Opens a communications link to the resource referenced by this URL, if such a connection has not already been established. More specifically, this method will attempt to open the outer jar file and locate the inner, nested jar file as specified by the URL.If the
connect
method is called when the connection has already been opened the call is ignored.- Specified by:
connect
in classURLConnection
- Throws:
IOException
- if an I/O error occurs while opening the connection.
-
getInputStream
Returns an input stream that reads from this open connection.- Overrides:
getInputStream
in classURLConnection
- Returns:
- an input stream that reads from this open connection.
- Throws:
IOException
- if an I/O error occurs while creating the input stream.UnknownServiceException
- if the protocol does not support input.
-
getContentType
Determine the content type of the resource- Overrides:
getContentType
in classURLConnection
-