@@ -0,0 +1,1494 @@
+package com.itranswarp.jsonstream;%0A%0Aimport java.io.IOException;%0Aimport java.io.Reader;%0A%0A/**%0A * Provide easy way to read or fetch next char, and auto-fill its buffer.%0A * %0A * @author Michael Liao%0A */%0Aclass CharReader %7B%0A%0A%09static final int BUFFER_SIZE = 1024;%0A%0A%09// total readed chars:%0A%09int readed = 0;%0A%0A%09// buffer position:%0A%09int pos = 0;%0A%0A%09// buffer ends:%0A%09int size = 0;%0A%0A%09final char%5B%5D buffer;%0A%09final Reader reader;%0A%0A%09public CharReader(Reader reader) %7B%0A%09%09this.buffer = new char%5BBUFFER_SIZE%5D;%0A%09%09this.reader = reader;%0A%09%7D%0A%0A%09public boolean hasMore() throws IOException %7B%0A%09%09if (pos %3C size) %7B%0A%09%09%09return true;%0A%09%09%7D%0A%09%09// try fill:%0A%09%09fillBuffer(null);%0A%09%09return pos %3C size;%0A%09%7D%0A%0A%09public String next(int size) throws IOException %7B%0A%09%09StringBuilder sb = new StringBuilder(size);%0A%09%09for (int i=0; i%3Csize; i++) %7B%0A%09%09%09sb.append(next());%0A%09%09%7D%0A%09%09return sb.toString();%0A%09%7D%0A%0A%09public char next() throws IOException %7B%0A%09%09if (this.pos==this.size) %7B%0A%09%09%09// fill buffer:%0A%09%09%09fillBuffer(%22EOF%22);%0A%09%09%7D%0A%09%09char ch = this.buffer%5Bthis.pos%5D;%0A%09%09this.pos ++;%0A%09%09return ch;%0A%09%7D%0A%0A%09public char peek() throws IOException %7B%0A%09%09if (this.pos==this.size) %7B%0A%09%09%09// fill buffer:%0A%09%09%09fillBuffer(%22EOF%22);%0A%09%09%7D%0A%09%09assert(this.pos %3C this.size);%0A%09%09return this.buffer%5Bthis.pos%5D;%0A%09%7D%0A%0A%09void fillBuffer(String eofErrorMessage) throws IOException %7B%0A%09%09int n = reader.read(buffer);%0A%09%09if (n==(-1)) %7B%0A%09%09%09if (eofErrorMessage!=null) %7B%0A%09%09%09%09throw new JsonParseException(eofErrorMessage, this.readed);%0A%09%09%09%7D%0A%09%09%09return;%0A%09%09%7D%0A%09%09this.pos = 0;%0A%09%09this.size = n;%0A%09%09this.readed += n;%0A%09%7D%0A%7D%0A

add CharReader