JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / io / PushbackInputStream.js
1 Clazz.load (["java.io.FilterInputStream"], "java.io.PushbackInputStream", ["java.io.IOException", "java.lang.IllegalArgumentException", "$.IndexOutOfBoundsException", "$.NullPointerException"], function () {\r
2 c$ = Clazz.decorateAsClass (function () {\r
3 this.buf = null;\r
4 this.pos = 0;\r
5 Clazz.instantialize (this, arguments);\r
6 }, java.io, "PushbackInputStream", java.io.FilterInputStream);\r
7 Clazz.defineMethod (c$, "ensureOpen", \r
8  function () {\r
9 if (this.$in == null) throw  new java.io.IOException ("Stream closed");\r
10 });\r
11 Clazz.makeConstructor (c$, \r
12 function ($in, size) {\r
13 Clazz.superConstructor (this, java.io.PushbackInputStream, [$in]);\r
14 if (size <= 0) {\r
15 throw  new IllegalArgumentException ("size <= 0");\r
16 }this.buf =  Clazz.newByteArray (size, 0);\r
17 this.pos = size;\r
18 }, "java.io.InputStream,~N");\r
19 Clazz.overrideMethod (c$, "readByteAsInt", \r
20 function () {\r
21 this.ensureOpen ();\r
22 if (this.pos < this.buf.length) {\r
23 return this.buf[this.pos++] & 0xff;\r
24 }return this.$in.readByteAsInt ();\r
25 });\r
26 Clazz.overrideMethod (c$, "read", \r
27 function (b, off, len) {\r
28 this.ensureOpen ();\r
29 if (b == null) {\r
30 throw  new NullPointerException ();\r
31\r
32     if (arguments.length == 1) { off = 0; len = b.length; }\r
33 \r
34 if (off < 0 || len < 0 || len > b.length - off) {\r
35 throw  new IndexOutOfBoundsException ();\r
36 } else if (len == 0) {\r
37 return 0;\r
38 }var avail = this.buf.length - this.pos;\r
39 if (avail > 0) {\r
40 if (len < avail) {\r
41 avail = len;\r
42 }System.arraycopy (this.buf, this.pos, b, off, avail);\r
43 this.pos += avail;\r
44 off += avail;\r
45 len -= avail;\r
46 }if (len > 0) {\r
47 len = this.$in.read (b, off, len);\r
48 if (len == -1) {\r
49 return avail == 0 ? -1 : avail;\r
50 }return avail + len;\r
51 }return avail;\r
52 }, "~A,~N,~N");\r
53 Clazz.defineMethod (c$, "unreadByte", \r
54 function (b) {\r
55 this.ensureOpen ();\r
56 if (this.pos == 0) {\r
57 throw  new java.io.IOException ("Push back buffer is full");\r
58 }this.buf[--this.pos] = b;\r
59 }, "~N");\r
60 Clazz.defineMethod (c$, "unread", \r
61 function (b, off, len) {\r
62 this.ensureOpen ();\r
63 if (len > this.pos) {\r
64 throw  new java.io.IOException ("Push back buffer is full");\r
65 }this.pos -= len;\r
66 System.arraycopy (b, off, this.buf, this.pos, len);\r
67 }, "~A,~N,~N");\r
68 Clazz.overrideMethod (c$, "available", \r
69 function () {\r
70 this.ensureOpen ();\r
71 var n = this.buf.length - this.pos;\r
72 var avail = this.$in.available ();\r
73 return n > (2147483647 - avail) ? 2147483647 : n + avail;\r
74 });\r
75 Clazz.overrideMethod (c$, "skip", \r
76 function (n) {\r
77 this.ensureOpen ();\r
78 if (n <= 0) {\r
79 return 0;\r
80 }var pskip = this.buf.length - this.pos;\r
81 if (pskip > 0) {\r
82 if (n < pskip) {\r
83 pskip = n;\r
84 }this.pos += pskip;\r
85 n -= pskip;\r
86 }if (n > 0) {\r
87 pskip += this.$in.skip (n);\r
88 }return pskip;\r
89 }, "~N");\r
90 Clazz.overrideMethod (c$, "markSupported", \r
91 function () {\r
92 return false;\r
93 });\r
94 Clazz.overrideMethod (c$, "mark", \r
95 function (readlimit) {\r
96 }, "~N");\r
97 Clazz.overrideMethod (c$, "reset", \r
98 function () {\r
99 throw  new java.io.IOException ("mark/reset not supported");\r
100 });\r
101 Clazz.overrideMethod (c$, "close", \r
102 function () {\r
103 if (this.$in == null) return;\r
104 this.$in.close ();\r
105 this.$in = null;\r
106 this.buf = null;\r
107 });\r
108 });\r