Package org.terracotta.utilities.exec
Class Shell.Encoding
java.lang.Object
org.terracotta.utilities.exec.Shell.Encoding
- Enclosing class:
- Shell
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 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 -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
CHARSET
TheCharsetto use when interacting with the shell.
-
-
Constructor Details
-
Encoding
public Encoding()
-
-
Method Details
-
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
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
-