Interface ClassReader
- All Superinterfaces:
- ConstantPool,- Iterable<PoolEntry>
Advanced 
class file reading support for AttributeMappers.
 Supports reading arbitrary offsets within a class file and reading
 data of various numeric types (e.g., u2, u4) in addition to
 constant pool access.
 
 All numeric values in the class file format are big endian.
 
 Unless otherwise specified, all out-of-bounds access result in an IllegalArgumentException to indicate the class file data is
 malformed.  Since the class file data is arbitrary, users should
 sanity-check the structural integrity of the data before attempting to
 interpret the potentially malformed data.
- Since:
- 24
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionintReturns the length of theclassfile, in number of bytes.voidcopyBytesTo(BufWriter buf, int offset, int len) Copy a range of bytes from theclassfile to aBufWriter.Returns the table of custom attribute mappers.intflags()Returns the access flags for the class, as a bit mask.byte[]readBytes(int offset, int len) Returns a copy of the bytes at the specified range in theclassfile.doublereadDouble(int offset) Returns the double value at the specified offset within theclassfile.readEntry(int offset) Returns the constant pool entry whose index is given at the specified offset within theclassfile.<T extends PoolEntry>
 TReturns the constant pool entry of a given type whose index is given at the specified offset within theclassfile.readEntryOrNull(int offset) Returns the constant pool entry whose index is given at the specified offset within theclassfile, ornullif the index at the specified offset is zero.<T extends PoolEntry>
 TreadEntryOrNull(int offset, Class<T> cls) Returns the constant pool entry of a given type whose index is given at the specified offset within theclassfile, ornullif the index at the specified offset is zero.floatreadFloat(int offset) Returns the float value at the specified offset within theclassfile.intreadInt(int offset) Returns the signed int at the specified offset within theclassfile.longreadLong(int offset) Returns the signed long at the specified offset within theclassfile.intreadS1(int offset) Returns the signed byte at the specified offset within theclassfile.intreadS2(int offset) Returns the signed byte at the specified offset within theclassfile.intreadU1(int offset) Returns the unsigned byte at the specified offset within theclassfile.intreadU2(int offset) Returns the unsigned short at the specified offset within theclassfile.Returns the constant pool entry describing the name of the superclass, if any.Returns the constant pool entry describing the name of class.Methods declared in interface java.lang.classfile.constantpool.ConstantPoolbootstrapMethodCount, bootstrapMethodEntry, entryByIndex, entryByIndex, iterator, sizeMethods declared in interface java.lang.IterableforEach, spliterator
- 
Method Details- 
customAttributesFunction<Utf8Entry, AttributeMapper<?>> customAttributes()Returns the table of custom attribute mappers. This is derived from the processing optionClassFile.AttributeMapperOption.- Returns:
- the table of custom attribute mappers
 
- 
flagsint flags()Returns the access flags for the class, as a bit mask.- Returns:
- the access flags for the class, as a bit mask
- See Also:
 
- 
thisClassEntryClassEntry thisClassEntry()Returns the constant pool entry describing the name of class.- Returns:
- the constant pool entry describing the name of class
- See Also:
 
- 
superclassEntryOptional<ClassEntry> superclassEntry()Returns the constant pool entry describing the name of the superclass, if any.- Returns:
- the constant pool entry describing the name of the superclass, if any
- See Also:
 
- 
classfileLengthint classfileLength()Returns the length of theclassfile, in number of bytes.- Returns:
- the length of the classfile, in number of bytes
 
- 
readEntryReturns the constant pool entry whose index is given at the specified offset within theclassfile.- API Note:
- If only a particular type of entry is expected, use readEntry(int, Class).
- Parameters:
- offset- the offset of the index within the- classfile
- Returns:
- the constant pool entry whose index is given at the specified
 offset within the classfile
- Throws:
- ConstantPoolException- if the index is out of range of the constant pool size, or zero
 
- 
readEntryReturns the constant pool entry of a given type whose index is given at the specified offset within theclassfile.- Type Parameters:
- T- the entry type
- Parameters:
- offset- the offset of the index within the- classfile
- cls- the entry type
- Returns:
- the constant pool entry of a given type whose index is given
 at the specified offset within the classfile
- Throws:
- ConstantPoolException- if the index is out of range of the constant pool size, or zero, or the entry is not of the given type
 
- 
readEntryOrNullReturns the constant pool entry whose index is given at the specified offset within theclassfile, ornullif the index at the specified offset is zero.- API Note:
- If only a particular type of entry is expected, use readEntryOrNull(int, Class).
- Parameters:
- offset- the offset of the index within the- classfile
- Returns:
- the constant pool entry whose index is given at the specified
 offset within the classfile, ornullif the index at the specified offset is zero
- Throws:
- ConstantPoolException- if the index is out of range of the constant pool size
 
- 
readEntryOrNullReturns the constant pool entry of a given type whose index is given at the specified offset within theclassfile, ornullif the index at the specified offset is zero.- Type Parameters:
- T- the entry type
- Parameters:
- offset- the offset of the index within the- classfile
- cls- the entry type
- Returns:
- the constant pool entry of a given type whose index is given
 at the specified offset within the classfile, ornullif the index at the specified offset is zero
- Throws:
- ConstantPoolException- if the index is out of range of the constant pool size, or zero, or the entry is not of the given type
 
- 
readU1int readU1(int offset) Returns the unsigned byte at the specified offset within theclassfile. Reads a byte and zero-extends it to anint.- Parameters:
- offset- the offset within the- classfile
- Returns:
- the unsigned byte at the specified offset within the classfile
 
- 
readU2int readU2(int offset) Returns the unsigned short at the specified offset within theclassfile. Reads a 2-byte value and zero-extends it to anint.- Parameters:
- offset- the offset within the- classfile
- Returns:
- the unsigned short at the specified offset within the classfile
 
- 
readS1int readS1(int offset) Returns the signed byte at the specified offset within theclassfile. Reads a byte and sign-extends it to anint.- Parameters:
- offset- the offset within the- classfile
- Returns:
- the signed byte at the specified offset within the classfile
 
- 
readS2int readS2(int offset) Returns the signed byte at the specified offset within theclassfile. Reads a 2-byte value and sign-extends it to anint.- Parameters:
- offset- the offset within the- classfile
- Returns:
- the signed byte at the specified offset within the classfile
 
- 
readIntint readInt(int offset) Returns the signed int at the specified offset within theclassfile. Reads 4 bytes of value.- Parameters:
- offset- the offset within the- classfile
- Returns:
- the signed int at the specified offset within the classfile
 
- 
readLonglong readLong(int offset) Returns the signed long at the specified offset within theclassfile. Reads 8 bytes of value.- Parameters:
- offset- the offset within the- classfile
- Returns:
- the signed long at the specified offset within the classfile
 
- 
readFloatfloat readFloat(int offset) Returns the float value at the specified offset within theclassfile. Reads 4 bytes of value.In the conversions, all NaN values of the floatmay or may not be collapsed into a single "canonical" NaN value.- Parameters:
- offset- the offset within the- classfile
- Returns:
- the float value at the specified offset within the classfile
 
- 
readDoubledouble readDouble(int offset) Returns the double value at the specified offset within theclassfile. Reads 8 bytes of value.In the conversions, all NaN values of the doublemay or may not be collapsed into a single "canonical" NaN value.- Parameters:
- offset- the offset within the- classfile
- Returns:
- the double value at the specified offset within the classfile
 
- 
readBytesbyte[] readBytes(int offset, int len) Returns a copy of the bytes at the specified range in theclassfile.- Parameters:
- offset- the offset within the- classfile
- len- the length of the range
- Returns:
- a copy of the bytes at the specified range in the classfile
 
- 
copyBytesTo
 
-