Class Slice
java.lang.Object
nonapi.io.github.classgraph.fileslice.Slice
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
ArraySlice
,FileSlice
,PathSlice
A slice of a
File
, ByteBuffer
or InputStream
. A single Slice
instance should only
be used by a single thread.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
The cached hashCode.final long
If the slice is a deflated zip entry, this is the expected uncompressed length, or -1L if unknown.final boolean
If true, the slice is a deflated zip entry, and needs to be inflated to access the content.protected final NestedJarHandler
TheNestedJarHandler
.protected final Slice
The parent slice.long
The length of the slice, or -1L if unknown (forInputStream
).final long
The start position of the slice. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Slice
(long length, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) Constructor.protected
Slice
(Slice parentSlice, long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) Constructor for treating a range of a slice as a sub-slice. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
int
hashCode()
abstract byte[]
load()
Load the slice as a byte array.Load the slice as a string.open()
Open thisSlice
as anInputStream
.Open thisSlice
as anInputStream
.abstract RandomAccessReader
Create a newRandomAccessReader
for thisSlice
.read()
Read the slice into aByteBuffer
.abstract Slice
slice
(long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint)
-
Field Details
-
nestedJarHandler
TheNestedJarHandler
. -
parentSlice
The parent slice. -
sliceStartPos
public final long sliceStartPosThe start position of the slice. -
sliceLength
public long sliceLengthThe length of the slice, or -1L if unknown (forInputStream
). -
isDeflatedZipEntry
public final boolean isDeflatedZipEntryIf true, the slice is a deflated zip entry, and needs to be inflated to access the content. -
inflatedLengthHint
public final long inflatedLengthHintIf the slice is a deflated zip entry, this is the expected uncompressed length, or -1L if unknown. -
hashCode
private int hashCodeThe cached hashCode.
-
-
Constructor Details
-
Slice
protected Slice(Slice parentSlice, long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) Constructor for treating a range of a slice as a sub-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
-
Slice
protected Slice(long length, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) Constructor.- Parameters:
length
- the lengthisDeflatedZipEntry
- 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
-
-
Method Details
-
slice
public abstract Slice slice(long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint) Get a childSlice
from this parentSlice
. The child slice must be smaller than the parent slice, and completely contained within it.- Parameters:
offset
- The offset to start slicing from, relative to this parent slice's start position.length
- The length of the slice.isDeflatedZipEntry
- 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 child slice.
-
open
Open thisSlice
as anInputStream
.- Returns:
- the input stream
- Throws:
IOException
- if an inflater cannot be created for thisSlice
.
-
open
Open thisSlice
as anInputStream
.- Parameters:
resourceToClose
- theResource
to close when the returnedInputStream
is closed, or null if none.- Returns:
- the input stream
- Throws:
IOException
- if an inflater cannot be created for thisSlice
.
-
randomAccessReader
Create a newRandomAccessReader
for thisSlice
.- Returns:
- the random access reader
-
load
Load the slice as a byte array.- Returns:
- the byte[]
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
loadAsString
Load the slice as a string.- Returns:
- the string
- Throws:
IOException
- if slice cannot be read.
-
read
Read the slice into aByteBuffer
.- Returns:
- the byte buffer
- Throws:
IOException
- Signals that an I/O exception has occurred.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
hashCode
public int hashCode() -
equals
-