4 import java.io.FilterReader;
5 import java.io.IOException;
7 public class EscapedUnicodeReader extends FilterReader {
10 boolean isEvenSlash = true;
12 public EscapedUnicodeReader(Reader in) {
15 public int read() throws IOException {
16 int r = (pushback==-1) ? in.read() : pushback; pushback=-1;
21 } else { // found a backslash;
22 if (!isEvenSlash) { // Only even slashes are eligible unicode escapes.
27 // Check for the trailing u.
34 // OK, we've found backslash-u.
35 // Reset pushback and snarf up all trailing u's.
37 while((r=in.read())=='u')
39 // Now we should find 4 hex digits.
40 // If we don't, we can raise bloody hell.
42 for (int i=0; i<4; i++, r=in.read()) {
43 int d=Character.digit((char)r, 16);
45 throw new Error("Invalid unicode escape character.");
54 // synthesize array read from single-character read.
55 public int read(char cbuf[], int off, int len) throws IOException {
56 for (int i=0; i<len; i++) {
58 if (c==-1) return (i==0) ? -1 : i; // end of stream reached.
59 else cbuf[i+off] = (char) c;
64 public boolean markSupported() {
68 public boolean ready() throws IOException {
69 if (pushback!=-1) return true;
70 else return in.ready();