# HG changeset patch # User Jaroslav Tulach # Date 1359724586 -3600 # Node ID f203b54b3d3385f93dd12e62afed83479239daa2 # Parent f08eb4df84c1021c26650f08d614dbe2f491d0a9 URL.openStream works via XHR diff -r f08eb4df84c1 -r f203b54b3d33 emul/mini/src/main/java/java/net/URL.java --- a/emul/mini/src/main/java/java/net/URL.java Thu Jan 31 19:21:37 2013 +0100 +++ b/emul/mini/src/main/java/java/net/URL.java Fri Feb 01 14:16:26 2013 +0100 @@ -25,6 +25,7 @@ package java.net; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import org.apidesign.bck2brwsr.core.JavaScriptBody; @@ -962,7 +963,11 @@ if (is != null) { return is; } - throw new IOException(); + byte[] arr = (byte[]) getContent(new Class[] { byte[].class }); + if (arr == null) { + throw new IOException(); + } + return new ByteArrayInputStream(arr); } /** diff -r f08eb4df84c1 -r f203b54b3d33 vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java Thu Jan 31 19:21:37 2013 +0100 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java Fri Feb 01 14:16:26 2013 +0100 @@ -17,6 +17,7 @@ */ package org.apidesign.bck2brwsr.tck; +import java.io.InputStream; import java.net.URL; import org.apidesign.bck2brwsr.core.JavaScriptBody; import org.apidesign.bck2brwsr.vmtest.BrwsrTest; @@ -65,6 +66,17 @@ assert arr.length == 1 : "One byte " + arr.length; assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]); } + + @HttpResource(path = "/bytes", content = "", resource = "0xfe", mimeType = "x-application/binary") + @BrwsrTest + public void testReadByteViaInputStream() throws Exception { + URL url = new URL("http:/bytes"); + InputStream is = url.openStream(); + byte[] arr = new byte[10]; + int len = is.read(arr); + assert len == 1 : "One byte " + len; + assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]); + } @JavaScriptBody(args = { "url" }, body = "var req = new XMLHttpRequest();\n"