Class NestedJarHandler
java.lang.Object
nonapi.io.github.classgraph.fastzipfilereader.NestedJarHandler
Open and read jarfiles, which may be nested within other jarfiles.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe interruption checker.A singleton map from aModuleRefto aModuleReaderProxyrecycler for the module.A singleton map from nested jarfile path to a tuple of the logical zipfile for the path, and the package root within the logical zipfile.final ScanSpecTheScanSpec.static final StringThe separator between random temp filename part and leafname. -
Constructor Summary
ConstructorsConstructorDescriptionNestedJarHandler(ScanSpec scanSpec, InterruptionChecker interruptionChecker, ReflectionUtils reflectionUtils) A handler for nested jars. -
Method Summary
Modifier and TypeMethodDescriptionvoidClose zipfiles, modules, and recyclers, and delete temporary files.voidcloseDirectByteBuffer(ByteBuffer backingByteBuffer) makeTempFile(String filePathBase, boolean onlyUseLeafname) Create a temporary file, and mark it for deletion on exit.voidmarkSliceAsClosed(Slice slice) Mark aSliceas closed.voidmarkSliceAsOpen(Slice slice) Mark aSliceas open, so it can be closed when theScanResultis closed.openInflaterInputStream(InputStream rawInputStream) static byte[]readAllBytesAsArray(InputStream inputStream, long uncompressedLengthHint) Read all the bytes in anInputStream.readAllBytesWithSpilloverToDisk(InputStream inputStream, String tempFileBaseName, long inputStreamLengthHint, LogNode log) Read all the bytes in anInputStream, with spillover to a temporary file on disk if a maximum buffer size is exceeded.void
-
Field Details
-
scanSpec
-
reflectionUtils
-
nestedPathToLogicalZipFileAndPackageRootMap
public SingletonMap<String, Map.Entry<LogicalZipFile, String>, IOException> nestedPathToLogicalZipFileAndPackageRootMapA singleton map from nested jarfile path to a tuple of the logical zipfile for the path, and the package root within the logical zipfile. -
moduleRefToModuleReaderProxyRecyclerMap
public SingletonMap<ModuleRef, Recycler<ModuleReaderProxy, IOException>, IOException> moduleRefToModuleReaderProxyRecyclerMapA singleton map from aModuleRefto aModuleReaderProxyrecycler for the module. -
TEMP_FILENAME_LEAF_SEPARATOR
The separator between random temp filename part and leafname.- See Also:
-
interruptionChecker
The interruption checker.
-
-
Constructor Details
-
NestedJarHandler
public NestedJarHandler(ScanSpec scanSpec, InterruptionChecker interruptionChecker, ReflectionUtils reflectionUtils) A handler for nested jars.- Parameters:
scanSpec- TheScanSpec.interruptionChecker- the interruption checker
-
-
Method Details
-
makeTempFile
Create a temporary file, and mark it for deletion on exit.- Parameters:
filePathBase- The path to derive the temporary filename from.onlyUseLeafname- If true, only use the leafname of filePath to derive the temporary filename.- Returns:
- The temporary
File. - Throws:
IOException- If the temporary file could not be created.
-
markSliceAsOpen
Mark aSliceas open, so it can be closed when theScanResultis closed.- Parameters:
slice- theSlicethat was just opened.- Throws:
IOException- Signals that an I/O exception has occurred.
-
markSliceAsClosed
-
openInflaterInputStream
- Parameters:
rawInputStream- the raw input stream- Returns:
- the inflater input stream
- Throws:
IOException- Signals that an I/O exception has occurred.
-
readAllBytesWithSpilloverToDisk
public Slice readAllBytesWithSpilloverToDisk(InputStream inputStream, String tempFileBaseName, long inputStreamLengthHint, LogNode log) throws IOException Read all the bytes in anInputStream, with spillover to a temporary file on disk if a maximum buffer size is exceeded.- Parameters:
inputStream- theInputStreamto read from.tempFileBaseName- the source URL or zip entry that inputStream was opened from (used to name temporary file, if needed).inputStreamLengthHint- the length of inputStream if known, else -1L.log- the log.- Returns:
- if the
InputStreamcould be read into a byte array, anArraySlicewill be returned. If this fails and theInputStreamis spilled over to disk, aFileSlicewill be returned. - Throws:
IOException- If the contents could not be read.
-
readAllBytesAsArray
public static byte[] readAllBytesAsArray(InputStream inputStream, long uncompressedLengthHint) throws IOException Read all the bytes in anInputStream.- Parameters:
inputStream- TheInputStream.uncompressedLengthHint- The length of the data once inflated from theInputStream, if known, otherwise -1L.- Returns:
- The contents of the
InputStreamas a byte array. - Throws:
IOException- If the contents could not be read.
-
close
Close zipfiles, modules, and recyclers, and delete temporary files. Called byScanResult.close().- Parameters:
log- The log.
-
runFinalizationMethod
public void runFinalizationMethod() -
closeDirectByteBuffer
-