1.1 --- a/emul/compact/src/main/java/java/io/InputStreamReader.java Wed Jan 23 23:16:47 2013 +0100
1.2 +++ b/emul/compact/src/main/java/java/io/InputStreamReader.java Mon Jan 28 12:18:24 2013 +0100
1.3 @@ -156,9 +156,39 @@
1.4 * @exception IOException If an I/O error occurs
1.5 */
1.6 public int read() throws IOException {
1.7 - return ((InputStream)lock).read();
1.8 + final InputStream is = (InputStream)lock;
1.9 + int c = is.read();
1.10 + if (c == -1) {
1.11 + return -1;
1.12 + }
1.13 + c = (int) c & 0xff;
1.14 + switch (c >> 4) {
1.15 + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
1.16 + /* 0xxxxxxx*/
1.17 + return c;
1.18 + case 12: case 13: {
1.19 + /* 110x xxxx 10xx xxxx*/
1.20 + int char2 = (int) is.read();
1.21 + if ((char2 & 0xC0) != 0x80)
1.22 + throw new UTFDataFormatException("malformed input");
1.23 + return (((c & 0x1F) << 6) | (char2 & 0x3F));
1.24 + }
1.25 + case 14: {
1.26 + /* 1110 xxxx 10xx xxxx 10xx xxxx */
1.27 + int char2 = is.read();
1.28 + int char3 = is.read();
1.29 + if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
1.30 + throw new UTFDataFormatException("malformed input");
1.31 + return (((c & 0x0F) << 12) |
1.32 + ((char2 & 0x3F) << 6) |
1.33 + ((char3 & 0x3F) << 0));
1.34 + }
1.35 + default:
1.36 + /* 10xx xxxx, 1111 xxxx */
1.37 + throw new UTFDataFormatException("malformed input");
1.38 + }
1.39 }
1.40 -
1.41 +
1.42 /**
1.43 * Reads characters into a portion of an array.
1.44 *