Class ClassParser
-
Constructor Summary
ConstructorsConstructorDescriptionClassParser(InputStream inputStream, String fileName) Parses class from the given stream.ClassParser(String fileName) Parses class from given .class file.ClassParser(String zipFile, String fileName) Parses class from given .class file in a ZIP-archive -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets whether compact Code header parsing is enabled for class file versions 45.0 through 45.2.parse()Parses the given Java class file and return an object that represents the contained data, that is, constants, methods, fields and commands.voidsetCompactCodeHeaderEnabled(boolean enabled) Sets whether to read compact Code headers in class file versions 45.0 through 45.2.
-
Constructor Details
-
ClassParser
Parses class from the given stream.- Parameters:
inputStream- Input stream.fileName- File name.
-
ClassParser
Parses class from given .class file.- Parameters:
fileName- file name.
-
ClassParser
Parses class from given .class file in a ZIP-archive- Parameters:
zipFile- ZIP file name.fileName- file name.
-
-
Method Details
-
isCompactCodeHeaderEnabled
Gets whether compact Code header parsing is enabled for class file versions 45.0 through 45.2.- Returns:
- Whether compact Code header parsing is enabled.
- Since:
- 6.14.0
- See Also:
-
parse
Parses the given Java class file and return an object that represents the contained data, that is, constants, methods, fields and commands. A ClassFormatException is raised, if the file is not a valid .class file. (This does not include verification of the byte code as it is performed by the Java interpreter).Code attributes use the standard eight-byte header by default, including in class files with version 45.0 through 45.2. Use
setCompactCodeHeaderEnabled(boolean)to read the compact four-byte header used by historical files with those versions.- Returns:
- Class object representing the parsed class file.
- Throws:
IOException- Thrown if an I/O error occurs.ClassFormatException- Thrown if a class is malformed or cannot be interpreted as a class file.
-
setCompactCodeHeaderEnabled
Sets whether to read compact Code headers in class file versions 45.0 through 45.2."Compact" refers to the widths of
max_stack,max_locals, andcode_length: unsigned one-, one-, and two-byte fields, respectively, totaling 4 bytes. Standard headers use unsigned two-, two-, and four-byte fields, totaling 8 bytes. These sizes exclude the common six-byte attribute prefix. The layout of that prefix and the remaining Code fields is unchanged.This option is disabled by default because modern JVMs also accept versions 45.0 through 45.2 with standard headers. The version therefore cannot determine the layout by itself; enabling this option selects the historical compact layout. Other class file versions always use standard headers, regardless of this option. Set this option before calling
parse().- Parameters:
enabled- Whether to enable compact Code header parsing.- Since:
- 6.14.0
- See Also:
-