Class ClassReader

  • All Implemented Interfaces:
    ClassConstants

    public final class ClassReader
    extends Object
    implements ClassConstants
    This is the core class for reading class file data. ClassReader performs lazy parsing, and thus most of the methods can throw an InvalidClassFileException.
    • Constructor Detail

      • ClassReader

        public ClassReader​(byte[] bytes)
                    throws InvalidClassFileException
        Build a reader. If the class file data is corrupt an exception might not be thrown immediately. Instead an exception might be thrown later, during the execution of some access method. This is a consequence of the 'lazy parsing' performed by ClassReader.
        Parameters:
        bytes - the class file data
        Throws:
        InvalidClassFileException - the class file data is corrupt
    • Method Detail

      • getBytes

        public byte[] getBytes()
        Returns:
        the raw class data bytes
      • getMagic

        public int getMagic()
        Returns:
        the magic number at the start of the class file.
      • getMinorVersion

        public int getMinorVersion()
        Returns:
        the minor version of the class file
      • getMajorVersion

        public int getMajorVersion()
        Returns:
        the major version of the class file
      • getAccessFlags

        public int getAccessFlags()
        Returns:
        the access flags for the class
      • getNameIndex

        public int getNameIndex()
        Returns:
        the index of the constant pool entry for the class name
      • getSuperNameIndex

        public int getSuperNameIndex()
        Returns:
        the constant pool index of the superclass name, or 0 if this is java.lang.Object
      • getInterfaceCount

        public int getInterfaceCount()
        Returns:
        the number of interfaces this class implements
      • getInterfaceNameIndex

        public int getInterfaceNameIndex​(int i)
        Returns:
        the constant pool index of the name of the i'th implemented interface
      • getInterfaceNameIndices

        public int[] getInterfaceNameIndices()
        Returns:
        an array of the constant pool indices for the names of the implemented interfaces
      • getCP

        public ConstantPoolParser getCP()
        This method allows direct read-only access to the constant pool for the class.
        Returns:
        the constant pool for the class
      • getInt

        public int getInt​(int i)
        Returns:
        the signed 32-bit value at offset i in the class data
      • getUShort

        public int getUShort​(int i)
        Returns:
        the unsigned 16-bit value at offset i in the class data
      • getShort

        public int getShort​(int i)
        Returns:
        the signed 16-bit value at offset i in the class data
      • getByte

        public byte getByte​(int i)
        Returns:
        the signed 8-bit value at offset i in the class data
      • getFieldCount

        public int getFieldCount()
        Returns:
        the number of fields in the class
      • getFieldAccessFlags

        public int getFieldAccessFlags​(int f)
        Returns:
        the access flags for the f'th field
      • getFieldNameIndex

        public int getFieldNameIndex​(int f)
        Returns:
        the index of the constant pool entry for the name of the f'th field, in JVM format (e.g., I, Z, Ljava/lang/Object;)
      • getFieldTypeIndex

        public int getFieldTypeIndex​(int f)
        Returns:
        the index of the constant pool entry for the type of the f'th field, in JVM format (e.g., I, Z, Ljava/lang/Object;)
      • getFieldRawOffset

        public int getFieldRawOffset​(int f)
        Returns:
        the offset of the raw class data for field f
      • getFieldRawSize

        public int getFieldRawSize​(int f)
        Returns:
        the size of the raw class data for field f
      • getMethodCount

        public int getMethodCount()
        Returns:
        the number of methods in the class
      • getMethodRawOffset

        public int getMethodRawOffset​(int m)
        Returns:
        the offset of the raw class data for method m
      • getMethodRawSize

        public int getMethodRawSize​(int m)
        Returns:
        the size of the raw class data for method m
      • getMethodAccessFlags

        public int getMethodAccessFlags​(int m)
        Returns:
        the access flags for method m
      • getMethodNameIndex

        public int getMethodNameIndex​(int m)
        Returns:
        the constant pool index of the name of method m
      • getMethodTypeIndex

        public int getMethodTypeIndex​(int m)
        Returns:
        the constant pool index of the method descriptor of method m