# HG changeset patch # User Jaroslav Tulach # Date 1358979407 -3600 # Node ID f06b2d18eb52d2506da34388a86fd4dd18ae456f # Parent 53fafe3848039ac4e28871cc43ae08a08e947f25 ASCII implementation of the reader diff -r 53fafe384803 -r f06b2d18eb52 emul/compact/src/main/java/java/io/InputStreamReader.java --- a/emul/compact/src/main/java/java/io/InputStreamReader.java Wed Jan 23 22:55:28 2013 +0100 +++ b/emul/compact/src/main/java/java/io/InputStreamReader.java Wed Jan 23 23:16:47 2013 +0100 @@ -25,10 +25,6 @@ package java.io; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import sun.nio.cs.StreamDecoder; - /** * An InputStreamReader is a bridge from byte streams to character streams: It @@ -61,8 +57,6 @@ public class InputStreamReader extends Reader { - private final StreamDecoder sd; - /** * Creates an InputStreamReader that uses the default charset. * @@ -70,12 +64,6 @@ */ public InputStreamReader(InputStream in) { super(in); - try { - sd = StreamDecoder.forInputStreamReader(in, this, (String)null); // ## check lock object - } catch (UnsupportedEncodingException e) { - // The default encoding should always be available - throw new Error(e); - } } /** @@ -95,9 +83,9 @@ throws UnsupportedEncodingException { super(in); - if (charsetName == null) - throw new NullPointerException("charsetName"); - sd = StreamDecoder.forInputStreamReader(in, this, charsetName); + if (!charsetName.toUpperCase().equals("UTF-8")) { + throw new UnsupportedEncodingException(charsetName); + } } /** @@ -156,7 +144,7 @@ * @spec JSR-51 */ public String getEncoding() { - return sd.getEncoding(); + return "UTF-8"; } /** @@ -168,7 +156,7 @@ * @exception IOException If an I/O error occurs */ public int read() throws IOException { - return sd.read(); + return ((InputStream)lock).read(); } /** @@ -184,7 +172,15 @@ * @exception IOException If an I/O error occurs */ public int read(char cbuf[], int offset, int length) throws IOException { - return sd.read(cbuf, offset, length); + for (int i = 0; i < length; i++) { + int ch = read(); + if (ch == -1) { + if (i == 0) return -1; + return i; + } + cbuf[offset++] = (char) ch; + } + return length; } /** @@ -195,10 +191,10 @@ * @exception IOException If an I/O error occurs */ public boolean ready() throws IOException { - return sd.ready(); + return ((InputStream)lock).available() > 0; } public void close() throws IOException { - sd.close(); + ((InputStream)lock).close(); } }