Class PathSlice
- java.lang.Object
-
- nonapi.io.github.classgraph.fileslice.Slice
-
- nonapi.io.github.classgraph.fileslice.PathSlice
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class PathSlice extends Slice
APathslice.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.channels.FileChannelfileChannelTheFileChannelopened on thePath.private longfileLengthThe file length.private java.util.concurrent.atomic.AtomicBooleanisClosedTrue ifclose()has been called.private booleanisTopLevelFileSliceTrue if this is a top level file slice.java.nio.file.PathpathThePath.-
Fields inherited from class nonapi.io.github.classgraph.fileslice.Slice
inflatedLengthHint, isDeflatedZipEntry, nestedJarHandler, parentSlice, sliceLength, sliceStartPos
-
-
Constructor Summary
Constructors Modifier Constructor Description PathSlice(java.nio.file.Path path, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler)Constructor for toplevel file slice.PathSlice(java.nio.file.Path path, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler, boolean checkAccess)Constructor for toplevel file slice.PathSlice(java.nio.file.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the slice.booleanequals(java.lang.Object o)inthashCode()byte[]load()Load the slice as a byte array.RandomAccessReaderrandomAccessReader()Read directly from FileChannel (slow path, but handles >2GB).java.nio.ByteBufferread()Read the slice into aByteBuffer(or memory-map the slice to aMappedByteBuffer, ifClassGraph.enableMemoryMapping()was called.)Sliceslice(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 Detail
-
path
public final java.nio.file.Path path
ThePath.
-
fileLength
private final long fileLength
The file length.
-
fileChannel
private java.nio.channels.FileChannel fileChannel
TheFileChannelopened on thePath.
-
isTopLevelFileSlice
private final boolean isTopLevelFileSlice
True if this is a top level file slice.
-
isClosed
private final java.util.concurrent.atomic.AtomicBoolean isClosed
True ifclose()has been called.
-
-
Constructor Detail
-
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(java.nio.file.Path path, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) throws java.io.IOExceptionConstructor 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:
java.io.IOException- if the file cannot be opened.
-
PathSlice
public PathSlice(java.nio.file.Path path, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler, boolean checkAccess) throws java.io.IOExceptionConstructor 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:
java.io.IOException- if the file cannot be opened.
-
PathSlice
public PathSlice(java.nio.file.Path path, NestedJarHandler nestedJarHandler) throws java.io.IOExceptionConstructor for toplevel file slice.- Parameters:
path- the pathnestedJarHandler- the nested jar handler- Throws:
java.io.IOException- if the file cannot be opened.
-
-
Method Detail
-
slice
public Slice slice(long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint)
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
public RandomAccessReader randomAccessReader()
Read directly from FileChannel (slow path, but handles >2GB).- Specified by:
randomAccessReaderin classSlice- Returns:
- the random access reader
-
load
public byte[] load() throws java.io.IOExceptionLoad the slice as a byte array.
-
read
public java.nio.ByteBuffer read() throws java.io.IOExceptionRead the slice into aByteBuffer(or memory-map the slice to aMappedByteBuffer, ifClassGraph.enableMemoryMapping()was called.)
-
-