1ded1b55e2eff2f585459fba963016c7585cff7a
[jalviewjs.git] / site / swingjs / j2s / jssun / misc / IOUtils.js
1 Clazz.declarePackage ("jssun.misc");
2 Clazz.load (null, "jssun.misc.IOUtils", ["java.io.EOFException", "java.util.Arrays"], function () {
3 c$ = Clazz.declareType (jssun.misc, "IOUtils");
4 c$.readFully = Clazz.defineMethod (c$, "readFully", 
5 function (is, length, readAll) {
6 var output =  Clazz.newByteArray (-1, []);
7 if (length == -1) length = 2147483647;
8 var pos = 0;
9 while (pos < length) {
10 var bytesToRead;
11 if (pos >= output.length) {
12 bytesToRead = Math.min (length - pos, output.length + 1024);
13 if (output.length < pos + bytesToRead) {
14 output = java.util.Arrays.copyOf (output, pos + bytesToRead);
15 }} else {
16 bytesToRead = output.length - pos;
17 }var cc = is.read (output, pos, bytesToRead);
18 if (cc < 0) {
19 if (readAll && length != 2147483647) {
20 throw  new java.io.EOFException ("Detect premature EOF");
21 } else {
22 if (output.length != pos) {
23 output = java.util.Arrays.copyOf (output, pos);
24 }break;
25 }}pos += cc;
26 }
27 return output;
28 }, "java.io.InputStream,~N,~B");
29 });