- private static class In extends InputStream {
- public Reader reader = new InputStreamReader(this);
- private final InputStream orig;
- public In(InputStream in) { orig = in; }
-
- char[] cbuf = new char[8192];
- int cstart = 0;
- int cend = 0;
-
- byte[] buf = new byte[8192];
- int start = 0;
- int end = 0;
+ private class In extends InputStream {
+ private ByteBufInputStream bbis;
+ private CharBufReader cbr;
+ public Reader reader;
+ private Writer unreader;
+
+ public char getc(boolean peek) { return cbr.getc(peek); }
+ public String readln() { return cbr.readln(); }
+ public int read() { return bbis.read(); }
+ public int read(byte[] b) { try { return bbis.read(b); } catch (IOException e) { ioe(e); return 0; } }
+ public int read(byte[] b, int off, int len) { return bbis.read(b, off, len); }
+ public void close() { try { cbr.close(); } catch (Exception e) { Log.error(this, e); } }
+ public int readBytes(byte[] b, int off, int len) { return bbis.read(b, off, len); }
+ public int readChars(char[] c, int off, int len) { return cbr.read(c, off, len); }
+
+ public In(InputStream in) {
+ bbis = new ByteBufInputStream(in) {
+ public void preread() {
+ try {
+ if (!cbr.ready()) return;
+ } catch (IOException e) { ioe(e); }
+ char[] c = new char[20];
+ while(true) {
+ try {
+ if (!cbr.ready()) break;
+ int numread = cbr.read(c, 0, c.length);
+ if (numread == -1) break;
+ unreader.write(c, 0, numread);
+ } catch (IOException e) { ioe(e); }
+ }
+ }
+ };
+ unreader = new OutputStreamWriter(new UnReaderStream(bbis));
+ cbr = new CharBufReader(new InputStreamReader(bbis));
+ }