Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / io / ByteArrayInputStream.js
1 Clazz.load (["java.io.InputStream"], "java.io.ByteArrayInputStream", ["java.lang.IndexOutOfBoundsException", "$.NullPointerException"], function () {
2 c$ = Clazz.decorateAsClass (function () {
3 this.buf = null;
4 this.pos = 0;
5 this.$mark = 0;
6 this.count = 0;
7 Clazz.instantialize (this, arguments);
8 }, java.io, "ByteArrayInputStream", java.io.InputStream);
9 Clazz.makeConstructor (c$, 
10 function (buf) {
11 Clazz.superConstructor (this, java.io.ByteArrayInputStream, []);
12 this.buf = buf;
13 this.pos = 0;
14 this.count = buf.length;
15 }, "~A");
16 Clazz.overrideMethod (c$, "readByteAsInt", 
17 function () {
18 return (this.pos < this.count) ? (this.buf[this.pos++] & 0xff) : -1;
19 });
20 Clazz.overrideMethod (c$, "read", 
21 function (b, off, len) {
22 if (b == null) {
23 throw  new NullPointerException ();
24 }
25     if (arguments.length == 1) { off = 0; len = b.length; }
26
27 if (off < 0 || len < 0 || len > b.length - off) {
28 throw  new IndexOutOfBoundsException ();
29 }if (this.pos >= this.count) {
30 return -1;
31 }var avail = this.count - this.pos;
32 if (len > avail) {
33 len = avail;
34 }if (len <= 0) {
35 return 0;
36 }System.arraycopy (this.buf, this.pos, b, off, len);
37 this.pos += len;
38 return len;
39 }, "~A,~N,~N");
40 Clazz.overrideMethod (c$, "skip", 
41 function (n) {
42 var k = this.count - this.pos;
43 if (n < k) {
44 k = n < 0 ? 0 : n;
45 }this.pos += k;
46 return k;
47 }, "~N");
48 Clazz.overrideMethod (c$, "available", 
49 function () {
50 return this.count - this.pos;
51 });
52 Clazz.overrideMethod (c$, "markSupported", 
53 function () {
54 return true;
55 });
56 Clazz.overrideMethod (c$, "mark", 
57 function (readAheadLimit) {
58 this.$mark = this.pos;
59 }, "~N");
60 Clazz.overrideMethod (c$, "resetStream", 
61 function () {
62 });
63 Clazz.overrideMethod (c$, "reset", 
64 function () {
65 this.pos = this.$mark;
66 });
67 Clazz.overrideMethod (c$, "close", 
68 function () {
69 });
70 });