public class ClassfileReader extends java.lang.Object implements RandomAccessReader, SequentialReader, java.io.Closeable
Slice reader that works as either a RandomAccessReader or a SequentialReader. The file
is buffered up to the point it has been read so far. Reads in big endian order, as required by the
classfile format.| Constructor and Description |
|---|
ClassfileReader(java.io.InputStream inputStream,
Resource resourceToClose)
Constructor for reader of module
InputStream (which is not deflated). |
ClassfileReader(Slice slice,
Resource resourceToClose)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
buf()
Buf.
|
void |
bufferTo(int numBytes)
Ensure that the given number of bytes have been read into the buffer from the beginning of the slice.
|
void |
close() |
int |
currPos()
Curr pos.
|
int |
read(long srcOffset,
byte[] dstArr,
int dstArrStart,
int numBytes)
Read bytes into a byte array.
|
int |
read(long srcOffset,
java.nio.ByteBuffer dstBuf,
int dstBufStart,
int numBytes)
Read bytes into a
ByteBuffer. |
byte |
readByte()
Read a byte at the current cursor position.
|
byte |
readByte(long offset)
Read a byte at a specific offset (without changing the current cursor offset).
|
int |
readInt()
Read a int at the current cursor position.
|
int |
readInt(long offset)
Read a int at a specific offset (without changing the current cursor offset).
|
long |
readLong()
Read a long at the current cursor position.
|
long |
readLong(long offset)
Read a long at a specific offset (without changing the current cursor offset).
|
short |
readShort()
Read a short at the current cursor position.
|
short |
readShort(long offset)
Read a short at a specific offset (without changing the current cursor offset).
|
java.lang.String |
readString(int numBytes)
Reads the "modified UTF8" format defined in the Java classfile spec.
|
java.lang.String |
readString(int numBytes,
boolean replaceSlashWithDot,
boolean stripLSemicolon)
Reads the "modified UTF8" format defined in the Java classfile spec, optionally replacing '/' with '
|
java.lang.String |
readString(long offset,
int numBytes)
Reads the "modified UTF8" format defined in the Java classfile spec.
|
java.lang.String |
readString(long offset,
int numBytes,
boolean replaceSlashWithDot,
boolean stripLSemicolon)
Reads the "modified UTF8" format defined in the Java classfile spec, optionally replacing '/' with '
|
int |
readUnsignedByte()
Read an unsigned byte at the current cursor position.
|
int |
readUnsignedByte(long offset)
Read an unsigned byte at a specific offset (without changing the current cursor offset).
|
long |
readUnsignedInt()
Read a unsigned int at the current cursor position.
|
long |
readUnsignedInt(long offset)
Read a unsigned int at a specific offset (without changing the current cursor offset).
|
int |
readUnsignedShort()
Read a unsigned short at the current cursor position.
|
int |
readUnsignedShort(long offset)
Read a unsigned short at a specific offset (without changing the current cursor offset).
|
void |
skip(int bytesToSkip)
Skip the given number of bytes.
|
public ClassfileReader(Slice slice, Resource resourceToClose) throws java.io.IOException
public ClassfileReader(java.io.InputStream inputStream,
Resource resourceToClose)
throws java.io.IOException
InputStream (which is not deflated).public int currPos()
public byte[] buf()
public void bufferTo(int numBytes)
throws java.io.IOException
numBytes - the number of bytes to ensure have been bufferedjava.io.IOException - on EOF or if the bytes could not be read.public int read(long srcOffset,
byte[] dstArr,
int dstArrStart,
int numBytes)
throws java.io.IOException
RandomAccessReaderread in interface RandomAccessReadersrcOffset - 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.java.io.IOException - If there was an exception while reading.public int read(long srcOffset,
java.nio.ByteBuffer dstBuf,
int dstBufStart,
int numBytes)
throws java.io.IOException
RandomAccessReaderByteBuffer.read in interface RandomAccessReadersrcOffset - The offset to start reading from.dstBuf - The ByteBuffer to write into.dstBufStart - The offset within the destination buffer to start writing at.numBytes - The number of bytes to read.java.io.IOException - If there was an exception while reading.public byte readByte(long offset)
throws java.io.IOException
RandomAccessReaderreadByte in interface RandomAccessReaderoffset - The buffer offset to read from.java.io.IOException - If there was an exception while reading.public int readUnsignedByte(long offset)
throws java.io.IOException
RandomAccessReaderreadUnsignedByte in interface RandomAccessReaderoffset - The buffer offset to read from.java.io.IOException - If there was an exception while reading.public short readShort(long offset)
throws java.io.IOException
RandomAccessReaderreadShort in interface RandomAccessReaderoffset - The buffer offset to read from.java.io.IOException - If there was an exception while reading.public int readUnsignedShort(long offset)
throws java.io.IOException
RandomAccessReaderreadUnsignedShort in interface RandomAccessReaderoffset - The buffer offset to read from.java.io.IOException - If there was an exception while reading.public int readInt(long offset)
throws java.io.IOException
RandomAccessReaderreadInt in interface RandomAccessReaderoffset - The buffer offset to read from.java.io.IOException - If there was an exception while reading.public long readUnsignedInt(long offset)
throws java.io.IOException
RandomAccessReaderreadUnsignedInt in interface RandomAccessReaderoffset - The buffer offset to read from.java.io.IOException - If there was an exception while reading.public long readLong(long offset)
throws java.io.IOException
RandomAccessReaderreadLong in interface RandomAccessReaderoffset - The buffer offset to read from.java.io.IOException - If there was an exception while reading.public byte readByte()
throws java.io.IOException
SequentialReaderreadByte in interface SequentialReaderjava.io.IOException - If there was an exception while reading.public int readUnsignedByte()
throws java.io.IOException
SequentialReaderreadUnsignedByte in interface SequentialReaderjava.io.IOException - If there was an exception while reading.public short readShort()
throws java.io.IOException
SequentialReaderreadShort in interface SequentialReaderjava.io.IOException - If there was an exception while reading.public int readUnsignedShort()
throws java.io.IOException
SequentialReaderreadUnsignedShort in interface SequentialReaderjava.io.IOException - If there was an exception while reading.public int readInt()
throws java.io.IOException
SequentialReaderreadInt in interface SequentialReaderjava.io.IOException - If there was an exception while reading.public long readUnsignedInt()
throws java.io.IOException
SequentialReaderreadUnsignedInt in interface SequentialReaderjava.io.IOException - If there was an exception while reading.public long readLong()
throws java.io.IOException
SequentialReaderreadLong in interface SequentialReaderjava.io.IOException - If there was an exception while reading.public void skip(int bytesToSkip)
throws java.io.IOException
SequentialReaderskip in interface SequentialReaderbytesToSkip - The number of bytes to skip.java.io.IOException - If there was an exception while reading.public java.lang.String readString(long offset,
int numBytes,
boolean replaceSlashWithDot,
boolean stripLSemicolon)
throws java.io.IOException
RandomAccessReaderreadString in interface RandomAccessReaderoffset - 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.java.io.IOException - If an I/O exception occurs.public java.lang.String readString(int numBytes,
boolean replaceSlashWithDot,
boolean stripLSemicolon)
throws java.io.IOException
SequentialReaderreadString in interface SequentialReadernumBytes - The number of bytes of the UTF8 encoding of the string.replaceSlashWithDot - If true, replace '/' with '.'.stripLSemicolon - If true, string final ';' character.java.io.IOException - If an I/O exception occurs.public java.lang.String readString(long offset,
int numBytes)
throws java.io.IOException
RandomAccessReaderreadString in interface RandomAccessReaderoffset - The start offset of the string.numBytes - The number of bytes of the UTF8 encoding of the string.java.io.IOException - If an I/O exception occurs.public java.lang.String readString(int numBytes)
throws java.io.IOException
SequentialReaderreadString in interface SequentialReadernumBytes - The number of bytes of the UTF8 encoding of the string.java.io.IOException - If an I/O exception occurs.public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseable