Class Slice
- java.lang.Object
-
- nonapi.io.github.classgraph.fileslice.Slice
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
ArraySlice
,FileSlice
,PathSlice
public abstract class Slice extends java.lang.Object implements java.io.Closeable
A slice of aFile
,ByteBuffer
orInputStream
. A singleSlice
instance should only be used by a single thread.
-
-
Field Summary
Fields Modifier and Type Field Description private int
hashCode
The cached hashCode.long
inflatedLengthHint
If the slice is a deflated zip entry, this is the expected uncompressed length, or -1L if unknown.boolean
isDeflatedZipEntry
If true, the slice is a deflated zip entry, and needs to be inflated to access the content.protected NestedJarHandler
nestedJarHandler
TheNestedJarHandler
.protected Slice
parentSlice
The parent slice.long
sliceLength
The length of the slice, or -1L if unknown (forInputStream
).long
sliceStartPos
The start position of the slice.
-
Constructor Summary
Constructors Modifier Constructor Description protected
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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
boolean
equals(java.lang.Object o)
int
hashCode()
abstract byte[]
load()
Load the slice as a byte array.java.lang.String
loadAsString()
Load the slice as a string.java.io.InputStream
open()
Open thisSlice
as anInputStream
.java.io.InputStream
open(Resource resourceToClose)
Open thisSlice
as anInputStream
.abstract RandomAccessReader
randomAccessReader()
Create a newRandomAccessReader
for thisSlice
.java.nio.ByteBuffer
read()
Read the slice into aByteBuffer
.abstract Slice
slice(long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint)
-
-
-
Field Detail
-
nestedJarHandler
protected final NestedJarHandler nestedJarHandler
TheNestedJarHandler
.
-
parentSlice
protected final Slice parentSlice
The parent slice.
-
sliceStartPos
public final long sliceStartPos
The start position of the slice.
-
sliceLength
public long sliceLength
The length of the slice, or -1L if unknown (forInputStream
).
-
isDeflatedZipEntry
public final boolean isDeflatedZipEntry
If true, the slice is a deflated zip entry, and needs to be inflated to access the content.
-
inflatedLengthHint
public final long inflatedLengthHint
If the slice is a deflated zip entry, this is the expected uncompressed length, or -1L if unknown.
-
hashCode
private int hashCode
The cached hashCode.
-
-
Constructor Detail
-
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 Detail
-
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
public java.io.InputStream open() throws java.io.IOException
Open thisSlice
as anInputStream
.- Returns:
- the input stream
- Throws:
java.io.IOException
- if an inflater cannot be created for thisSlice
.
-
open
public java.io.InputStream open(Resource resourceToClose) throws java.io.IOException
Open thisSlice
as anInputStream
.
-
randomAccessReader
public abstract RandomAccessReader randomAccessReader()
Create a newRandomAccessReader
for thisSlice
.- Returns:
- the random access reader
-
load
public abstract byte[] load() throws java.io.IOException
Load the slice as a byte array.- Returns:
- the byte[]
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
loadAsString
public java.lang.String loadAsString() throws java.io.IOException
Load the slice as a string.- Returns:
- the string
- Throws:
java.io.IOException
- if slice cannot be read.
-
read
public java.nio.ByteBuffer read() throws java.io.IOException
Read the slice into aByteBuffer
.- Returns:
- the byte buffer
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
-