package java.io;

import static jsweet.util.Lang.any;

import java.nio.charset.Charset;

/**
 * JSweet implementation.
 */

public class InputStreamReader extends Reader {

	InputStream in;

	public InputStreamReader(InputStream in) {
		super(in);
		this.in = in;
	}

	public InputStreamReader(InputStream in, String charsetName) throws UnsupportedEncodingException {
		super(in);
		this.in = in;
	}

	public InputStreamReader(InputStream in, Charset cs) {
		super(in);
		this.in = in;
		if (cs == null)
			throw new NullPointerException("charset");
	}

	public int read(char cbuf[], int offset, int length) throws IOException {
		byte[] buf = any(cbuf);
		return in.read(buf, offset, length);
	}

	public boolean ready() throws IOException {
		return in.available()>0;
	}

	public void close() throws IOException {
		in.close();
	}
}

@@ -46,16 +46,55 @@
 ang.any;
+%0Aimport static jsweet.util.Lang.string;
 %0A%0Aimport
@@ -680,56 +680,240 @@
 f = 
-any(cbuf);%0A%09%09return in.read(buf, offset, length)
+new byte%5Blength - offset%5D;%0A%09%09int success = in.read(buf, 0, length);%0A%0A%09%09if (success %3E 0) %7B%0A%09%09%09for (int i = 0; i %3C success; ++i) %7B%0A%09%09%09%09cbuf%5Bi + offset%5D = string(def.js.String.fromCharCode(buf%5Bi%5D)).charAt(0);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09return success
 ;%0A%09%7D

fix inputStreamReader