Top Description Fields Constructors Methods
nonapi.io.github.classgraph.fileslice

public abstract Class Slice

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
nonapi.io.github.classgraph.fileslice.ArraySlice, nonapi.io.github.classgraph.fileslice.FileSlice, nonapi.io.github.classgraph.fileslice.PathSlice
Imports
java.io.Closeable, .File, .IOException, .InputStream, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.concurrent.atomic.AtomicBoolean, io.github.classgraph.Resource, nonapi.io.github.classgraph.fastzipfilereader.NestedJarHandler, nonapi.io.github.classgraph.fileslice.reader.RandomAccessReader, nonapi.io.github.classgraph.utils.FileUtils

A slice of a File, ByteBuffer or InputStream. A single Slice instance should only be used by a single thread.

Field Summary

Modifier and TypeField and Description
private int
hashCode

The cached hashCode.

public final long
inflatedLengthHint

If the slice is a deflated zip entry, this is the expected uncompressed length, or -1L if unknown.

public final boolean
isDeflatedZipEntry

If true, the slice is a deflated zip entry, and needs to be inflated to access the content.

protected final NestedJarHandler
protected final Slice
parentSlice

The parent slice.

public long
sliceLength

The length of the slice, or -1L if unknown (for InputStream).

public final long
sliceStartPos

The start position of the slice.

Constructor Summary

AccessConstructor and Description
protected
Slice(final Slice
the parent slice
parentSlice
,
final long
the offset of the sub-slice within the parent slice
offset
,
final long
the length of the sub-slice
length
,
final boolean
true if this is a deflated zip entry
isDeflatedZipEntry
,
final long
the uncompressed size of a deflated zip entry, or -1 if unknown, or 0 of this is not a deflated zip entry.
inflatedLengthHint
,
final NestedJarHandler
the nested jar handler
nestedJarHandler
)

Constructor for treating a range of a slice as a sub-slice.

protected
Slice(final long
the length
length
,
final boolean
true if this is a deflated zip entry
isDeflatedZipEntry
,
final long
the uncompressed size of a deflated zip entry, or -1 if unknown, or 0 of this is not a deflated zip entry.
inflatedLengthHint
,
final NestedJarHandler
the nested jar handler
nestedJarHandler
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public boolean
equals(final Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public abstract byte[]

Returns:

the byte[]
load
()

Load the slice as a byte array.

public String

Returns:

the string
loadAsString
()

Load the slice as a string.

public InputStream

Returns:

the input stream
open
()

Open this Slice as an InputStream.

public InputStream

Returns:

the input stream
open
(final Resource
the Resource to close when the returned InputStream is closed, or null if none.
resourceToClose
)

Open this Slice as an InputStream.

public abstract RandomAccessReader

Returns:

the random access reader
randomAccessReader
()

Create a new RandomAccessReader for this Slice.

public ByteBuffer

Returns:

the byte buffer
read
()

Read the slice into a ByteBuffer.

public abstract Slice

Returns:

The child slice.
slice
(long
The offset to start slicing from, relative to this parent slice's start position.
offset
,
long
The length of the slice.
length
,
boolean
true if this is a deflated zip entry
isDeflatedZipEntry
,
final long
the uncompressed size of a deflated zip entry, or -1 if unknown, or 0 of this is not a deflated zip entry.
inflatedLengthHint
)

Get a child Slice from this parent Slice.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

hashCodeback to summary
private int hashCode

The cached hashCode.

inflatedLengthHintback to summary
public final long inflatedLengthHint

If the slice is a deflated zip entry, this is the expected uncompressed length, or -1L if unknown.

isDeflatedZipEntryback to summary
public final boolean isDeflatedZipEntry

If true, the slice is a deflated zip entry, and needs to be inflated to access the content.

nestedJarHandlerback to summary
protected final NestedJarHandler nestedJarHandler

The NestedJarHandler.

parentSliceback to summary
protected final Slice parentSlice

The parent slice.

sliceLengthback to summary
public long sliceLength

The length of the slice, or -1L if unknown (for InputStream).

sliceStartPosback to summary
public final long sliceStartPos

The start position of the slice.

Constructor Detail

Sliceback to summary
protected Slice(final Slice parentSlice, final long offset, final long length, final boolean isDeflatedZipEntry, final long inflatedLengthHint, final NestedJarHandler nestedJarHandler)

Constructor for treating a range of a slice as a sub-slice.

Parameters
parentSlice:Slice

the parent slice

offset:long

the offset of the sub-slice within the parent slice

length:long

the length of the sub-slice

isDeflatedZipEntry:boolean

true if this is a deflated zip entry

inflatedLengthHint:long

the uncompressed size of a deflated zip entry, or -1 if unknown, or 0 of this is not a deflated zip entry.

nestedJarHandler:NestedJarHandler

the nested jar handler

Sliceback to summary
protected Slice(final long length, final boolean isDeflatedZipEntry, final long inflatedLengthHint, final NestedJarHandler nestedJarHandler)

Constructor.

Parameters
length:long

the length

isDeflatedZipEntry:boolean

true if this is a deflated zip entry

inflatedLengthHint:long

the uncompressed size of a deflated zip entry, or -1 if unknown, or 0 of this is not a deflated zip entry.

nestedJarHandler:NestedJarHandler

the nested jar handler

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
equalsback to summary
public boolean equals(final Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
loadback to summary
public abstract byte[] load() throws IOException

Load the slice as a byte array.

Returns:byte[]

the byte[]

Exceptions
IOException:
Signals that an I/O exception has occurred.
loadAsStringback to summary
public String loadAsString() throws IOException

Load the slice as a string.

Returns:String

the string

Exceptions
IOException:
if slice cannot be read.
openback to summary
public InputStream open() throws IOException

Open this Slice as an InputStream.

Returns:InputStream

the input stream

Exceptions
IOException:
if an inflater cannot be created for this Slice.
openback to summary
public InputStream open(final Resource resourceToClose) throws IOException

Open this Slice as an InputStream.

Parameters
resourceToClose:Resource

the Resource to close when the returned InputStream is closed, or null if none.

Returns:InputStream

the input stream

Exceptions
IOException:
if an inflater cannot be created for this Slice.
randomAccessReaderback to summary
public abstract RandomAccessReader randomAccessReader()

Create a new RandomAccessReader for this Slice.

Returns:RandomAccessReader

the random access reader

readback to summary
public ByteBuffer read() throws IOException

Read the slice into a ByteBuffer.

Returns:ByteBuffer

the byte buffer

Exceptions
IOException:
Signals that an I/O exception has occurred.
sliceback to summary
public abstract Slice slice(long offset, long length, boolean isDeflatedZipEntry, final long inflatedLengthHint)

Get a child Slice from this parent Slice. The child slice must be smaller than the parent slice, and completely contained within it.

Parameters
offset:long

The offset to start slicing from, relative to this parent slice's start position.

length:long

The length of the slice.

isDeflatedZipEntry:boolean

true if this is a deflated zip entry

inflatedLengthHint:long

the uncompressed size of a deflated zip entry, or -1 if unknown, or 0 of this is not a deflated zip entry.

Returns:Slice

The child slice.