Class ClassReaderImpl

java.lang.Object
org.glavo.classfile.impl.ClassReaderImpl
All Implemented Interfaces:
ClassReader, ConstantPool

public final class ClassReaderImpl extends Object implements ClassReader
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of entries in the bootstrap method table.
    Returns the BootstrapMethodEntry at the specified index within the bootstrap method table.
    int
    Returns the length of the classfile, in bytes.
    boolean
    compare(BufWriter bufWriter, int bufWriterOffset, int classReaderOffset, int length)
    Compare a range of bytes from the classfile to a range of bytes within a BufWriter.
    void
    copyBytesTo(BufWriter buf, int p, int len)
    Copy a range of bytes from the classfile to a BufWriter
    Returns the table of custom attribute mappers.
    entryByIndex(int index)
    Returns the entry at the specified index.
    int
    Returns the number of entries in the constant pool.
    int
    Returns the access flags for the class, as a bit mask.
     
    byte[]
    readBytes(int p, int len)
    Returns a copy of the bytes at the specified range in the classfile.
    readClassEntry(int pos)
    Returns the class entry whose index is given at the specified offset within the classfile.
    double
    readDouble(int p)
    Returns the double value at the specified offset within the classfile.
    readEntry(int pos)
    Returns the constant pool entry whose index is given at the specified offset within the classfile.
    readEntryOrNull(int pos)
    Returns the constant pool entry whose index is given at the specified offset within the classfile, or null if the index at the specified offset is zero.
    float
    readFloat(int p)
    Returns the float value at the specified offset within the classfile.
    int
    readInt(int p)
    Returns the signed int at the specified offset within the classfile.
    long
    readLong(int p)
    Returns the signed long at the specified offset within the classfile.
    Returns the method handle entry whose index is given at the specified offset within the classfile.
    readModuleEntry(int pos)
    Returns the module entry whose index is given at the specified offset within the classfile.
    Returns the name-and-type entry whose index is given at the specified offset within the classfile.
    Returns the package entry whose index is given at the specified offset within the classfile.
    int
    readS1(int p)
    Returns the signed byte at the specified offset within the classfile.
    int
    readS2(int p)
    Returns the signed byte at the specified offset within the classfile.
    int
    readU1(int p)
    Returns the unsigned byte at the specified offset within the classfile.
    int
    readU2(int p)
    Returns the unsigned short at the specified offset within the classfile.
    readUtf8Entry(int pos)
    Returns the UTF8 entry whose index is given at the specified offset within the classfile.
    Returns the UTF8 entry whose index is given at the specified offset within the classfile, or null if the index at the specified offset is zero.
    int
    skipAttributeHolder(int offset)
    Returns the offset following the block of attributes starting at the specified position.
    Returns the constant pool entry describing the name of the superclass, if any.
    Returns the constant pool entry describing the name of class.
    int
    Returns the offset into the classfile of the this_class field.
    utf8EntryByIndex(int index)
    Returns the UTF8 constant pool entry at the given index of the constant pool.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • options

      public Options options()
    • customAttributes

      public Function<Utf8Entry,AttributeMapper<?>> customAttributes()
      Description copied from interface: ClassReader
      Returns the table of custom attribute mappers. This is derived from the processing option Classfile.Option.attributeMapper(Function).
      Specified by:
      customAttributes in interface ClassReader
      Returns:
      the table of custom attribute mappers
    • entryCount

      public int entryCount()
      Description copied from interface: ConstantPool
      Returns the number of entries in the constant pool.
      Specified by:
      entryCount in interface ConstantPool
      Returns:
      the number of entries in the constant pool
    • flags

      public int flags()
      Description copied from interface: ClassReader
      Returns the access flags for the class, as a bit mask .
      Specified by:
      flags in interface ClassReader
      Returns:
      the access flags for the class, as a bit mask
    • thisClassEntry

      public ClassEntry thisClassEntry()
      Description copied from interface: ClassReader
      Returns the constant pool entry describing the name of class.
      Specified by:
      thisClassEntry in interface ClassReader
      Returns:
      the constant pool entry describing the name of class
    • superclassEntry

      public Optional<ClassEntry> superclassEntry()
      Description copied from interface: ClassReader
      Returns the constant pool entry describing the name of the superclass, if any.
      Specified by:
      superclassEntry in interface ClassReader
      Returns:
      the constant pool entry describing the name of the superclass, if any
    • thisClassPos

      public int thisClassPos()
      Description copied from interface: ClassReader
      Returns the offset into the classfile of the this_class field.
      Specified by:
      thisClassPos in interface ClassReader
      Returns:
      the offset into the classfile of the this_class field
    • classfileLength

      public int classfileLength()
      Description copied from interface: ClassReader
      Returns the length of the classfile, in bytes.
      Specified by:
      classfileLength in interface ClassReader
      Returns:
      the length of the classfile, in bytes
    • bootstrapMethodCount

      public int bootstrapMethodCount()
      Description copied from interface: ConstantPool
      Returns the number of entries in the bootstrap method table.
      Specified by:
      bootstrapMethodCount in interface ConstantPool
      Returns:
      the number of entries in the bootstrap method table
    • bootstrapMethodEntry

      public BootstrapMethodEntryImpl bootstrapMethodEntry(int index)
      Description copied from interface: ConstantPool
      Returns the BootstrapMethodEntry at the specified index within the bootstrap method table.
      Specified by:
      bootstrapMethodEntry in interface ConstantPool
      Parameters:
      index - the index within the bootstrap method table of the desired entry
      Returns:
      the BootstrapMethodEntry at the specified index within the bootstrap method table
    • readU1

      public int readU1(int p)
      Description copied from interface: ClassReader
      Returns the unsigned byte at the specified offset within the classfile.
      Specified by:
      readU1 in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the unsigned byte at the specified offset within the classfile
    • readU2

      public int readU2(int p)
      Description copied from interface: ClassReader
      Returns the unsigned short at the specified offset within the classfile.
      Specified by:
      readU2 in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the unsigned short at the specified offset within the classfile
    • readS1

      public int readS1(int p)
      Description copied from interface: ClassReader
      Returns the signed byte at the specified offset within the classfile.
      Specified by:
      readS1 in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the signed byte at the specified offset within the classfile
    • readS2

      public int readS2(int p)
      Description copied from interface: ClassReader
      Returns the signed byte at the specified offset within the classfile.
      Specified by:
      readS2 in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the signed byte at the specified offset within the classfile
    • readInt

      public int readInt(int p)
      Description copied from interface: ClassReader
      Returns the signed int at the specified offset within the classfile.
      Specified by:
      readInt in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the signed int at the specified offset within the classfile
    • readLong

      public long readLong(int p)
      Description copied from interface: ClassReader
      Returns the signed long at the specified offset within the classfile.
      Specified by:
      readLong in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the signed long at the specified offset within the classfile
    • readFloat

      public float readFloat(int p)
      Description copied from interface: ClassReader
      Returns the float value at the specified offset within the classfile.
      Specified by:
      readFloat in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the float value at the specified offset within the classfile
    • readDouble

      public double readDouble(int p)
      Description copied from interface: ClassReader
      Returns the double value at the specified offset within the classfile.
      Specified by:
      readDouble in interface ClassReader
      Parameters:
      p - the offset within the classfile
      Returns:
      the double value at the specified offset within the classfile
    • readBytes

      public byte[] readBytes(int p, int len)
      Description copied from interface: ClassReader
      Returns a copy of the bytes at the specified range in the classfile.
      Specified by:
      readBytes in interface ClassReader
      Parameters:
      p - 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

      public void copyBytesTo(BufWriter buf, int p, int len)
      Description copied from interface: ClassReader
      Copy a range of bytes from the classfile to a BufWriter
      Specified by:
      copyBytesTo in interface ClassReader
      Parameters:
      buf - the BufWriter
      p - the offset within the classfile
      len - the length of the range
    • entryByIndex

      public PoolEntry entryByIndex(int index)
      Description copied from interface: ConstantPool
      Returns the entry at the specified index.
      Specified by:
      entryByIndex in interface ConstantPool
      Parameters:
      index - the index within the pool of the desired entry
      Returns:
      the entry at the specified index
    • utf8EntryByIndex

      public AbstractPoolEntry.Utf8EntryImpl utf8EntryByIndex(int index)
      Description copied from interface: ClassReader
      Returns the UTF8 constant pool entry at the given index of the constant pool. The given index must correspond to a valid constant pool index whose slot holds a UTF8 constant.
      Specified by:
      utf8EntryByIndex in interface ClassReader
      Parameters:
      index - the index into the constant pool
      Returns:
      the UTF8 constant pool entry at the given index of the constant pool
    • skipAttributeHolder

      public int skipAttributeHolder(int offset)
      Description copied from interface: ClassReader
      Returns the offset following the block of attributes starting at the specified position.
      Specified by:
      skipAttributeHolder in interface ClassReader
      Parameters:
      offset - the offset into the classfile at which the attribute block starts
      Returns:
      the offset following the block of attributes starting at the specified position
    • readEntry

      public PoolEntry readEntry(int pos)
      Description copied from interface: ClassReader
      Returns the constant pool entry whose index is given at the specified offset within the classfile.
      Specified by:
      readEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the constant pool entry whose index is given at the specified offset within the classfile
    • readEntryOrNull

      public PoolEntry readEntryOrNull(int pos)
      Description copied from interface: ClassReader
      Returns the constant pool entry whose index is given at the specified offset within the classfile, or null if the index at the specified offset is zero.
      Specified by:
      readEntryOrNull in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the constant pool entry whose index is given at the specified offset within the classfile, or null if the index at the specified offset is zero
    • readUtf8Entry

      public Utf8Entry readUtf8Entry(int pos)
      Description copied from interface: ClassReader
      Returns the UTF8 entry whose index is given at the specified offset within the classfile.
      Specified by:
      readUtf8Entry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the UTF8 entry whose index is given at the specified offset within the classfile
    • readUtf8EntryOrNull

      public Utf8Entry readUtf8EntryOrNull(int pos)
      Description copied from interface: ClassReader
      Returns the UTF8 entry whose index is given at the specified offset within the classfile, or null if the index at the specified offset is zero.
      Specified by:
      readUtf8EntryOrNull in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the UTF8 entry whose index is given at the specified offset within the classfile, or null if the index at the specified offset is zero
    • readModuleEntry

      public ModuleEntry readModuleEntry(int pos)
      Description copied from interface: ClassReader
      Returns the module entry whose index is given at the specified offset within the classfile.
      Specified by:
      readModuleEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the module entry whose index is given at the specified offset within the classfile
    • readPackageEntry

      public PackageEntry readPackageEntry(int pos)
      Description copied from interface: ClassReader
      Returns the package entry whose index is given at the specified offset within the classfile.
      Specified by:
      readPackageEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the package entry whose index is given at the specified offset within the classfile
    • readClassEntry

      public ClassEntry readClassEntry(int pos)
      Description copied from interface: ClassReader
      Returns the class entry whose index is given at the specified offset within the classfile.
      Specified by:
      readClassEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the class entry whose index is given at the specified offset within the classfile
    • readNameAndTypeEntry

      public NameAndTypeEntry readNameAndTypeEntry(int pos)
      Description copied from interface: ClassReader
      Returns the name-and-type entry whose index is given at the specified offset within the classfile.
      Specified by:
      readNameAndTypeEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the name-and-type entry whose index is given at the specified offset within the classfile
    • readMethodHandleEntry

      public MethodHandleEntry readMethodHandleEntry(int pos)
      Description copied from interface: ClassReader
      Returns the method handle entry whose index is given at the specified offset within the classfile.
      Specified by:
      readMethodHandleEntry in interface ClassReader
      Parameters:
      pos - the offset of the index within the classfile
      Returns:
      the method handle entry whose index is given at the specified offset within the classfile
    • compare

      public boolean compare(BufWriter bufWriter, int bufWriterOffset, int classReaderOffset, int length)
      Description copied from interface: ClassReader
      Compare a range of bytes from the classfile to a range of bytes within a BufWriter.
      Specified by:
      compare in interface ClassReader
      Parameters:
      bufWriter - the BufWriter
      bufWriterOffset - the offset within the BufWriter
      classReaderOffset - the offset within the classfile
      length - the length of the range
      Returns:
      whether the two ranges were identical