类 ClassReader
- java.lang.Object
-
- com.alibaba.nacos.common.packagescan.classreading.ClassReader
-
public class ClassReader extends java.lang.ObjectCopy from ASM, with less modifications A parser to make a visit a ClassFile structure, as defined in the Java Virtual Machine Specification (JVMS). This class parses the ClassFile content and calls the appropriate visit methods of a given ClassVisitor for each field, method and bytecode instruction encountered.- 作者:
- Eric Bruneton, Eugene Kuleshov
- 另请参阅:
- JVMS 4
-
-
字段概要
字段 修饰符和类型 字段 说明 byte[]b已过时。UsereadByte(int)and the other read methods instead.(专用程序包) byte[]classFileBufferA byte array containing the JVMS ClassFile structure to be parsed.private java.lang.String[]constantUtf8ValuesThe String objects corresponding to the CONSTANT_Utf8 constant pool items.private int[]cpInfoOffsetsThe offset in bytes, inclassFileBuffer, of each cp_info entry of the ClassFile's constant_pool array, plus one.(专用程序包) static intEXPAND_ASM_INSNSA flag to expand the ASM specific instructions into an equivalent sequence of standard bytecode instructions.static intEXPAND_FRAMESA flag to expand the stack map frames.intheaderThe offset in bytes of the ClassFile's access_flags field.private static intINPUT_STREAM_DATA_CHUNK_SIZEThe size of the temporary byte array used to read class input streams chunk by chunk.private static intMAX_BUFFER_SIZEThe maximum size of array to allocate.private intmaxStringLengthA conservative estimate of the maximum length of the strings contained in the constant pool of the class.static intSKIP_CODEA flag to skip the Code attributes.static intSKIP_DEBUGA flag to skip the SourceFile.static intSKIP_FRAMESA flag to skip the StackMap and StackMapTable attributes.static intV19
-
构造器概要
构造器 构造器 说明 ClassReader(byte[] classFile)Constructs a newClassReaderobject.ClassReader(byte[] classFileBuffer, int classFileOffset, boolean checkClassVersion)Constructs a newClassReaderobject.ClassReader(byte[] classFileBuffer, int classFileOffset, int classFileLength)Constructs a newClassReaderobject.ClassReader(java.io.InputStream inputStream)Constructs a newClassReaderobject.ClassReader(java.lang.String className)Constructs a newClassReaderobject.
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 private static intcalculateBufferSize(java.io.InputStream inputStream)intgetAccess()Returns the class's access flags .java.lang.StringgetClassName()the internal class name.(专用程序包) intgetFirstAttributeOffset()Returns the offset inclassFileBufferof the first ClassFile's 'attributes' array field entry.java.lang.String[]getInterfaces()the internal names of the directly implemented interfaces.intgetItem(int constantPoolEntryIndex)Returns the start offset in thisClassReaderof a JVMS 'cp_info' structure (i.e. a constant pool entry), plus one.intgetItemCount()Returns the number of entries in the class's constant pool table.intgetMaxStringLength()Returns a conservative estimate of the maximum length of the strings contained in the class's constant pool table.java.lang.StringgetSuperName()intreadByte(int offset)Reads a byte value in thisClassReader.java.lang.StringreadClass(int offset, char[] charBuffer)Reads a CONSTANT_Class constant pool entry in thisClassReader.intreadInt(int offset)Reads a signed int value in thisClassReader.longreadLong(int offset)Reads a signed long value in thisClassReader.java.lang.StringreadModule(int offset, char[] charBuffer)Reads a CONSTANT_Module constant pool entry in thisClassReader.java.lang.StringreadPackage(int offset, char[] charBuffer)Reads a CONSTANT_Package constant pool entry in thisClassReader.shortreadShort(int offset)Reads a signed short value in thisClassReader.private static byte[]readStream(java.io.InputStream inputStream, boolean close)Reads the given input stream and returns its content as a byte array.private java.lang.StringreadStringish(int offset, char[] charBuffer)Reads a CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType, CONSTANT_Module or CONSTANT_Package constant pool entry inclassFileBuffer.intreadUnsignedShort(int offset)Reads an unsigned short value in thisClassReader.(专用程序包) java.lang.StringreadUtf(int constantPoolEntryIndex, char[] charBuffer)Reads a CONSTANT_Utf8 constant pool entry inclassFileBuffer.private java.lang.StringreadUtf(int utfOffset, int utfLength, char[] charBuffer)Reads an UTF8 string inclassFileBuffer.java.lang.StringreadUtf8(int offset, char[] charBuffer)Reads a CONSTANT_Utf8 constant pool entry in thisClassReader.
-
-
-
字段详细资料
-
SKIP_CODE
public static final int SKIP_CODE
A flag to skip the Code attributes. If this flag is set the Code attributes are neither parsed nor visited.- 另请参阅:
- 常量字段值
-
V19
public static final int V19
- 另请参阅:
- 常量字段值
-
SKIP_DEBUG
public static final int SKIP_DEBUG
A flag to skip the SourceFile.- 另请参阅:
- 常量字段值
-
SKIP_FRAMES
public static final int SKIP_FRAMES
A flag to skip the StackMap and StackMapTable attributes. If this flag is set these attributes are neither parsed nor visited is not called). This flag is useful when the option is used: it avoids visiting frames that will be ignored and recomputed from scratch.- 另请参阅:
- 常量字段值
-
EXPAND_FRAMES
public static final int EXPAND_FRAMES
A flag to expand the stack map frames. By default stack map frames are visited in their original format (i.e. "expanded" for classes whose version is less than V1_6, and "compressed" for the other classes). If this flag is set, stack map frames are always visited in expanded format (this option adds a decompression/compression step in ClassReader and ClassWriter which degrades performance quite a lot).- 另请参阅:
- 常量字段值
-
EXPAND_ASM_INSNS
static final int EXPAND_ASM_INSNS
A flag to expand the ASM specific instructions into an equivalent sequence of standard bytecode instructions. When resolving a forward jump it may happen that the signed 2 bytes offset reserved for it is not sufficient to store the bytecode offset. This internal flag is used to re-read classes containing such instructions, in order to replace them with standard instructions. In addition, when this flag is used, goto_w and jsr_w are not converted into goto and jsr, to make sure that infinite loops where a goto_w is replaced with a goto in ClassReader and converted back to a goto_w in ClassWriter cannot occur.- 另请参阅:
- 常量字段值
-
MAX_BUFFER_SIZE
private static final int MAX_BUFFER_SIZE
The maximum size of array to allocate.- 另请参阅:
- 常量字段值
-
INPUT_STREAM_DATA_CHUNK_SIZE
private static final int INPUT_STREAM_DATA_CHUNK_SIZE
The size of the temporary byte array used to read class input streams chunk by chunk.- 另请参阅:
- 常量字段值
-
b
@Deprecated public final byte[] b
已过时。UsereadByte(int)and the other read methods instead. This field will eventually be deleted.A byte array containing the JVMS ClassFile structure to be parsed.
-
header
public final int header
The offset in bytes of the ClassFile's access_flags field.
-
classFileBuffer
final byte[] classFileBuffer
A byte array containing the JVMS ClassFile structure to be parsed. The content of this array must not be modified. This field is intended for Attribute sub classes, and is normally not needed by class visitors.NOTE: the ClassFile structure can start at any offset within this array, i.e. it does not necessarily start at offset 0. Use
getItem(int)andheaderto get correct ClassFile element offsets within this byte array.
-
cpInfoOffsets
private final int[] cpInfoOffsets
The offset in bytes, inclassFileBuffer, of each cp_info entry of the ClassFile's constant_pool array, plus one. In other words, the offset of constant pool entry i is given by cpInfoOffsets[i] - 1, i.e. its cp_info's tag field is given by b[cpInfoOffsets[i] - 1].
-
constantUtf8Values
private final java.lang.String[] constantUtf8Values
The String objects corresponding to the CONSTANT_Utf8 constant pool items. This cache avoids multiple parsing of a given CONSTANT_Utf8 constant pool item.
-
maxStringLength
private final int maxStringLength
A conservative estimate of the maximum length of the strings contained in the constant pool of the class.
-
-
构造器详细资料
-
ClassReader
public ClassReader(byte[] classFile)
Constructs a newClassReaderobject.- 参数:
classFile- the JVMS ClassFile structure to be read.
-
ClassReader
public ClassReader(byte[] classFileBuffer, int classFileOffset, int classFileLength)Constructs a newClassReaderobject.- 参数:
classFileBuffer- a byte array containing the JVMS ClassFile structure to be read.classFileOffset- the offset in byteBuffer of the first byte of the ClassFile to be read.classFileLength- the length in bytes of the ClassFile to be read.
-
ClassReader
ClassReader(byte[] classFileBuffer, int classFileOffset, boolean checkClassVersion)Constructs a newClassReaderobject. This internal constructor must not be exposed as a public API.- 参数:
classFileBuffer- a byte array containing the JVMS ClassFile structure to be read.classFileOffset- the offset in byteBuffer of the first byte of the ClassFile to be read.checkClassVersion- whether to check the class version or not.
-
ClassReader
public ClassReader(java.io.InputStream inputStream) throws java.io.IOExceptionConstructs a newClassReaderobject.- 参数:
inputStream- an input stream of the JVMS ClassFile structure to be read. This input stream must contain nothing more than the ClassFile structure itself. It is read from its current position to its end.- 抛出:
java.io.IOException- if a problem occurs during reading.
-
ClassReader
public ClassReader(java.lang.String className) throws java.io.IOExceptionConstructs a newClassReaderobject.- 参数:
className- the fully qualified name of the class to be read. The ClassFile structure is retrieved with the current class loader'sClassLoader.getSystemResourceAsStream(java.lang.String).- 抛出:
java.io.IOException- if an exception occurs during reading.
-
-
方法详细资料
-
readStream
private static byte[] readStream(java.io.InputStream inputStream, boolean close) throws java.io.IOExceptionReads the given input stream and returns its content as a byte array.- 参数:
inputStream- an input stream.close- true to close the input stream after reading.- 返回:
- the content of the given input stream.
- 抛出:
java.io.IOException- if a problem occurs during reading.
-
calculateBufferSize
private static int calculateBufferSize(java.io.InputStream inputStream) throws java.io.IOException- 抛出:
java.io.IOException
-
getAccess
public int getAccess()
Returns the class's access flags . This value may not reflect Deprecated and Synthetic flags when bytecode is before 1.5 and those flags are represented by attributes.- 返回:
- the class access flags.
-
getClassName
public java.lang.String getClassName()
the internal class name.
-
getSuperName
public java.lang.String getSuperName()
-
getInterfaces
public java.lang.String[] getInterfaces()
the internal names of the directly implemented interfaces. Inherited implemented interfaces are not returned.
-
getFirstAttributeOffset
final int getFirstAttributeOffset()
Returns the offset inclassFileBufferof the first ClassFile's 'attributes' array field entry.- 返回:
- the offset in
classFileBufferof the first ClassFile's 'attributes' array field entry.
-
getItemCount
public int getItemCount()
Returns the number of entries in the class's constant pool table.- 返回:
- the number of entries in the class's constant pool table.
-
getItem
public int getItem(int constantPoolEntryIndex)
Returns the start offset in thisClassReaderof a JVMS 'cp_info' structure (i.e. a constant pool entry), plus one. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
constantPoolEntryIndex- the index a constant pool entry in the class's constant pool table.- 返回:
- the start offset in this
ClassReaderof the corresponding JVMS 'cp_info' structure, plus one.
-
getMaxStringLength
public int getMaxStringLength()
Returns a conservative estimate of the maximum length of the strings contained in the class's constant pool table.- 返回:
- a conservative estimate of the maximum length of the strings contained in the class's constant pool table.
-
readByte
public int readByte(int offset)
Reads a byte value in thisClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of the value to be read in thisClassReader.- 返回:
- the read value.
-
readUnsignedShort
public int readUnsignedShort(int offset)
Reads an unsigned short value in thisClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start index of the value to be read in thisClassReader.- 返回:
- the read value.
-
readShort
public short readShort(int offset)
Reads a signed short value in thisClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of the value to be read in thisClassReader.- 返回:
- the read value.
-
readInt
public int readInt(int offset)
Reads a signed int value in thisClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of the value to be read in thisClassReader.- 返回:
- the read value.
-
readLong
public long readLong(int offset)
Reads a signed long value in thisClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of the value to be read in thisClassReader.- 返回:
- the read value.
-
readUtf8
public java.lang.String readUtf8(int offset, char[] charBuffer)Reads a CONSTANT_Utf8 constant pool entry in thisClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of an unsigned short value in thisClassReader, whose value is the index of a CONSTANT_Utf8 entry in the class's constant pool table.charBuffer- the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified CONSTANT_Utf8 entry.
-
readUtf
final java.lang.String readUtf(int constantPoolEntryIndex, char[] charBuffer)Reads a CONSTANT_Utf8 constant pool entry inclassFileBuffer.- 参数:
constantPoolEntryIndex- the index of a CONSTANT_Utf8 entry in the class's constant pool table.charBuffer- the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified CONSTANT_Utf8 entry.
-
readUtf
private java.lang.String readUtf(int utfOffset, int utfLength, char[] charBuffer)Reads an UTF8 string inclassFileBuffer.- 参数:
utfOffset- the start offset of the UTF8 string to be read.utfLength- the length of the UTF8 string to be read.charBuffer- the buffer to be used to read the string. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified UTF8 string.
-
readStringish
private java.lang.String readStringish(int offset, char[] charBuffer)Reads a CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType, CONSTANT_Module or CONSTANT_Package constant pool entry inclassFileBuffer. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of an unsigned short value inclassFileBuffer, whose value is the index of a CONSTANT_Class, CONSTANT_String, CONSTANT_MethodType, CONSTANT_Module or CONSTANT_Package entry in class's constant pool table.charBuffer- the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified constant pool entry.
-
readClass
public java.lang.String readClass(int offset, char[] charBuffer)Reads a CONSTANT_Class constant pool entry in thisClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of an unsigned short value in thisClassReader, whose value is the index of a CONSTANT_Class entry in class's constant pool table.charBuffer- the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified CONSTANT_Class entry.
-
readModule
public java.lang.String readModule(int offset, char[] charBuffer)Reads a CONSTANT_Module constant pool entry in thisClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of an unsigned short value in thisClassReader, whose value is the index of a CONSTANT_Module entry in class's constant pool table.charBuffer- the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified CONSTANT_Module entry.
-
readPackage
public java.lang.String readPackage(int offset, char[] charBuffer)Reads a CONSTANT_Package constant pool entry in thisClassReader. This method is intended for Attribute sub classes, and is normally not needed by class generators or adapters.- 参数:
offset- the start offset of an unsigned short value in thisClassReader, whose value is the index of a CONSTANT_Package entry in class's constant pool table.charBuffer- the buffer to be used to read the item. This buffer must be sufficiently large. It is not automatically resized.- 返回:
- the String corresponding to the specified CONSTANT_Package entry.
-
-