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