Class RandomAccessArrayReader
java.lang.Object
nonapi.io.github.classgraph.fileslice.reader.RandomAccessArrayReader
- All Implemented Interfaces:
RandomAccessReader
RandomAccessReader
backed by a byte array. Reads in little endian order, as required by the
zipfile format.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]
The array.private final int
The length of the slice within the array.private final int
The start index of the slice within the array. -
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessArrayReader
(byte[] arr, int sliceStartPos, int sliceLength) Constructor for slicing an array. -
Method Summary
Modifier and TypeMethodDescriptionint
read
(long srcOffset, byte[] dstArr, int dstArrStart, int numBytes) Read bytes into a byte array.int
read
(long srcOffset, ByteBuffer dstBuf, int dstBufStart, int numBytes) Read bytes into aByteBuffer
.byte
readByte
(long offset) Read a byte at a specific offset (without changing the current cursor offset).int
readInt
(long offset) Read a int at a specific offset (without changing the current cursor offset).long
readLong
(long offset) Read a long at a specific offset (without changing the current cursor offset).short
readShort
(long offset) Read a short at a specific offset (without changing the current cursor offset).readString
(long offset, int numBytes) Reads the "modified UTF8" format defined in the Java classfile spec.readString
(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 ";".int
readUnsignedByte
(long offset) Read an unsigned byte at a specific offset (without changing the current cursor offset).long
readUnsignedInt
(long offset) Read a unsigned int at a specific offset (without changing the current cursor offset).int
readUnsignedShort
(long offset) Read a unsigned short at a specific offset (without changing the current cursor offset).
-
Field Details
-
arr
private final byte[] arrThe array. -
sliceStartPos
private final int sliceStartPosThe start index of the slice within the array. -
sliceLength
private final int sliceLengthThe length of the slice within the array.
-
-
Constructor Details
-
RandomAccessArrayReader
public RandomAccessArrayReader(byte[] arr, int sliceStartPos, int sliceLength) Constructor for slicing an array.- Parameters:
arr
- the array to slice.sliceStartPos
- the start index of the slice within the array.sliceLength
- the length of the slice within the array.
-
-
Method Details
-
read
Description copied from interface:RandomAccessReader
Read bytes into a byte array.- Specified by:
read
in 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:
IOException
- If there was an exception while reading.
-
read
public int read(long srcOffset, ByteBuffer dstBuf, int dstBufStart, int numBytes) throws IOException Description copied from interface:RandomAccessReader
Read bytes into aByteBuffer
.- Specified by:
read
in interfaceRandomAccessReader
- Parameters:
srcOffset
- The offset to start reading from.dstBuf
- TheByteBuffer
to 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:
IOException
- If there was an exception while reading.
-
readByte
Description copied from interface:RandomAccessReader
Read a byte at a specific offset (without changing the current cursor offset).- Specified by:
readByte
in interfaceRandomAccessReader
- Parameters:
offset
- The buffer offset to read from.- Returns:
- The byte at the offset.
- Throws:
IOException
- If there was an exception while reading.
-
readUnsignedByte
Description copied from interface:RandomAccessReader
Read an unsigned byte at a specific offset (without changing the current cursor offset).- Specified by:
readUnsignedByte
in interfaceRandomAccessReader
- Parameters:
offset
- The buffer offset to read from.- Returns:
- The unsigned byte at the offset.
- Throws:
IOException
- If there was an exception while reading.
-
readShort
Description copied from interface:RandomAccessReader
Read a short at a specific offset (without changing the current cursor offset).- Specified by:
readShort
in interfaceRandomAccessReader
- Parameters:
offset
- The buffer offset to read from.- Returns:
- The short at the offset.
- Throws:
IOException
- If there was an exception while reading.
-
readUnsignedShort
Description copied from interface:RandomAccessReader
Read a unsigned short at a specific offset (without changing the current cursor offset).- Specified by:
readUnsignedShort
in interfaceRandomAccessReader
- Parameters:
offset
- The buffer offset to read from.- Returns:
- The unsigned short at the offset.
- Throws:
IOException
- If there was an exception while reading.
-
readInt
Description copied from interface:RandomAccessReader
Read a int at a specific offset (without changing the current cursor offset).- Specified by:
readInt
in interfaceRandomAccessReader
- Parameters:
offset
- The buffer offset to read from.- Returns:
- The int at the offset.
- Throws:
IOException
- If there was an exception while reading.
-
readUnsignedInt
Description copied from interface:RandomAccessReader
Read a unsigned int at a specific offset (without changing the current cursor offset).- Specified by:
readUnsignedInt
in interfaceRandomAccessReader
- Parameters:
offset
- The buffer offset to read from.- Returns:
- The int at the offset, as a long.
- Throws:
IOException
- If there was an exception while reading.
-
readLong
Description copied from interface:RandomAccessReader
Read a long at a specific offset (without changing the current cursor offset).- Specified by:
readLong
in interfaceRandomAccessReader
- Parameters:
offset
- The buffer offset to read from.- Returns:
- The long at the offset.
- Throws:
IOException
- If there was an exception while reading.
-
readString
public String readString(long offset, int numBytes, boolean replaceSlashWithDot, boolean stripLSemicolon) throws IOException Description copied from interface:RandomAccessReader
Reads the "modified UTF8" format defined in the Java classfile spec, optionally replacing '/' with '.', and optionally removing the prefix "L" and the suffix ";".- Specified by:
readString
in 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:
IOException
- If an I/O exception occurs.
-
readString
Description copied from interface:RandomAccessReader
Reads the "modified UTF8" format defined in the Java classfile spec.- Specified by:
readString
in 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:
IOException
- If an I/O exception occurs.
-