Reading streams in Java isn't completely easy: Prevent allocating zero length array.
1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Mon Mar 28 06:34:38 2016 +0200
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Mon Mar 28 07:22:41 2016 +0200
1.3 @@ -107,7 +107,11 @@
1.4 append("\n ").append(getExportsObject()).append("['registerResource']('");
1.5 append(r).append("', '");
1.6 InputStream is = this.resources.get(r);
1.7 - byte[] arr = new byte[is.available()];
1.8 + int avail = is.available();
1.9 + if (avail <= 0) {
1.10 + avail = 4096;
1.11 + }
1.12 + byte[] arr = new byte[avail];
1.13 int offset = 0;
1.14 for (;;) {
1.15 if (offset == arr.length) {