Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / JU / InflaterInputStream.js
1 Clazz.declarePackage ("JU");
2 Clazz.load (["java.io.FilterInputStream"], "JU.InflaterInputStream", ["java.io.EOFException", "$.IOException", "java.lang.IllegalArgumentException", "$.IndexOutOfBoundsException", "$.NullPointerException"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.inflater = null;
5 this.buf = null;
6 this.len = 0;
7 this.closed = false;
8 this.eof = false;
9 this.close_in = true;
10 this.myinflater = false;
11 this.byte1 = null;
12 this.b = null;
13 Clazz.instantialize (this, arguments);
14 }, JU, "InflaterInputStream", java.io.FilterInputStream);
15 Clazz.prepareFields (c$, function () {
16 this.byte1 =  Clazz.newByteArray (1, 0);
17 this.b =  Clazz.newByteArray (512, 0);
18 });
19 Clazz.makeConstructor (c$, 
20 function ($in, inflater, size, close_in) {
21 Clazz.superConstructor (this, JU.InflaterInputStream, [$in]);
22 this.inflater = inflater;
23 this.buf =  Clazz.newByteArray (size, 0);
24 this.close_in = close_in;
25 }, "java.io.InputStream,JU.Inflater,~N,~B");
26 Clazz.overrideMethod (c$, "readByteAsInt", 
27 function () {
28 if (this.closed) {
29 throw  new java.io.IOException ("Stream closed");
30 }return this.read (this.byte1, 0, 1) == -1 ? -1 : this.byte1[0] & 0xff;
31 });
32 Clazz.overrideMethod (c$, "read", 
33 function (b, off, len) {
34 return this.readInf (b, off, len);
35 }, "~A,~N,~N");
36 Clazz.defineMethod (c$, "readInf", 
37 function (b, off, len) {
38 if (this.closed) {
39 throw  new java.io.IOException ("Stream closed");
40 }if (b == null) {
41 throw  new NullPointerException ();
42 } else if (off < 0 || len < 0 || len > b.length - off) {
43 throw  new IndexOutOfBoundsException ();
44 } else if (len == 0) {
45 return 0;
46 } else if (this.eof) {
47 return -1;
48 }var n = 0;
49 this.inflater.setOutput (b, off, len);
50 while (!this.eof) {
51 if (this.inflater.avail_in == 0) this.fill ();
52 var err = this.inflater.inflate (0);
53 n += this.inflater.next_out_index - off;
54 off = this.inflater.next_out_index;
55 switch (err) {
56 case -3:
57 throw  new java.io.IOException (this.inflater.msg);
58 case 1:
59 case 2:
60 this.eof = true;
61 if (err == 2) return -1;
62 break;
63 default:
64 }
65 if (this.inflater.avail_out == 0) break;
66 }
67 return n;
68 }, "~A,~N,~N");
69 Clazz.overrideMethod (c$, "available", 
70 function () {
71 if (this.closed) {
72 throw  new java.io.IOException ("Stream closed");
73 }return (this.eof ? 0 : 1);
74 });
75 Clazz.overrideMethod (c$, "skip", 
76 function (n) {
77 if (n < 0) {
78 throw  new IllegalArgumentException ("negative skip length");
79 }if (this.closed) {
80 throw  new java.io.IOException ("Stream closed");
81 }var max = Math.min (n, 2147483647);
82 var total = 0;
83 while (total < max) {
84 var len = max - total;
85 if (len > this.b.length) {
86 len = this.b.length;
87 }len = this.read (this.b, 0, len);
88 if (len == -1) {
89 this.eof = true;
90 break;
91 }total += len;
92 }
93 return total;
94 }, "~N");
95 Clazz.overrideMethod (c$, "close", 
96 function () {
97 if (!this.closed) {
98 if (this.myinflater) this.inflater.end ();
99 if (this.close_in) this.$in.close ();
100 this.closed = true;
101 }});
102 Clazz.defineMethod (c$, "fill", 
103 function () {
104 if (this.closed) {
105 throw  new java.io.IOException ("Stream closed");
106 }this.len = this.$in.read (this.buf, 0, this.buf.length);
107 if (this.len == -1) {
108 if (this.inflater.istate.wrap == 0 && !this.inflater.finished ()) {
109 this.buf[0] = 0;
110 this.len = 1;
111 } else if (this.inflater.istate.was != -1) {
112 throw  new java.io.IOException ("footer is not found");
113 } else {
114 throw  new java.io.EOFException ("Unexpected end of ZLIB input stream");
115 }}this.inflater.setInput (this.buf, 0, this.len, true);
116 });
117 Clazz.overrideMethod (c$, "markSupported", 
118 function () {
119 return false;
120 });
121 Clazz.overrideMethod (c$, "mark", 
122 function (readlimit) {
123 }, "~N");
124 Clazz.overrideMethod (c$, "reset", 
125 function () {
126 throw  new java.io.IOException ("mark/reset not supported");
127 });
128 Clazz.defineMethod (c$, "getTotalIn", 
129 function () {
130 return this.inflater.getTotalIn ();
131 });
132 Clazz.defineMethod (c$, "getTotalOut", 
133 function () {
134 return this.inflater.getTotalOut ();
135 });
136 Clazz.defineMethod (c$, "getAvailIn", 
137 function () {
138 if (this.inflater.avail_in <= 0) return null;
139 var tmp =  Clazz.newByteArray (this.inflater.avail_in, 0);
140 System.arraycopy (this.inflater.next_in, this.inflater.next_in_index, tmp, 0, this.inflater.avail_in);
141 return tmp;
142 });
143 Clazz.defineMethod (c$, "readHeader", 
144 function () {
145 var empty = "".getBytes ();
146 this.inflater.setInput (empty, 0, 0, false);
147 this.inflater.setOutput (empty, 0, 0);
148 var err = this.inflater.inflate (0);
149 if (!this.inflater.istate.inParsingHeader ()) {
150 return;
151 }var b1 =  Clazz.newByteArray (1, 0);
152 do {
153 var i = this.$in.read (b1, 0, 1);
154 if (i <= 0) throw  new java.io.IOException ("no input");
155 this.inflater.setInput (b1, 0, b1.length, false);
156 err = this.inflater.inflate (0);
157 if (err != 0) throw  new java.io.IOException (this.inflater.msg);
158 } while (this.inflater.istate.inParsingHeader ());
159 });
160 Clazz.defineMethod (c$, "getInflater", 
161 function () {
162 return this.inflater;
163 });
164 Clazz.defineStatics (c$,
165 "DEFAULT_BUFSIZE", 512);
166 });