Package net.openhft.compiler
Enum CompilerUtils
- All Implemented Interfaces:
Serializable
,Comparable<CompilerUtils>
This class support loading and debugging Java Classes dynamically.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CachedCompiler
static final boolean
private static final Method
private static final String
private static final org.slf4j.Logger
(package private) static JavaCompiler
(package private) static StandardJavaFileManager
private static final Charset
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
addClassPath
(@NotNull String dir) Add a directory to the class path for compiling.private static void
private static @NotNull String
decodeUTF8
(@org.jetbrains.annotations.NotNull byte[] bytes) static void
defineClass
(@NotNull String className, @org.jetbrains.annotations.NotNull byte[] bytes) Define a class for byte code.static Class
defineClass
(@Nullable ClassLoader classLoader, @NotNull String className, @org.jetbrains.annotations.NotNull byte[] bytes) Define a class for byte code.private static @org.jetbrains.annotations.NotNull byte[]
encodeUTF8
(@NotNull String text) private static @NotNull InputStream
getInputStream
(@NotNull String filename) private static boolean
isDebug()
private static Class
loadFromJava
(@NotNull String className, @NotNull String javaCode) Load a java class from text.static Class
loadFromResource
(@NotNull String className, @NotNull String resourceName) Load a java class file from the classpath or local file system.private static @org.jetbrains.annotations.Nullable byte[]
private static String
private static void
reset()
static CompilerUtils
Returns the enum constant of this type with the specified name.static CompilerUtils[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.static boolean
writeBytes
(@NotNull File file, @org.jetbrains.annotations.NotNull byte[] bytes) static boolean
-
Field Details
-
DEBUGGING
public static final boolean DEBUGGING -
CACHED_COMPILER
-
LOGGER
private static final org.slf4j.Logger LOGGER -
DEFINE_CLASS_METHOD
-
UTF_8
-
JAVA_CLASS_PATH
- See Also:
-
s_compiler
-
s_standardJavaFileManager
-
-
Constructor Details
-
CompilerUtils
private CompilerUtils()
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
isDebug
private static boolean isDebug() -
reset
private static void reset() -
loadFromResource
public static Class loadFromResource(@NotNull @NotNull String className, @NotNull @NotNull String resourceName) throws IOException, ClassNotFoundException Load a java class file from the classpath or local file system.- Parameters:
className
- expected class name of the outer class.resourceName
- as the full file name with extension.- Returns:
- the outer class loaded.
- Throws:
IOException
- the resource could not be loaded.ClassNotFoundException
- the class name didn't match or failed to initialise.
-
loadFromJava
private static Class loadFromJava(@NotNull @NotNull String className, @NotNull @NotNull String javaCode) throws ClassNotFoundException Load a java class from text.- Parameters:
className
- expected class name of the outer class.javaCode
- to compile and load.- Returns:
- the outer class loaded.
- Throws:
ClassNotFoundException
- the class name didn't match or failed to initialise.
-
addClassPath
Add a directory to the class path for compiling. This can be required with custom- Parameters:
dir
- to add.- Returns:
- whether the directory was found, if not it is not added either.
-
defineClass
public static void defineClass(@NotNull @NotNull String className, @NotNull @org.jetbrains.annotations.NotNull byte[] bytes) Define a class for byte code.- Parameters:
className
- expected to load.bytes
- of the byte code.
-
defineClass
public static Class defineClass(@Nullable @Nullable ClassLoader classLoader, @NotNull @NotNull String className, @NotNull @org.jetbrains.annotations.NotNull byte[] bytes) Define a class for byte code.- Parameters:
classLoader
- to load the class into.className
- expected to load.bytes
- of the byte code.
-
readText
- Throws:
IOException
-
decodeUTF8
@NotNull private static @NotNull String decodeUTF8(@NotNull @org.jetbrains.annotations.NotNull byte[] bytes) -
readBytes
@Nullable private static @org.jetbrains.annotations.Nullable byte[] readBytes(@NotNull @NotNull File file) -
close
-
writeText
-
encodeUTF8
@NotNull private static @org.jetbrains.annotations.NotNull byte[] encodeUTF8(@NotNull @NotNull String text) -
writeBytes
public static boolean writeBytes(@NotNull @NotNull File file, @NotNull @org.jetbrains.annotations.NotNull byte[] bytes) -
getInputStream
@NotNull private static @NotNull InputStream getInputStream(@NotNull @NotNull String filename) throws FileNotFoundException - Throws:
FileNotFoundException
-