Class PathSlice
java.lang.Object
nonapi.io.github.classgraph.fileslice.Slice
nonapi.io.github.classgraph.fileslice.PathSlice
- All Implemented Interfaces:
Closeable,AutoCloseable
A
Path slice.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FileChannelTheFileChannelopened on thePath.private final longThe file length.private final AtomicBooleanTrue ifclose()has been called.private final booleanTrue if this is a top level file slice.final PathThePath.Fields inherited from class nonapi.io.github.classgraph.fileslice.Slice
inflatedLengthHint, isDeflatedZipEntry, nestedJarHandler, parentSlice, sliceLength, sliceStartPos -
Constructor Summary
ConstructorsModifierConstructorDescriptionPathSlice(Path path, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) Constructor for toplevel file slice.PathSlice(Path path, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler, boolean checkAccess) Constructor for toplevel file slice.PathSlice(Path path, NestedJarHandler nestedJarHandler) Constructor for toplevel file slice.privatePathSlice(PathSlice parentSlice, long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) Constructor for treating a range of a file as a slice. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the slice.booleaninthashCode()byte[]load()Load the slice as a byte array.Read directly from FileChannel (slow path, but handles >2GB).read()Read the slice into aByteBuffer(or memory-map the slice to aMappedByteBuffer, ifClassGraph.enableMemoryMapping()was called.)slice(long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint) Slice the file.Methods inherited from class nonapi.io.github.classgraph.fileslice.Slice
loadAsString, open, open
-
Field Details
-
path
ThePath. -
fileLength
private final long fileLengthThe file length. -
fileChannel
TheFileChannelopened on thePath. -
isTopLevelFileSlice
private final boolean isTopLevelFileSliceTrue if this is a top level file slice. -
isClosed
True ifclose()has been called.
-
-
Constructor Details
-
PathSlice
private PathSlice(PathSlice parentSlice, long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) Constructor for treating a range of a file as a slice.- Parameters:
parentSlice- the parent sliceoffset- the offset of the sub-slice within the parent slicelength- the length of the sub-sliceisDeflatedZipEntry- true if this is a deflated zip entryinflatedLengthHint- the uncompressed size of a deflated zip entry, or -1 if unknown, or 0 of this is not a deflated zip entry.nestedJarHandler- the nested jar handler
-
PathSlice
public PathSlice(Path path, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) throws IOException Constructor for toplevel file slice.- Parameters:
path- the pathisDeflatedZipEntry- true if this is a deflated zip entryinflatedLengthHint- the uncompressed size of a deflated zip entry, or -1 if unknown, or 0 of this is not a deflated zip entry.nestedJarHandler- the nested jar handler- Throws:
IOException- if the file cannot be opened.
-
PathSlice
public PathSlice(Path path, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler, boolean checkAccess) throws IOException Constructor for toplevel file slice.- Parameters:
path- the pathisDeflatedZipEntry- true if this is a deflated zip entryinflatedLengthHint- the uncompressed size of a deflated zip entry, or -1 if unknown, or 0 of this is not a deflated zip entry.nestedJarHandler- the nested jar handlercheckAccess- whether it is needed to check read access and if it is a file- Throws:
IOException- if the file cannot be opened.
-
PathSlice
Constructor for toplevel file slice.- Parameters:
path- the pathnestedJarHandler- the nested jar handler- Throws:
IOException- if the file cannot be opened.
-
-
Method Details
-
slice
Slice the file.- Specified by:
slicein classSlice- Parameters:
offset- the offset of the sub-slice within the parent slicelength- the length of the sub-sliceisDeflatedZipEntry- true if this is a deflated zip entryinflatedLengthHint- the uncompressed size of a deflated zip entry, or -1 if unknown, or 0 of this is not a deflated zip entry.- Returns:
- the slice
-
randomAccessReader
Read directly from FileChannel (slow path, but handles >2GB).- Specified by:
randomAccessReaderin classSlice- Returns:
- the random access reader
-
load
Load the slice as a byte array.- Specified by:
loadin classSlice- Returns:
- the byte[]
- Throws:
IOException- Signals that an I/O exception has occurred.
-
read
Read the slice into aByteBuffer(or memory-map the slice to aMappedByteBuffer, ifClassGraph.enableMemoryMapping()was called.)- Overrides:
readin classSlice- Returns:
- the byte buffer
- Throws:
IOException- Signals that an I/O exception has occurred.
-
equals
-
hashCode
public int hashCode() -
close
public void close()Close the slice. Unmaps any backingMappedByteBuffer.
-