public class NestedJarHandler extends Object
Somewhat paradoxically, the fastest way to support scanning zipfiles-within-zipfiles is to unzip the inner zipfile to a temporary file on disk, because the inner zipfile can only be read using ZipInputStream, not ZipFile (the ZipFile constructors only take a File argument). ZipInputStream doesn't have methods for reading the zip directory at the beginning of the stream, so using ZipInputStream rather than ZipFile, you have to decompress the entire zipfile to read all the directory entries. However, there may be many non-whitelisted entries in the zipfile, so this could be a lot of wasted work.
FastClasspathScanner makes two passes, one to read the zipfile directory, which whitelist and blacklist criteria are applied to (this is a fast operation when using ZipFile), and then an additional pass to read only whitelisted (non-blacklisted) entries. Therefore, in the general case, the ZipFile API is always going to be faster than ZipInputStream. Therefore, decompressing the inner zipfile to disk is the only efficient option.
Modifier and Type | Field and Description |
---|---|
static String |
TEMP_FILENAME_LEAF_SEPARATOR |
Constructor and Description |
---|
NestedJarHandler(InterruptionChecker interruptionChecker,
LogNode log) |
Modifier and Type | Method and Description |
---|---|
void |
close(LogNode log)
Delete temporary files and release other resources.
|
Map.Entry<File,Set<String>> |
getInnermostNestedJar(String nestedJarPath,
LogNode log)
Get a File for a given (possibly nested) jarfile path, unzipping the first N-1 segments of an N-segment
'!'-delimited path to temporary files, then returning the File reference for the N-th temporary file.
|
Recycler<ZipFile,IOException> |
getZipFileRecycler(String canonicalPath,
LogNode log)
Get a ZipFile recycler given the (non-nested) canonical path of a jarfile.
|
public static final String TEMP_FILENAME_LEAF_SEPARATOR
public NestedJarHandler(InterruptionChecker interruptionChecker, LogNode log)
public Recycler<ZipFile,IOException> getZipFileRecycler(String canonicalPath, LogNode log) throws Exception
Exception
public Map.Entry<File,Set<String>> getInnermostNestedJar(String nestedJarPath, LogNode log) throws Exception
If the path does not contain '!', returns the File represented by the path.
All path segments should end in a jarfile extension, e.g. ".jar" or ".zip".
Entry<File, Set<String>>
, where the File
is the innermost jar, and the
Set<String>
is the set of all relative paths of scanning roots within the innermost jar (may
be empty, or may contain strings like "target/classes" or similar). If there was an issue with the
path, returns null.Exception
public void close(LogNode log)
Copyright © 2018. All rights reserved.