1.1 --- a/emul/mini/src/main/java/java/net/URL.java Thu Jan 31 18:22:14 2013 +0100
1.2 +++ b/emul/mini/src/main/java/java/net/URL.java Thu Jan 31 18:45:00 2013 +0100
1.3 @@ -987,6 +987,17 @@
1.4 )
1.5 private static native String loadText(String url) throws IOException;
1.6
1.7 + @JavaScriptBody(args = { "url", "arr" }, body = ""
1.8 + + "var request = new XMLHttpRequest();\n"
1.9 + + "request.open('GET', url, false);\n"
1.10 + + "request.overrideMimeType('text\\/plain; charset=x-user-defined');\n"
1.11 + + "request.send();\n"
1.12 + + "var t = request.responseText;\n"
1.13 + + "for (var i = 0; i < t.length; i++) arr.push(t.charCodeAt(i) & 0xff);\n"
1.14 + + "return arr;\n"
1.15 + )
1.16 + private static native Object loadBytes(String url, byte[] arr) throws IOException;
1.17 +
1.18 /**
1.19 * Gets the contents of this URL. This method is a shorthand for:
1.20 * <blockquote><pre>
1.21 @@ -1005,7 +1016,10 @@
1.22 throws java.io.IOException {
1.23 for (Class<?> c : classes) {
1.24 if (c == String.class) {
1.25 - return getContent();
1.26 + return loadText(toExternalForm());
1.27 + }
1.28 + if (c == byte[].class) {
1.29 + return loadBytes(toExternalForm(), new byte[0]);
1.30 }
1.31 }
1.32 return null;
2.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java Thu Jan 31 18:22:14 2013 +0100
2.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java Thu Jan 31 18:45:00 2013 +0100
2.3 @@ -54,6 +54,17 @@
2.4 assert "Hello via URL!".equals(msg) : "The message was " + msg;
2.5 return msg;
2.6 }
2.7 +
2.8 + @HttpResource(path = "/bytes", content = "\u00fe", mimeType = "x-application/binary")
2.9 + @BrwsrTest
2.10 + public void testReadByte() throws Exception {
2.11 + URL url = new URL("http:/bytes");
2.12 + final Object res = url.getContent(new Class[] { byte[].class });
2.13 + assert res instanceof byte[] : "Expecting byte[]: " + res;
2.14 + byte[] arr = (byte[]) res;
2.15 + assert arr.length == 1 : "One byte " + arr.length;
2.16 + assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]);
2.17 + }
2.18
2.19 @JavaScriptBody(args = { "url" }, body =
2.20 "var req = new XMLHttpRequest();\n"