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 intThe cached hashCode.final longIf the slice is a deflated zip entry, this is the expected uncompressed length, or -1L if unknown.final booleanIf true, the slice is a deflated zip entry, and needs to be inflated to access the content.protected final NestedJarHandlerTheNestedJarHandler.protected final SliceThe parent slice.longThe length of the slice, or -1L if unknown (forInputStream).final longThe start position of the slice. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSlice(long length, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) Constructor.protectedSlice(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 TypeMethodDescriptionvoidclose()booleaninthashCode()abstract byte[]load()Load the slice as a byte array.Load the slice as a string.open()Open thisSliceas anInputStream.Open thisSliceas anInputStream.abstract RandomAccessReaderCreate a newRandomAccessReaderfor thisSlice.read()Read the slice into aByteBuffer.abstract Sliceslice(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 childSlicefrom 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 thisSliceas anInputStream.- Returns:
- the input stream
- Throws:
IOException- if an inflater cannot be created for thisSlice.
-
open
Open thisSliceas anInputStream.- Parameters:
resourceToClose- theResourceto close when the returnedInputStreamis closed, or null if none.- Returns:
- the input stream
- Throws:
IOException- if an inflater cannot be created for thisSlice.
-
randomAccessReader
Create a newRandomAccessReaderfor 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
hashCode
-
equals
-