1 package fi.jyu.mit;
2 import java.io.*;
3
4
14
15 public class CoreIO {
16
17 private static BufferedReader myIn = initMyIn();
18 private static BufferedWriter myOut = initMyOut();
19 private static final String OEM = "Cp437";
20
21 private static boolean isWinConsole() {
22 String osName = System.getProperty("os.name");
23 String isOEM = System.getProperty("OEM");
24 return ( osName != null && osName.startsWith("Windows") && isOEM != null );
25 }
26
27 private static BufferedReader initMyIn() {
28 if ( isWinConsole() ) try {
29 return new BufferedReader(new InputStreamReader(System.in,OEM));
30 }
31 catch ( UnsupportedEncodingException e) { }
32 return new BufferedReader(new InputStreamReader(System.in));
33 }
34
35 private static BufferedWriter initMyOut() {
36 if ( isWinConsole() ) try {
37 OutputStreamWriter out = new OutputStreamWriter(System.out, OEM);
38 BufferedWriter bout = new BufferedWriter(out);
39 return bout;
40 }
42 catch ( UnsupportedEncodingException e) { }
43 return new BufferedWriter(new OutputStreamWriter(System.out));
44 }
45
46
47
51 public static String readln(String prompt) {
52 print(prompt);
53 try {
54 String s = myIn.readLine();
55 return s;
56 }
57 catch (IOException e) {
58 return "";
59 }
60 }
61
62
65 public static BufferedWriter os() {
66 return myOut;
67 }
68
69
72 public static void println(String s) {
73 try {
74 myOut.write(s);
75 myOut.newLine();
76 myOut.flush();
77 }
78 catch ( IOException e ) { e.printStackTrace(System.err); }
79 }
80
81
84 public static void print(String s) {
85 try {
86 myOut.write(s);
87 myOut.flush();
88 }
89 catch ( IOException e ) { e.printStackTrace(System.err); }
90 }
91
92 }
93
94