Package net.openhft.compiler
Enum CompilerUtils
- java.lang.Object
-
- java.lang.Enum<CompilerUtils>
-
- net.openhft.compiler.CompilerUtils
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<CompilerUtils>
public enum CompilerUtils extends java.lang.Enum<CompilerUtils>
This class support loading and debugging Java Classes dynamically.
-
-
Field Summary
Fields Modifier and Type Field Description static CachedCompiler
CACHED_COMPILER
static boolean
DEBUGGING
private static java.lang.reflect.Method
DEFINE_CLASS_METHOD
private static java.lang.String
JAVA_CLASS_PATH
private static org.slf4j.Logger
LOGGER
(package private) static javax.tools.JavaCompiler
s_compiler
(package private) static javax.tools.StandardJavaFileManager
s_standardJavaFileManager
private static java.nio.charset.Charset
UTF_8
-
Constructor Summary
Constructors Modifier Constructor Description private
CompilerUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
addClassPath(@NotNull java.lang.String dir)
Add a directory to the class path for compiling.private static void
close(@Nullable java.io.Closeable closeable)
private static @NotNull java.lang.String
decodeUTF8(@org.jetbrains.annotations.NotNull byte[] bytes)
static void
defineClass(@NotNull java.lang.String className, @org.jetbrains.annotations.NotNull byte[] bytes)
Define a class for byte code.static java.lang.Class
defineClass(@Nullable java.lang.ClassLoader classLoader, @NotNull java.lang.String className, @org.jetbrains.annotations.NotNull byte[] bytes)
Define a class for byte code.private static @org.jetbrains.annotations.NotNull byte[]
encodeUTF8(@NotNull java.lang.String text)
private static @NotNull java.io.InputStream
getInputStream(@NotNull java.lang.String filename)
private static boolean
isDebug()
private static java.lang.Class
loadFromJava(@NotNull java.lang.String className, @NotNull java.lang.String javaCode)
Load a java class from text.static java.lang.Class
loadFromResource(@NotNull java.lang.String className, @NotNull java.lang.String resourceName)
Load a java class file from the classpath or local file system.private static @org.jetbrains.annotations.Nullable byte[]
readBytes(@NotNull java.io.File file)
private static java.lang.String
readText(@NotNull java.lang.String resourceName)
private static void
reset()
static CompilerUtils
valueOf(java.lang.String name)
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 java.io.File file, @org.jetbrains.annotations.NotNull byte[] bytes)
static boolean
writeText(@NotNull java.io.File file, @NotNull java.lang.String text)
-
-
-
Field Detail
-
DEBUGGING
public static final boolean DEBUGGING
-
CACHED_COMPILER
public static final CachedCompiler CACHED_COMPILER
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
DEFINE_CLASS_METHOD
private static final java.lang.reflect.Method DEFINE_CLASS_METHOD
-
UTF_8
private static final java.nio.charset.Charset UTF_8
-
JAVA_CLASS_PATH
private static final java.lang.String JAVA_CLASS_PATH
- See Also:
- Constant Field Values
-
s_compiler
static javax.tools.JavaCompiler s_compiler
-
s_standardJavaFileManager
static javax.tools.StandardJavaFileManager s_standardJavaFileManager
-
-
Method Detail
-
values
public static CompilerUtils[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (CompilerUtils c : CompilerUtils.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static CompilerUtils valueOf(java.lang.String name)
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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
isDebug
private static boolean isDebug()
-
reset
private static void reset()
-
loadFromResource
public static java.lang.Class loadFromResource(@NotNull @NotNull java.lang.String className, @NotNull @NotNull java.lang.String resourceName) throws java.io.IOException, java.lang.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:
java.io.IOException
- the resource could not be loaded.java.lang.ClassNotFoundException
- the class name didn't match or failed to initialise.
-
loadFromJava
private static java.lang.Class loadFromJava(@NotNull @NotNull java.lang.String className, @NotNull @NotNull java.lang.String javaCode) throws java.lang.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:
java.lang.ClassNotFoundException
- the class name didn't match or failed to initialise.
-
addClassPath
public static boolean addClassPath(@NotNull @NotNull java.lang.String dir)
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 java.lang.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 java.lang.Class defineClass(@Nullable @Nullable java.lang.ClassLoader classLoader, @NotNull @NotNull java.lang.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
private static java.lang.String readText(@NotNull @NotNull java.lang.String resourceName) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeUTF8
@NotNull private static @NotNull java.lang.String decodeUTF8(@NotNull @org.jetbrains.annotations.NotNull byte[] bytes)
-
readBytes
@Nullable private static @org.jetbrains.annotations.Nullable byte[] readBytes(@NotNull @NotNull java.io.File file)
-
close
private static void close(@Nullable @Nullable java.io.Closeable closeable)
-
writeText
public static boolean writeText(@NotNull @NotNull java.io.File file, @NotNull @NotNull java.lang.String text)
-
encodeUTF8
@NotNull private static @org.jetbrains.annotations.NotNull byte[] encodeUTF8(@NotNull @NotNull java.lang.String text)
-
writeBytes
public static boolean writeBytes(@NotNull @NotNull java.io.File file, @NotNull @org.jetbrains.annotations.NotNull byte[] bytes)
-
getInputStream
@NotNull private static @NotNull java.io.InputStream getInputStream(@NotNull @NotNull java.lang.String filename) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
-