Enum CompilerUtils

java.lang.Object
java.lang.Enum<CompilerUtils>
net.openhft.compiler.CompilerUtils
All Implemented Interfaces:
Serializable, Comparable<CompilerUtils>

public enum CompilerUtils extends Enum<CompilerUtils>
This class support loading and debugging Java Classes dynamically.
  • Field Details

    • 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 Method DEFINE_CLASS_METHOD
    • UTF_8

      private static final Charset UTF_8
    • JAVA_CLASS_PATH

      private static final String JAVA_CLASS_PATH
      See Also:
    • s_compiler

      static JavaCompiler s_compiler
    • s_standardJavaFileManager

      static StandardJavaFileManager s_standardJavaFileManager
  • Constructor Details

    • CompilerUtils

      private CompilerUtils()
  • Method Details

    • values

      public static CompilerUtils[] 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

      public static CompilerUtils valueOf(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:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - 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

      public static boolean addClassPath(@NotNull @NotNull 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 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

      private static String readText(@NotNull @NotNull String resourceName) throws IOException
      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

      private static void close(@Nullable @Nullable Closeable closeable)
    • writeText

      public static boolean writeText(@NotNull @NotNull File file, @NotNull @NotNull String text)
    • 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