1.1 --- a/emul/mini/src/main/java/java/net/URL.java Thu Jan 31 19:21:37 2013 +0100
1.2 +++ b/emul/mini/src/main/java/java/net/URL.java Fri Feb 01 14:16:26 2013 +0100
1.3 @@ -25,6 +25,7 @@
1.4
1.5 package java.net;
1.6
1.7 +import java.io.ByteArrayInputStream;
1.8 import java.io.IOException;
1.9 import java.io.InputStream;
1.10 import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.11 @@ -962,7 +963,11 @@
1.12 if (is != null) {
1.13 return is;
1.14 }
1.15 - throw new IOException();
1.16 + byte[] arr = (byte[]) getContent(new Class[] { byte[].class });
1.17 + if (arr == null) {
1.18 + throw new IOException();
1.19 + }
1.20 + return new ByteArrayInputStream(arr);
1.21 }
1.22
1.23 /**
2.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java Thu Jan 31 19:21:37 2013 +0100
2.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java Fri Feb 01 14:16:26 2013 +0100
2.3 @@ -17,6 +17,7 @@
2.4 */
2.5 package org.apidesign.bck2brwsr.tck;
2.6
2.7 +import java.io.InputStream;
2.8 import java.net.URL;
2.9 import org.apidesign.bck2brwsr.core.JavaScriptBody;
2.10 import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
2.11 @@ -65,6 +66,17 @@
2.12 assert arr.length == 1 : "One byte " + arr.length;
2.13 assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]);
2.14 }
2.15 +
2.16 + @HttpResource(path = "/bytes", content = "", resource = "0xfe", mimeType = "x-application/binary")
2.17 + @BrwsrTest
2.18 + public void testReadByteViaInputStream() throws Exception {
2.19 + URL url = new URL("http:/bytes");
2.20 + InputStream is = url.openStream();
2.21 + byte[] arr = new byte[10];
2.22 + int len = is.read(arr);
2.23 + assert len == 1 : "One byte " + len;
2.24 + assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]);
2.25 + }
2.26
2.27 @JavaScriptBody(args = { "url" }, body =
2.28 "var req = new XMLHttpRequest();\n"