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