Class RandomAccessFileChannelReader
- java.lang.Object
-
- nonapi.io.github.classgraph.fileslice.reader.RandomAccessFileChannelReader
-
- All Implemented Interfaces:
RandomAccessReader
public class RandomAccessFileChannelReader extends java.lang.Object implements RandomAccessReader
RandomAccessReaderfor aFile. Reads in little endian order, as required by the zipfile format.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.channels.FileChannelfileChannelThe file channel.private java.nio.ByteBufferreusableByteBufferThe reusable byte buffer.private byte[]scratchArrThe scratch arr.private java.nio.ByteBufferscratchByteBufThe scratch byte buf.private longsliceLengthThe slice length.private longsliceStartPosThe slice start pos.private byte[]utf8BytesThe utf 8 bytes.
-
Constructor Summary
Constructors Constructor Description RandomAccessFileChannelReader(java.nio.channels.FileChannel fileChannel, long sliceStartPos, long sliceLength)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intread(long srcOffset, byte[] dstArr, int dstArrStart, int numBytes)Read bytes into a byte array.intread(long srcOffset, java.nio.ByteBuffer dstBuf, int dstBufStart, int numBytes)Read bytes into aByteBuffer.bytereadByte(long offset)Read a byte at a specific offset (without changing the current cursor offset).intreadInt(long offset)Read a int at a specific offset (without changing the current cursor offset).longreadLong(long offset)Read a long at a specific offset (without changing the current cursor offset).shortreadShort(long offset)Read a short at a specific offset (without changing the current cursor offset).java.lang.StringreadString(long offset, int numBytes)Reads the "modified UTF8" format defined in the Java classfile spec.java.lang.StringreadString(long offset, int numBytes, boolean replaceSlashWithDot, boolean stripLSemicolon)Reads the "modified UTF8" format defined in the Java classfile spec, optionally replacing '/' with '.', and optionally removing the prefix "L" and the suffix ";".intreadUnsignedByte(long offset)Read an unsigned byte at a specific offset (without changing the current cursor offset).longreadUnsignedInt(long offset)Read a unsigned int at a specific offset (without changing the current cursor offset).intreadUnsignedShort(long offset)Read a unsigned short at a specific offset (without changing the current cursor offset).
-
-
-
Field Detail
-
fileChannel
private final java.nio.channels.FileChannel fileChannel
The file channel.
-
sliceStartPos
private final long sliceStartPos
The slice start pos.
-
sliceLength
private final long sliceLength
The slice length.
-
reusableByteBuffer
private java.nio.ByteBuffer reusableByteBuffer
The reusable byte buffer.
-
scratchArr
private final byte[] scratchArr
The scratch arr.
-
scratchByteBuf
private final java.nio.ByteBuffer scratchByteBuf
The scratch byte buf.
-
utf8Bytes
private byte[] utf8Bytes
The utf 8 bytes.
-
-
Method Detail
-
read
public int read(long srcOffset, java.nio.ByteBuffer dstBuf, int dstBufStart, int numBytes) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderRead bytes into aByteBuffer.- Specified by:
readin interfaceRandomAccessReader- Parameters:
srcOffset- The offset to start reading from.dstBuf- TheByteBufferto write into.dstBufStart- The offset within the destination buffer to start writing at.numBytes- The number of bytes to read.- Returns:
- The number of bytes actually read, or -1 if no more bytes could be read.
- Throws:
java.io.IOException- If there was an exception while reading.
-
read
public int read(long srcOffset, byte[] dstArr, int dstArrStart, int numBytes) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderRead bytes into a byte array.- Specified by:
readin interfaceRandomAccessReader- Parameters:
srcOffset- The offset to start reading from.dstArr- The byte array to write into.dstArrStart- The offset within the destination array to start writing at.numBytes- The number of bytes to read.- Returns:
- The number of bytes actually read, or -1 if no more bytes could be read.
- Throws:
java.io.IOException- If there was an exception while reading.
-
readByte
public byte readByte(long offset) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderRead a byte at a specific offset (without changing the current cursor offset).- Specified by:
readBytein interfaceRandomAccessReader- Parameters:
offset- The buffer offset to read from.- Returns:
- The byte at the offset.
- Throws:
java.io.IOException- If there was an exception while reading.
-
readUnsignedByte
public int readUnsignedByte(long offset) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderRead an unsigned byte at a specific offset (without changing the current cursor offset).- Specified by:
readUnsignedBytein interfaceRandomAccessReader- Parameters:
offset- The buffer offset to read from.- Returns:
- The unsigned byte at the offset.
- Throws:
java.io.IOException- If there was an exception while reading.
-
readShort
public short readShort(long offset) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderRead a short at a specific offset (without changing the current cursor offset).- Specified by:
readShortin interfaceRandomAccessReader- Parameters:
offset- The buffer offset to read from.- Returns:
- The short at the offset.
- Throws:
java.io.IOException- If there was an exception while reading.
-
readUnsignedShort
public int readUnsignedShort(long offset) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderRead a unsigned short at a specific offset (without changing the current cursor offset).- Specified by:
readUnsignedShortin interfaceRandomAccessReader- Parameters:
offset- The buffer offset to read from.- Returns:
- The unsigned short at the offset.
- Throws:
java.io.IOException- If there was an exception while reading.
-
readInt
public int readInt(long offset) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderRead a int at a specific offset (without changing the current cursor offset).- Specified by:
readIntin interfaceRandomAccessReader- Parameters:
offset- The buffer offset to read from.- Returns:
- The int at the offset.
- Throws:
java.io.IOException- If there was an exception while reading.
-
readUnsignedInt
public long readUnsignedInt(long offset) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderRead a unsigned int at a specific offset (without changing the current cursor offset).- Specified by:
readUnsignedIntin interfaceRandomAccessReader- Parameters:
offset- The buffer offset to read from.- Returns:
- The int at the offset, as a long.
- Throws:
java.io.IOException- If there was an exception while reading.
-
readLong
public long readLong(long offset) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderRead a long at a specific offset (without changing the current cursor offset).- Specified by:
readLongin interfaceRandomAccessReader- Parameters:
offset- The buffer offset to read from.- Returns:
- The long at the offset.
- Throws:
java.io.IOException- If there was an exception while reading.
-
readString
public java.lang.String readString(long offset, int numBytes, boolean replaceSlashWithDot, boolean stripLSemicolon) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderReads the "modified UTF8" format defined in the Java classfile spec, optionally replacing '/' with '.', and optionally removing the prefix "L" and the suffix ";".- Specified by:
readStringin interfaceRandomAccessReader- Parameters:
offset- The start offset of the string.numBytes- The number of bytes of the UTF8 encoding of the string.replaceSlashWithDot- If true, replace '/' with '.'.stripLSemicolon- If true, string final ';' character.- Returns:
- The string.
- Throws:
java.io.IOException- If an I/O exception occurs.
-
readString
public java.lang.String readString(long offset, int numBytes) throws java.io.IOExceptionDescription copied from interface:RandomAccessReaderReads the "modified UTF8" format defined in the Java classfile spec.- Specified by:
readStringin interfaceRandomAccessReader- Parameters:
offset- The start offset of the string.numBytes- The number of bytes of the UTF8 encoding of the string.- Returns:
- The string.
- Throws:
java.io.IOException- If an I/O exception occurs.
-
-