forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.java
More file actions
57 lines (51 loc) · 1.27 KB
/
Copy pathConsole.java
File metadata and controls
57 lines (51 loc) · 1.27 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
package javaforce;
/** Console
*
* @author pquiring
*/
import java.io.*;
import javaforce.jni.*;
public class Console {
private static boolean isWindows = JF.isWindows();
public static InputStream getInputStream() {
return new InputStream() {
public int read() throws IOException {
int ch;
if (isWindows) {
ch = WinNative.readConsole();
} else {
ch = LnxNative.readConsole();
}
return ch;
}
public int read(byte[] buf) throws IOException {
return read(buf, 0, buf.length);
}
public int read(byte[] buf, int offset, int length) throws IOException {
int start = offset;
int end = offset + length;
int count = 0;
for(int i=start;i<end;) {
int ch = read();
if (ch == 0 || ch == -1) break;
buf[i] = (byte)ch;
i++;
count++;
}
return count;
}
};
}
public static OutputStream getOutputStream() {
return new OutputStream() {
public void write(int utf16) throws IOException {
char ch = ASCII8.convertUTF16(utf16);
if (isWindows) {
WinNative.writeConsole(ch);
} else {
LnxNative.writeConsole(ch);
}
}
};
}
}