Class Shell.Encoding

java.lang.Object
org.terracotta.utilities.exec.Shell.Encoding
Enclosing class:
Shell

public static final class Shell.Encoding extends Object
Singleton identifying the Charset used for encoding/decoding interactions with the "shell" command interpreter environment. On Windows, especially, this is likely not the value of Charset.defaultCharset() -- which is the Charset used for file content encoding.

For Windows, this method calls the Windows chcp command to determine the code page used by a "fresh" CMD shell and returns the corresponding Charset.

The following Java system properties and values deal with encodings:

file.encoding
The encoding used for file content:
Windows
Derived from GetLocaleInfoEx(GetUserDefaultLCID(), LOCALE_IDEFAULTANSICODEPAGE, ...); uses code page 1252 if the GetLocaleInfoEx request fails.
Non-Windows
setlocale(LC_ALL, "") is used to establish the system's default locale; then setlocale(LC_CTYPE, NULL) is used to fetch the character-handling aspects of the default locale. The encoding value is parsed from the default locale name or obtained from nl_langinfo(CODESET) depending on the values involved. On Mac OS X, if the value is determined to be US-ASCII and none of the environment variables LANG, LC_ALL, or LC_CTYPE are set, a value of UTF-8 is used instead.
The value of Charset.defaultCharset() is derived from this value if it represents a supported character set.
sun.jnu.encoding
The "platform" encoding -- the encoding used bt the JVM to form strings presented to the OS:
Windows
Derived from GetLocaleInfoEx(GetSystemDefaultLCID(), LOCALE_IDEFAULTANSICODEPAGE, ...); uses encoding 1252 if the GetLocaleInfoEx request fails.
Non-Windows
See file.encoding above.
sun.stdout.encoding
The encoding used for output to STDOUT; only available for "console" applications:
Windows
Determined by GetConsoleCP(). This is actually in error -- it should rely on GetConsoleOutputCP().
Non-Windows
Not used.
sun.stderr.encoding
The encoding used for output to STDERR; only available for "console" applications:
Windows
Determined by GetConsoleCP(). This is actually in error -- it should rely on GetConsoleOutputCP().
Non-Windows
Not used.
  • Field Details

    • CHARSET

      public static final Charset CHARSET
      The Charset to use when interacting with the shell.
  • Constructor Details

    • Encoding

      public Encoding()
  • Method Details

    • getShellEncoding

      private static Charset getShellEncoding()
      Attempt to determine the "shell" character encoding -- the encoding used by the command interpreter to generate output lines.
      Returns:
      the Charset representing the encoding to use for decoding of command output lines
    • getJavaBasedSystemEncoding

      private static Charset getJavaBasedSystemEncoding()
      Gets the Charset used by the JDK to interpret host command output. This value may not be the correct value with which to interpret Windows command shell output.
      Returns:
      the host command encoding Charset