Class JavaPlatformStringLookup

java.lang.Object
org.apache.commons.text.lookup.AbstractStringLookup
org.apache.commons.text.lookup.JavaPlatformStringLookup
All Implemented Interfaces:
StringLookup

final class JavaPlatformStringLookup extends AbstractStringLookup
Looks up keys related to Java: Java version, JRE version, VM version, and so on.

The lookup keys with examples are:

  • version: "Java version 1.8.0_181"
  • runtime: "Java(TM) SE Runtime Environment (build 1.8.0_181-b13) from Oracle Corporation"
  • vm: "Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)"
  • os: "Windows 10 10.0, architecture: amd64-64"
  • hardware: "processors: 4, architecture: amd64-64, instruction sets: amd64"
  • locale: "default locale: en_US, platform encoding: iso-8859-1"

Using a StringLookup from the StringLookupFactory:

 StringLookupFactory.INSTANCE.javaPlatformStringLookup().lookup("version");
 

Using a StringSubstitutor:

 StringSubstitutor.createInterpolator().replace("... ${java:version} ..."));
 

The above examples convert "version" to the current VM version, for example, "Java version 1.8.0_181".

Since:
1.3
  • Field Details

  • Constructor Details

    • JavaPlatformStringLookup

      private JavaPlatformStringLookup()
      No need to build instances for now.
  • Method Details

    • main

      public static void main(String[] args)
      The main method for running the JavaPlatformStringLookup.
      Parameters:
      args - the standard java main method parameter which is unused for our running of this class.
    • getHardware

      String getHardware()
      Accessible through the Lookup key hardware.
      Returns:
      hardware processor information.
    • getLocale

      String getLocale()
      Accessible through the Lookup key locale.
      Returns:
      system locale and file encoding information.
    • getOperatingSystem

      String getOperatingSystem()
      Accessible through the Lookup key os.
      Returns:
      operating system information.
    • getRuntime

      String getRuntime()
      Accessible through the Lookup key runtime.
      Returns:
      Java Runtime Environment information.
    • getSystemProperty

      private String getSystemProperty(String name)
      Gets the given system property.
      Parameters:
      name - a system property name.
      Returns:
      a system property value.
    • getSystemProperty

      private String getSystemProperty(String prefix, String name)
      Gets the given system property.
      Parameters:
      prefix - the prefix to use for the result string
      name - a system property name.
      Returns:
      The prefix + a system property value.
    • getVirtualMachine

      String getVirtualMachine()
      Accessible through the Lookup key vm.
      Returns:
      Java Virtual Machine information.
    • lookup

      public String lookup(String key)
      Looks up the value of the Java platform key.

      The lookup keys with examples are:

      • version: "Java version 1.8.0_181"
      • runtime: "Java(TM) SE Runtime Environment (build 1.8.0_181-b13) from Oracle Corporation"
      • vm: "Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)"
      • os: "Windows 10 10.0, architecture: amd64-64"
      • hardware: "processors: 4, architecture: amd64-64, instruction sets: amd64"
      • locale: "default locale: en_US, platform encoding: iso-8859-1"
      Parameters:
      key - the key to be looked up, may be null
      Returns:
      The value of the environment variable.