Package org.terracotta.utilities.exec
Class Shell.Encoding
- java.lang.Object
-
- org.terracotta.utilities.exec.Shell.Encoding
-
- Enclosing class:
- Shell
public static final class Shell.Encoding extends java.lang.ObjectSingleton identifying theCharsetused for encoding/decoding interactions with the "shell" command interpreter environment. On Windows, especially, this is likely not the value ofCharset.defaultCharset()-- which is theCharsetused for file content encoding.For Windows, this method calls the Windows
chcpcommand to determine the code page used by a "fresh"CMDshell and returns the correspondingCharset.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 theGetLocaleInfoExrequest fails. - Non-Windows
setlocale(LC_ALL, "")is used to establish the system's default locale; thensetlocale(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 fromnl_langinfo(CODESET)depending on the values involved. On Mac OS X, if the value is determined to beUS-ASCIIand none of the environment variablesLANG,LC_ALL, orLC_CTYPEare set, a value ofUTF-8is used instead.
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 theGetLocaleInfoExrequest fails. - Non-Windows
- See
file.encodingabove.
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 onGetConsoleOutputCP(). - 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 onGetConsoleOutputCP(). - Non-Windows
- Not used.
-
-
Field Summary
Fields Modifier and Type Field Description static java.nio.charset.CharsetCHARSETTheCharsetto use when interacting with the shell.
-
Constructor Summary
Constructors Constructor Description Encoding()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.nio.charset.CharsetgetJavaBasedSystemEncoding()Gets theCharsetused by the JDK to interpret host command output.private static java.nio.charset.CharsetgetShellEncoding()Attempt to determine the "shell" character encoding -- the encoding used by the command interpreter to generate output lines.
-
-
-
Method Detail
-
getShellEncoding
private static java.nio.charset.Charset getShellEncoding()
Attempt to determine the "shell" character encoding -- the encoding used by the command interpreter to generate output lines.- Returns:
- the
Charsetrepresenting the encoding to use for decoding of command output lines
-
getJavaBasedSystemEncoding
private static java.nio.charset.Charset getJavaBasedSystemEncoding()
Gets theCharsetused 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
-
-