forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleOutput.java
More file actions
44 lines (39 loc) · 848 Bytes
/
Copy pathConsoleOutput.java
File metadata and controls
44 lines (39 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package javaforce;
/** Console Output
*
* Alternative to System.out which has issues in Graal.
*
* @author pquiring
*/
import java.io.*;
import javaforce.jni.*;
public class ConsoleOutput extends OutputStream {
private int low = -1;
private boolean isWindows;
public ConsoleOutput() {
isWindows = JF.isWindows();
}
public void write(int b) throws IOException {
b &= 0xff;
if (low == -1) {
low = b;
} else {
b <<= 8;
b |= low;
char c = ASCII8.convertUTF16(b);
if (isWindows) {
WinNative.writeConsole(c);
} else {
LnxNative.writeConsole(c);
}
low = -1;
}
}
public static void install() {
try {
System.setOut(new PrintStream(new ConsoleOutput(), true, "UTF-16LE"));
} catch (Exception e) {
e.printStackTrace();
}
}
}