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.CloseableA slice of aFile,ByteBufferorInputStream. A singleSliceinstance should only be used by a single thread.
-
-
Field Summary
Fields Modifier and Type Field Description private inthashCodeThe cached hashCode.longinflatedLengthHintIf the slice is a deflated zip entry, this is the expected uncompressed length, or -1L if unknown.booleanisDeflatedZipEntryIf true, the slice is a deflated zip entry, and needs to be inflated to access the content.protected NestedJarHandlernestedJarHandlerTheNestedJarHandler.protected SliceparentSliceThe parent slice.longsliceLengthThe length of the slice, or -1L if unknown (forInputStream).longsliceStartPosThe start position of the slice.
-
Constructor Summary
Constructors Modifier Constructor Description protectedSlice(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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()booleanequals(java.lang.Object o)inthashCode()abstract byte[]load()Load the slice as a byte array.java.lang.StringloadAsString()Load the slice as a string.java.io.InputStreamopen()Open thisSliceas anInputStream.java.io.InputStreamopen(Resource resourceToClose)Open thisSliceas anInputStream.abstract RandomAccessReaderrandomAccessReader()Create a newRandomAccessReaderfor thisSlice.java.nio.ByteBufferread()Read the slice into aByteBuffer.abstract Sliceslice(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 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
public java.io.InputStream open() throws java.io.IOExceptionOpen thisSliceas 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 thisSliceas anInputStream.
-
randomAccessReader
public abstract RandomAccessReader randomAccessReader()
Create a newRandomAccessReaderfor thisSlice.- Returns:
- the random access reader
-
load
public abstract byte[] load() throws java.io.IOExceptionLoad 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.IOExceptionLoad 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.IOExceptionRead 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
-