Class PathSlice

java.lang.Object
nonapi.io.github.classgraph.fileslice.Slice
nonapi.io.github.classgraph.fileslice.PathSlice
All Implemented Interfaces:
Closeable, AutoCloseable

public class PathSlice extends Slice
A Path slice.
  • Field Details

    • path

      public final Path path
      The Path.
    • fileLength

      private final long fileLength
      The file length.
    • fileChannel

      private FileChannel fileChannel
      The FileChannel opened on the Path.
    • isTopLevelFileSlice

      private final boolean isTopLevelFileSlice
      True if this is a top level file slice.
    • isClosed

      private final AtomicBoolean isClosed
      True if close() has been called.
  • Constructor Details

    • PathSlice

      private PathSlice(PathSlice parentSlice, long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler)
      Constructor for treating a range of a file as a 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
    • PathSlice

      public PathSlice(Path path, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler) throws IOException
      Constructor for toplevel file slice.
      Parameters:
      path - the path
      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
      Throws:
      IOException - if the file cannot be opened.
    • PathSlice

      public PathSlice(Path path, NestedJarHandler nestedJarHandler) throws IOException
      Constructor for toplevel file slice.
      Parameters:
      path - the path
      nestedJarHandler - the nested jar handler
      Throws:
      IOException - if the file cannot be opened.
  • Method Details

    • slice

      public Slice slice(long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint)
      Slice the file.
      Specified by:
      slice in class Slice
      Parameters:
      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.
      Returns:
      the slice
    • randomAccessReader

      public RandomAccessReader randomAccessReader()
      Read directly from FileChannel (slow path, but handles >2GB).
      Specified by:
      randomAccessReader in class Slice
      Returns:
      the random access reader
    • load

      public byte[] load() throws IOException
      Load the slice as a byte array.
      Specified by:
      load in class Slice
      Returns:
      the byte[]
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • read

      public ByteBuffer read() throws IOException
      Read the slice into a ByteBuffer (or memory-map the slice to a MappedByteBuffer, if ClassGraph.enableMemoryMapping() was called.)
      Overrides:
      read in class Slice
      Returns:
      the byte buffer
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Slice
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Slice
    • close

      public void close()
      Close the slice. Unmaps any backing MappedByteBuffer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class Slice