Class PathSlice

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

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

      • path

        public final java.nio.file.Path path
        The Path.
      • fileLength

        private final long fileLength
        The file length.
      • fileChannel

        private java.nio.channels.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 java.util.concurrent.atomic.AtomicBoolean isClosed
        True if close() has been called.
    • Constructor Detail

      • 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​(java.nio.file.Path path,
                         boolean isDeflatedZipEntry,
                         long inflatedLengthHint,
                         NestedJarHandler nestedJarHandler)
                  throws java.io.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:
        java.io.IOException - if the file cannot be opened.
      • PathSlice

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

      • 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 java.io.IOException
        Load the slice as a byte array.
        Specified by:
        load in class Slice
        Returns:
        the byte[]
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • read

        public java.nio.ByteBuffer read()
                                 throws java.io.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:
        java.io.IOException - Signals that an I/O exception has occurred.
      • equals

        public boolean equals​(java.lang.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 java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class Slice