1 Clazz.load (["java.io.FilterInputStream"], "java.io.BufferedInputStream", ["java.io.IOException", "java.lang.IndexOutOfBoundsException"], function () {
2 c$ = Clazz.decorateAsClass (function () {
8 Clazz.instantialize (this, arguments);
9 }, java.io, "BufferedInputStream", java.io.FilterInputStream);
10 Clazz.defineMethod (c$, "getInIfOpen",
13 if (input == null) throw new java.io.IOException ("Stream closed");
16 Clazz.defineMethod (c$, "getBufIfOpen",
18 var buffer = this.buf;
19 if (buffer == null) throw new java.io.IOException ("Stream closed");
22 Clazz.overrideMethod (c$, "resetStream",
25 Clazz.makeConstructor (c$,
27 Clazz.superConstructor (this, java.io.BufferedInputStream, [$in]);
28 this.buf = Clazz.newByteArray (8192, 0);
29 }, "java.io.InputStream");
30 Clazz.defineMethod (c$, "fill",
32 var buffer = this.getBufIfOpen ();
33 if (this.markpos < 0) this.pos = 0;
34 else if (this.pos >= buffer.length) if (this.markpos > 0) {
35 var sz = this.pos - this.markpos;
36 System.arraycopy (buffer, this.markpos, buffer, 0, sz);
39 } else if (buffer.length >= this.marklimit) {
43 var nsz = this.pos * 2;
44 if (nsz > this.marklimit) nsz = this.marklimit;
45 var nbuf = Clazz.newByteArray (nsz, 0);
46 System.arraycopy (buffer, 0, nbuf, 0, this.pos);
47 buffer = this.buf = nbuf;
48 }this.count = this.pos;
49 var n = this.getInIfOpen ().read (buffer, this.pos, buffer.length - this.pos);
50 if (n > 0) this.count = n + this.pos;
52 Clazz.overrideMethod (c$, "readByteAsInt",
54 if (this.pos >= this.count) {
56 if (this.pos >= this.count) return -1;
57 }return this.getBufIfOpen ()[this.pos++] & 0xff;
59 Clazz.defineMethod (c$, "read1",
60 function (b, off, len) {
61 var avail = this.count - this.pos;
63 if (len >= this.getBufIfOpen ().length && this.markpos < 0) {
64 return this.getInIfOpen ().read (b, off, len);
66 avail = this.count - this.pos;
67 if (avail <= 0) return -1;
68 }var cnt = (avail < len) ? avail : len;
69 System.arraycopy (this.getBufIfOpen (), this.pos, b, off, cnt);
73 Clazz.overrideMethod (c$, "read",
74 function (b, off, len) {
75 if (arguments.length == 1) {
80 if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
81 throw new IndexOutOfBoundsException ();
82 } else if (len == 0) {
86 var nread = this.read1 (b, off + n, len - n);
87 if (nread <= 0) return (n == 0) ? nread : n;
89 if (n >= len) return n;
91 if (input != null && input.available () <= 0) return n;
94 Clazz.overrideMethod (c$, "skip",
99 }var avail = this.count - this.pos;
101 if (this.markpos < 0) return this.getInIfOpen ().skip (n);
103 avail = this.count - this.pos;
104 if (avail <= 0) return 0;
105 }var skipped = (avail < n) ? avail : n;
109 Clazz.overrideMethod (c$, "available",
111 var n = this.count - this.pos;
112 var avail = this.getInIfOpen ().available ();
113 return n > (2147483647 - avail) ? 2147483647 : n + avail;
115 Clazz.overrideMethod (c$, "mark",
116 function (readlimit) {
117 this.marklimit = readlimit;
118 this.markpos = this.pos;
120 Clazz.overrideMethod (c$, "reset",
122 this.getBufIfOpen ();
123 if (this.markpos < 0) throw new java.io.IOException ("Resetting to invalid mark");
124 this.pos = this.markpos;
126 Clazz.overrideMethod (c$, "markSupported",
130 Clazz.overrideMethod (c$, "close",
132 var input = this.$in;
134 if (input != null) input.close ();
137 Clazz.defineStatics (c$,
138 "DEFAULT_BUFFER_SIZE", 8192);