java.lang.Object
nonapi.io.github.classgraph.fileslice.Slice
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
ArraySlice, FileSlice, PathSlice

public abstract class Slice extends Object implements Closeable
A slice of a File, ByteBuffer or InputStream. A single Slice instance should only be used by a single thread.
  • Field Details

    • nestedJarHandler

      protected final NestedJarHandler nestedJarHandler
    • 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 (for InputStream).
    • 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 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 slice
      offset - the offset of the sub-slice within the parent slice
      length - the length of the sub-slice
      isDeflatedZipEntry - true if this is a deflated zip entry
      inflatedLengthHint - 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 length
      isDeflatedZipEntry - true if this is a deflated zip entry
      inflatedLengthHint - 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 child Slice from this parent Slice. 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 entry
      inflatedLengthHint - 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 InputStream open() throws IOException
      Open this Slice as an InputStream.
      Returns:
      the input stream
      Throws:
      IOException - if an inflater cannot be created for this Slice.
    • open

      public InputStream open(Resource resourceToClose) throws IOException
      Open this Slice as an InputStream.
      Parameters:
      resourceToClose - the Resource to close when the returned InputStream is closed, or null if none.
      Returns:
      the input stream
      Throws:
      IOException - if an inflater cannot be created for this Slice.
    • randomAccessReader

      public abstract RandomAccessReader randomAccessReader()
      Create a new RandomAccessReader for this Slice.
      Returns:
      the random access reader
    • load

      public abstract byte[] load() throws IOException
      Load the slice as a byte array.
      Returns:
      the byte[]
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • loadAsString

      public String loadAsString() throws IOException
      Load the slice as a string.
      Returns:
      the string
      Throws:
      IOException - if slice cannot be read.
    • read

      public ByteBuffer read() throws IOException
      Read the slice into a ByteBuffer.
      Returns:
      the byte buffer
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object