SoftNet-Consult Java Utility Library

com.softnetConsult.utils.reflect
Class ClassTools

java.lang.Object
  extended by com.softnetConsult.utils.reflect.ClassTools

public final class ClassTools
extends java.lang.Object

Defines static utilities for dealing with classes and reflection.

This product includes software developed by the SoftNet-Consult Java Utility Library project and its contributors.
(http://java-tools.sourceforge.net)
Copyright (c) 2007-2008 SoftNet-Consult.
Copyright (c) 2007-2008 G. Paperin.
All rights reserved.

File: ClassTools.java
Library API version: "2.02"
Java compliance version: "1.5"

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:

1. Redistributions of source code must retain the above acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived software must display the following acknowledgement:
This product includes software developed by the SoftNet-Consult Java Utility Library project and its contributors.

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version:
"2.02"
Author:
Greg Paperin (http://www.paperin.org)

Field Summary
static int JAVA_CLASSFILE_MAGIC_NUMBER
          The magic number that must be contained in the first two bytes of all Java class binaries.
 
Constructor Summary
private ClassTools()
          Prevents instances of this class from being created as this class contains only static utility methods.
 
Method Summary
static ClassVersionInfo getClassVersionInfo(java.io.InputStream classdata)
          Parses the version information from a a Java class binary.
static java.lang.String getMinimumRequiredJavaVersion(int classBinaryMajorVersion, int classBinaryMinorVersion)
          Determines the minimum JVM version required to run a class binary of the specified version.
static java.lang.Class<?> getWrapperClass(java.lang.Class<?> type)
          Find the correct wrapper class for a primitive type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAVA_CLASSFILE_MAGIC_NUMBER

public static final int JAVA_CLASSFILE_MAGIC_NUMBER
The magic number that must be contained in the first two bytes of all Java class binaries.

See Also:
Constant Field Values
Constructor Detail

ClassTools

private ClassTools()
Prevents instances of this class from being created as this class contains only static utility methods.

Method Detail

getWrapperClass

public static java.lang.Class<?> getWrapperClass(java.lang.Class<?> type)
Find the correct wrapper class for a primitive type. If the specified class type does not describe a primitive type, it is simply returned. If the specified class type describes a primitive type, the corresponding warpper class type is returned. For instance:
int => Integer.class
double => Double.class
Object => Object
null => null

Parameters:
type - An object representing a Java class or interface.
Returns:
The wrapper class type corresponding to the specified class type.

getMinimumRequiredJavaVersion

public static final java.lang.String getMinimumRequiredJavaVersion(int classBinaryMajorVersion,
                                                                   int classBinaryMinorVersion)
Determines the minimum JVM version required to run a class binary of the specified version. The current version of this method supports class binaries up to version 50.0 (which corresponds to JVM 1.6).

Parameters:
classBinaryMajorVersion - Major version of a class binary.
classBinaryMinorVersion - Minor version of a class binary.
Returns:
A string specifying the minimum version of a Java virtual machine required to run a class binary with the specified version number. If the specified class binary version is unknown, the string "<unknown>" is returned.

getClassVersionInfo

public static ClassVersionInfo getClassVersionInfo(java.io.InputStream classdata)
                                            throws java.io.IOException
Parses the version information from a a Java class binary.

Parameters:
classdata - A stream containing the Java class binary data.
Returns:
The version information of the specified class binary.
Throws:
java.io.IOException - If an error occurs when reading from the specified class binary stream.

SoftNet-Consult Java Utility Library is a member of SourceForge.net