Class ArchiveURLConnection
archive:file:///c:/temp/example.zip!/org/example/nested.zip!/org/example/deeply-nested.htmlThe general recursive pattern is
archive:$nestedURL${/!$archivePath$}+
So the nested URL for the example above is
file:///c:/temp/example.zip
Since the nested URL may itself contain archive schemes, the subsequence of the archive paths that should be associated with the nested URL is determined by finding the nth archive separator, i.e., the nth !/, where n is the number of ":"s before the first "/" of the nested URL, i.e., the number of nested schemes. For example, for a more complex case where the nested URL is itself an archive-based scheme, e.g.,
archive:jar:file:///c:/temp/example.zip!/org/example/nested.zip!/org/example/deeply-nested.htmlthe nested URL is correctly parsed to skip to the second archive separator as
jar:file:///c:/temp/example.zip!/org/example/nested.zip
The logic for accessing archives can be tailored and reused independant from its usage as a URL connection.
This is normally done by using the constructor ArchiveURLConnection(String)
and overriding createInputStream(String) and createOutputStream(String).
The behavior can be tailored by overriding emulateArchiveScheme() and useZipFile().
-
Field Summary
FieldsFields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a new archive accessor.ArchiveURLConnection(URL url) Constructs a new connection for the URL. -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Record that this is connected.protected InputStreamcreateInputStream(String nestedURL) Creates an input stream for the nested URL by callingopeninga stream on it.protected OutputStreamcreateOutputStream(String nestedURL) Creates an output stream for the nested URL by callingopeninga stream on it.voiddelete()protected booleanReturns whether the implementation will handle all the archive accessors directly.Creates the input stream for the URL.protected StringCreates the output stream for the URL.voidsetTimeStamp(long timeStamp) protected booleanReturns whether to handle the special case of a nested URL with file: schema using aZipFile.protected InputStreamyield(ZipEntry zipEntry, InputStream inputStream) protected OutputStreamyield(ZipEntry zipEntry, OutputStream outputStream) Methods inherited from class java.net.URLConnection
addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentLengthLong, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHeaderFieldLong, getHeaderFields, getIfModifiedSince, getLastModified, getPermission, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
-
Field Details
-
urlString
The cached string version of theURL.
-
-
Constructor Details
-
ArchiveURLConnection
Constructs a new connection for the URL.- Parameters:
url- the URL of this connection.
-
ArchiveURLConnection
Constructs a new archive accessor. This constructor forwards a null URL to be super constructor, so an instance built with this constructor cannot be used as a URLConnection. The logic for accessing archives and for delegating to the nested URL can be reused in other applications, without creating an URLs.- Parameters:
url- the URL of the archive.
-
-
Method Details
-
emulateArchiveScheme
protected boolean emulateArchiveScheme()Returns whether the implementation will handle all the archive accessors directly. For example, whetherarchive:jar:file:///c:/temp/example.zip!/org/example/nested.zip!/org/example/deeply-nested.html
will be handled as if it were specified asarchive:file:///c:/temp/example.zip!/org/example/nested.zip!/org/example/deeply-nested.html
Override this only if you are reusing the logic of retrieving an input stream into an archive and hence are likely to be overriding createInputStream, which is the point of delegation to the nested URL for recursive stream creation.- Returns:
- whether the implementation will handle all the archive accessors directly.
-
useZipFile
protected boolean useZipFile()Returns whether to handle the special case of a nested URL with file: schema using aZipFile. This gives more efficient direct access to the root entry, e.g.,archive:file:///c:/temp/example.zip!/org/example/nested.html
- Returns:
- whether to handle the special case of a nested URL with file: schema using a ZipFile.
-
connect
Record that this is connected.- Specified by:
connectin classURLConnection- Throws:
IOException
-
getNestedURL
- Throws:
IOException
-
getInputStream
Creates the input stream for the URL.- Overrides:
getInputStreamin classURLConnection- Returns:
- the input stream for the URL.
- Throws:
IOException
-
yield
- Throws:
IOException
-
createInputStream
Creates an input stream for the nested URL by callingopeninga stream on it.- Parameters:
nestedURL- the nested URL for which a stream is required.- Returns:
- the open stream of the nested URL.
- Throws:
IOException
-
getOutputStream
Creates the output stream for the URL.- Overrides:
getOutputStreamin classURLConnection- Returns:
- the output stream for the URL.
- Throws:
IOException
-
delete
- Throws:
IOException
-
setTimeStamp
- Throws:
IOException
-
yield
- Throws:
IOException
-
createOutputStream
Creates an output stream for the nested URL by callingopeninga stream on it.- Parameters:
nestedURL- the nested URL for which a stream is required.- Returns:
- the open stream of the nested URL.
- Throws:
IOException
-