Class FileSlice
- java.lang.Object
-
- nonapi.io.github.classgraph.fileslice.Slice
-
- nonapi.io.github.classgraph.fileslice.FileSlice
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class FileSlice extends Slice
AFile
slice.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBuffer
backingByteBuffer
The backing byte buffer, if any.java.io.File
file
TheFile
.private java.nio.channels.FileChannel
fileChannel
The file channel.private long
fileLength
The file length.private java.util.concurrent.atomic.AtomicBoolean
isClosed
True ifclose()
has been called.private boolean
isTopLevelFileSlice
True if this is a top level file slice.java.io.RandomAccessFile
raf
TheRandomAccessFile
opened on theFile
.-
Fields inherited from class nonapi.io.github.classgraph.fileslice.Slice
inflatedLengthHint, isDeflatedZipEntry, nestedJarHandler, parentSlice, sliceLength, sliceStartPos
-
-
Constructor Summary
Constructors Modifier Constructor Description FileSlice(java.io.File file, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler, LogNode log)
Constructor for toplevel file slice.FileSlice(java.io.File file, NestedJarHandler nestedJarHandler, LogNode log)
Constructor for toplevel file slice.private
FileSlice(FileSlice parentSlice, long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler)
Constructor for treating a range of a file as a slice.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the slice.boolean
equals(java.lang.Object o)
int
hashCode()
byte[]
load()
Load the slice as a byte array.RandomAccessReader
randomAccessReader()
Read directly from FileChannel (slow path, but handles >2GB).java.nio.ByteBuffer
read()
Read the slice into aByteBuffer
(or memory-map the slice to aMappedByteBuffer
, ifClassGraph.enableMemoryMapping()
was called.)Slice
slice(long offset, long length, boolean isDeflatedZipEntry, long inflatedLengthHint)
Slice the file.-
Methods inherited from class nonapi.io.github.classgraph.fileslice.Slice
loadAsString, open, open
-
-
-
-
Field Detail
-
file
public final java.io.File file
TheFile
.
-
raf
public java.io.RandomAccessFile raf
TheRandomAccessFile
opened on theFile
.
-
fileLength
private final long fileLength
The file length.
-
fileChannel
private java.nio.channels.FileChannel fileChannel
The file channel.
-
backingByteBuffer
private java.nio.ByteBuffer backingByteBuffer
The backing byte buffer, if any.
-
isTopLevelFileSlice
private final boolean isTopLevelFileSlice
True if this is a top level file slice.
-
isClosed
private final java.util.concurrent.atomic.AtomicBoolean isClosed
True ifclose()
has been called.
-
-
Constructor Detail
-
FileSlice
private FileSlice(FileSlice 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 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
-
FileSlice
public FileSlice(java.io.File file, boolean isDeflatedZipEntry, long inflatedLengthHint, NestedJarHandler nestedJarHandler, LogNode log) throws java.io.IOException
Constructor for toplevel file slice.- Parameters:
file
- the fileisDeflatedZipEntry
- 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 handlerlog
- the log- Throws:
java.io.IOException
- if the file cannot be opened.
-
FileSlice
public FileSlice(java.io.File file, NestedJarHandler nestedJarHandler, LogNode log) throws java.io.IOException
Constructor for toplevel file slice.- Parameters:
file
- the filenestedJarHandler
- the nested jar handlerlog
- the log- 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 classSlice
- Parameters:
offset
- 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.- Returns:
- the slice
-
randomAccessReader
public RandomAccessReader randomAccessReader()
Read directly from FileChannel (slow path, but handles >2GB).- Specified by:
randomAccessReader
in classSlice
- Returns:
- the random access reader
-
load
public byte[] load() throws java.io.IOException
Load the slice as a byte array.
-
read
public java.nio.ByteBuffer read() throws java.io.IOException
Read the slice into aByteBuffer
(or memory-map the slice to aMappedByteBuffer
, ifClassGraph.enableMemoryMapping()
was called.)
-
-