Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / io / InputStream.js
1 Clazz.load (null, "java.io.InputStream", ["java.io.IOException", "java.lang.IndexOutOfBoundsException", "$.NullPointerException"], function () {
2 c$ = Clazz.declareType (java.io, "InputStream");
3 Clazz.defineMethod (c$, "read", 
4 function (b, off, len) {
5 if (b == null) {
6 throw  new NullPointerException ();
7
8     if (arguments.length == 1) { off = 0; len = b.length; }
9
10 if (off < 0 || len < 0 || len > b.length - off) {
11 throw  new IndexOutOfBoundsException ();
12 } else if (len == 0) {
13 return 0;
14 }var c = this.readByteAsInt ();
15 if (c == -1) {
16 return -1;
17 }b[off] = c;
18 var i = 1;
19 try {
20 for (; i < len; i++) {
21 c = this.readByteAsInt ();
22 if (c == -1) {
23 break;
24 }b[off + i] = c;
25 }
26 } catch (ee) {
27 if (Clazz.exceptionOf (ee, java.io.IOException)) {
28 } else {
29 throw ee;
30 }
31 }
32 return i;
33 }, "~A,~N,~N");
34 Clazz.defineMethod (c$, "skip", 
35 function (n) {
36 var remaining = n;
37 var nr;
38 if (java.io.InputStream.skipBuffer == null) java.io.InputStream.skipBuffer =  Clazz.newByteArray (2048, 0);
39 var localSkipBuffer = java.io.InputStream.skipBuffer;
40 if (n <= 0) {
41 return 0;
42 }while (remaining > 0) {
43 nr = this.read (localSkipBuffer, 0, Math.min (2048, remaining));
44 if (nr < 0) {
45 break;
46 }remaining -= nr;
47 }
48 return n - remaining;
49 }, "~N");
50 Clazz.defineMethod (c$, "available", 
51 function () {
52 return 0;
53 });
54 Clazz.defineMethod (c$, "close", 
55 function () {
56 });
57 Clazz.defineMethod (c$, "mark", 
58 function (readlimit) {
59 }, "~N");
60 Clazz.defineMethod (c$, "reset", 
61 function () {
62 throw  new java.io.IOException ("mark/reset not supported");
63 });
64 Clazz.defineMethod (c$, "markSupported", 
65 function () {
66 return false;
67 });
68 Clazz.defineMethod (c$, "resetStream", 
69 function () {
70 });
71 Clazz.defineStatics (c$,
72 "SKIP_BUFFER_SIZE", 2048,
73 "skipBuffer", null);
74 });