diff -r f06b2d18eb52 -r 784aaf9ee179 emul/compact/src/main/java/java/io/InputStreamReader.java --- a/emul/compact/src/main/java/java/io/InputStreamReader.java Wed Jan 23 23:16:47 2013 +0100 +++ b/emul/compact/src/main/java/java/io/InputStreamReader.java Mon Jan 28 12:18:24 2013 +0100 @@ -156,9 +156,39 @@ * @exception IOException If an I/O error occurs */ public int read() throws IOException { - return ((InputStream)lock).read(); + final InputStream is = (InputStream)lock; + int c = is.read(); + if (c == -1) { + return -1; + } + c = (int) c & 0xff; + switch (c >> 4) { + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: + /* 0xxxxxxx*/ + return c; + case 12: case 13: { + /* 110x xxxx 10xx xxxx*/ + int char2 = (int) is.read(); + if ((char2 & 0xC0) != 0x80) + throw new UTFDataFormatException("malformed input"); + return (((c & 0x1F) << 6) | (char2 & 0x3F)); + } + case 14: { + /* 1110 xxxx 10xx xxxx 10xx xxxx */ + int char2 = is.read(); + int char3 = is.read(); + if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) + throw new UTFDataFormatException("malformed input"); + return (((c & 0x0F) << 12) | + ((char2 & 0x3F) << 6) | + ((char3 & 0x3F) << 0)); + } + default: + /* 10xx xxxx, 1111 xxxx */ + throw new UTFDataFormatException("malformed input"); + } } - + /** * Reads characters into a portion of an array. *