|
18 | 18 | */ |
19 | 19 | package jp.osscons.opensourcecobol.libcobj.termio; |
20 | 20 |
|
| 21 | +import java.io.InputStreamReader; |
21 | 22 | import java.io.PrintStream; |
22 | 23 | import java.nio.ByteBuffer; |
| 24 | +import java.nio.charset.Charset; |
| 25 | +import java.nio.charset.StandardCharsets; |
| 26 | +import java.nio.charset.UnsupportedCharsetException; |
23 | 27 | import java.time.LocalDateTime; |
24 | 28 | import java.time.format.DateTimeFormatter; |
25 | 29 | import java.util.Scanner; |
| 30 | +import jp.osscons.opensourcecobol.libcobj.common.CobolEncoding; |
26 | 31 | import jp.osscons.opensourcecobol.libcobj.common.CobolModule; |
27 | 32 | import jp.osscons.opensourcecobol.libcobj.common.CobolUtil; |
28 | 33 | import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; |
@@ -68,7 +73,16 @@ public static void display(boolean dispStdout, boolean newline, AbstractCobolFie |
68 | 73 |
|
69 | 74 | private static void displayAlnum(AbstractCobolField f, PrintStream stream) { |
70 | 75 | CobolDataStorage storage = f.getDataStorage(); |
71 | | - stream.write(storage.getRefOfData(), storage.getIndex(), f.getSize()); |
| 76 | + if (CobolUtil.terminalEncoding == CobolEncoding.UTF8) { |
| 77 | + byte[] utf8Bytes = |
| 78 | + new String( |
| 79 | + storage.getByteArrayRef(0, f.getSize()), |
| 80 | + AbstractCobolField.charSetSJIS) |
| 81 | + .getBytes(StandardCharsets.UTF_8); |
| 82 | + stream.write(utf8Bytes, 0, utf8Bytes.length); |
| 83 | + } else { |
| 84 | + stream.write(storage.getRefOfData(), storage.getIndex(), f.getSize()); |
| 85 | + } |
72 | 86 | } |
73 | 87 |
|
74 | 88 | /** |
@@ -108,7 +122,18 @@ public static void display( |
108 | 122 | public static void accept(AbstractCobolField f) { |
109 | 123 | try { |
110 | 124 | if (scan == null) { |
111 | | - scan = new Scanner(System.in); |
| 125 | + if (CobolUtil.terminalEncoding == CobolEncoding.UTF8) { |
| 126 | + scan = new Scanner(new InputStreamReader(System.in, StandardCharsets.UTF_8)); |
| 127 | + } else { |
| 128 | + try { |
| 129 | + scan = |
| 130 | + new Scanner( |
| 131 | + new InputStreamReader( |
| 132 | + System.in, Charset.forName("Shift_JIS"))); |
| 133 | + } catch (UnsupportedCharsetException e) { |
| 134 | + scan = new Scanner(System.in); |
| 135 | + } |
| 136 | + } |
112 | 137 | } |
113 | 138 |
|
114 | 139 | String input = scan.nextLine(); |
|
0 commit comments