-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #441 from dmlloyd/logmgr-342
[LOGMGR-342] Properly detect console charset
- Loading branch information
Showing
6 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/org/jboss/logmanager/handlers/JDKSpecific.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jboss.logmanager.handlers; | ||
|
||
import java.io.Console; | ||
import java.nio.charset.Charset; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
/** | ||
* JDK-specific code relating to {@link Console}. | ||
*/ | ||
final class JDKSpecific { | ||
private JDKSpecific() { | ||
} | ||
|
||
private static final Charset CONSOLE_CHARSET; | ||
|
||
static { | ||
// Make various guesses as to what the encoding of the console is | ||
String encodingName = AccessController | ||
.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("stdout.encoding")); | ||
if (encodingName == null) { | ||
encodingName = AccessController | ||
.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("native.encoding")); | ||
} | ||
CONSOLE_CHARSET = encodingName == null ? Charset.defaultCharset() : Charset.forName(encodingName); | ||
} | ||
|
||
static Charset consoleCharset() { | ||
return CONSOLE_CHARSET; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java17/org/jboss/logmanager/handlers/JDKSpecific.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.jboss.logmanager.handlers; | ||
|
||
import java.io.Console; | ||
import java.nio.charset.Charset; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
/** | ||
* JDK-specific code relating to {@link Console}. | ||
*/ | ||
final class JDKSpecific { | ||
private JDKSpecific() {} | ||
|
||
private static final Charset CONSOLE_CHARSET; | ||
|
||
static { | ||
Console console = System.console(); | ||
Charset charset; | ||
if (console != null) { | ||
charset = console.charset(); | ||
} else { | ||
// Make various guesses as to what the encoding of the console is | ||
String encodingName = AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("stdout.encoding")); | ||
if (encodingName == null) { | ||
encodingName = AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("native.encoding")); | ||
} | ||
charset = encodingName == null ? Charset.defaultCharset() : Charset.forName(encodingName); | ||
} | ||
CONSOLE_CHARSET = charset; | ||
} | ||
|
||
static Charset consoleCharset() { | ||
return CONSOLE_CHARSET; | ||
} | ||
} |