1.1 --- a/emul/compact/src/main/java/java/io/InputStreamReader.java Wed Jan 23 22:55:28 2013 +0100
1.2 +++ b/emul/compact/src/main/java/java/io/InputStreamReader.java Wed Jan 23 23:16:47 2013 +0100
1.3 @@ -25,10 +25,6 @@
1.4
1.5 package java.io;
1.6
1.7 -import java.nio.charset.Charset;
1.8 -import java.nio.charset.CharsetDecoder;
1.9 -import sun.nio.cs.StreamDecoder;
1.10 -
1.11
1.12 /**
1.13 * An InputStreamReader is a bridge from byte streams to character streams: It
1.14 @@ -61,8 +57,6 @@
1.15
1.16 public class InputStreamReader extends Reader {
1.17
1.18 - private final StreamDecoder sd;
1.19 -
1.20 /**
1.21 * Creates an InputStreamReader that uses the default charset.
1.22 *
1.23 @@ -70,12 +64,6 @@
1.24 */
1.25 public InputStreamReader(InputStream in) {
1.26 super(in);
1.27 - try {
1.28 - sd = StreamDecoder.forInputStreamReader(in, this, (String)null); // ## check lock object
1.29 - } catch (UnsupportedEncodingException e) {
1.30 - // The default encoding should always be available
1.31 - throw new Error(e);
1.32 - }
1.33 }
1.34
1.35 /**
1.36 @@ -95,9 +83,9 @@
1.37 throws UnsupportedEncodingException
1.38 {
1.39 super(in);
1.40 - if (charsetName == null)
1.41 - throw new NullPointerException("charsetName");
1.42 - sd = StreamDecoder.forInputStreamReader(in, this, charsetName);
1.43 + if (!charsetName.toUpperCase().equals("UTF-8")) {
1.44 + throw new UnsupportedEncodingException(charsetName);
1.45 + }
1.46 }
1.47
1.48 /**
1.49 @@ -156,7 +144,7 @@
1.50 * @spec JSR-51
1.51 */
1.52 public String getEncoding() {
1.53 - return sd.getEncoding();
1.54 + return "UTF-8";
1.55 }
1.56
1.57 /**
1.58 @@ -168,7 +156,7 @@
1.59 * @exception IOException If an I/O error occurs
1.60 */
1.61 public int read() throws IOException {
1.62 - return sd.read();
1.63 + return ((InputStream)lock).read();
1.64 }
1.65
1.66 /**
1.67 @@ -184,7 +172,15 @@
1.68 * @exception IOException If an I/O error occurs
1.69 */
1.70 public int read(char cbuf[], int offset, int length) throws IOException {
1.71 - return sd.read(cbuf, offset, length);
1.72 + for (int i = 0; i < length; i++) {
1.73 + int ch = read();
1.74 + if (ch == -1) {
1.75 + if (i == 0) return -1;
1.76 + return i;
1.77 + }
1.78 + cbuf[offset++] = (char) ch;
1.79 + }
1.80 + return length;
1.81 }
1.82
1.83 /**
1.84 @@ -195,10 +191,10 @@
1.85 * @exception IOException If an I/O error occurs
1.86 */
1.87 public boolean ready() throws IOException {
1.88 - return sd.ready();
1.89 + return ((InputStream)lock).available() > 0;
1.90 }
1.91
1.92 public void close() throws IOException {
1.93 - sd.close();
1.94 + ((InputStream)lock).close();
1.95 }
1.96 }