JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / JU / ZStream.js
1 Clazz.declarePackage ("JU");\r
2 Clazz.load (null, "JU.ZStream", ["JU.Adler32"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.next_in = null;\r
5 this.next_in_index = 0;\r
6 this.avail_in = 0;\r
7 this.total_in = 0;\r
8 this.next_out = null;\r
9 this.next_out_index = 0;\r
10 this.avail_out = 0;\r
11 this.total_out = 0;\r
12 this.msg = null;\r
13 this.dstate = null;\r
14 this.istate = null;\r
15 this.data_type = 0;\r
16 this.checksum = null;\r
17 Clazz.instantialize (this, arguments);\r
18 }, JU, "ZStream");\r
19 Clazz.defineMethod (c$, "setAdler32", \r
20 function () {\r
21 this.checksum =  new JU.Adler32 ();\r
22 });\r
23 Clazz.defineMethod (c$, "inflate", \r
24 function (f) {\r
25 if (this.istate == null) return -2;\r
26 return this.istate.inflate (f);\r
27 }, "~N");\r
28 Clazz.defineMethod (c$, "deflate", \r
29 function (flush) {\r
30 if (this.dstate == null) {\r
31 return -2;\r
32 }return this.dstate.deflate (flush);\r
33 }, "~N");\r
34 Clazz.defineMethod (c$, "flush_pending", \r
35 function () {\r
36 var len = this.dstate.pending;\r
37 if (len > this.avail_out) len = this.avail_out;\r
38 if (len == 0) return;\r
39 System.arraycopy (this.dstate.pending_buf, this.dstate.pending_out, this.next_out, this.next_out_index, len);\r
40 this.next_out_index += len;\r
41 this.dstate.pending_out += len;\r
42 this.total_out += len;\r
43 this.avail_out -= len;\r
44 this.dstate.pending -= len;\r
45 if (this.dstate.pending == 0) {\r
46 this.dstate.pending_out = 0;\r
47 }});\r
48 Clazz.defineMethod (c$, "read_buf", \r
49 function (buf, start, size) {\r
50 var len = this.avail_in;\r
51 if (len > size) len = size;\r
52 if (len == 0) return 0;\r
53 this.avail_in -= len;\r
54 if (this.dstate.wrap != 0) {\r
55 this.checksum.update (this.next_in, this.next_in_index, len);\r
56 }System.arraycopy (this.next_in, this.next_in_index, buf, start, len);\r
57 this.next_in_index += len;\r
58 this.total_in += len;\r
59 return len;\r
60 }, "~A,~N,~N");\r
61 Clazz.defineMethod (c$, "getAdler", \r
62 function () {\r
63 return this.checksum.getValue ();\r
64 });\r
65 Clazz.defineMethod (c$, "free", \r
66 function () {\r
67 this.next_in = null;\r
68 this.next_out = null;\r
69 this.msg = null;\r
70 });\r
71 Clazz.defineMethod (c$, "setOutput", \r
72 function (buf, off, len) {\r
73 this.next_out = buf;\r
74 this.next_out_index = off;\r
75 this.avail_out = len;\r
76 }, "~A,~N,~N");\r
77 Clazz.defineMethod (c$, "setInput", \r
78 function (buf, off, len, append) {\r
79 if (len <= 0 && append && this.next_in != null) return;\r
80 if (this.avail_in > 0 && append) {\r
81 var tmp =  Clazz.newByteArray (this.avail_in + len, 0);\r
82 System.arraycopy (this.next_in, this.next_in_index, tmp, 0, this.avail_in);\r
83 System.arraycopy (buf, off, tmp, this.avail_in, len);\r
84 this.next_in = tmp;\r
85 this.next_in_index = 0;\r
86 this.avail_in += len;\r
87 } else {\r
88 this.next_in = buf;\r
89 this.next_in_index = off;\r
90 this.avail_in = len;\r
91 }}, "~A,~N,~N,~B");\r
92 Clazz.defineMethod (c$, "getAvailIn", \r
93 function () {\r
94 return this.avail_in;\r
95 });\r
96 Clazz.defineMethod (c$, "getTotalOut", \r
97 function () {\r
98 return this.total_out;\r
99 });\r
100 Clazz.defineMethod (c$, "getTotalIn", \r
101 function () {\r
102 return this.total_in;\r
103 });\r
104 c$.getBytes = Clazz.defineMethod (c$, "getBytes", \r
105 function (s) {\r
106 {\r
107 var x = [];\r
108 for (var i = 0; i < s.length;i++) {\r
109 var pt = s.charCodeAt(i);\r
110 if (pt <= 0x7F) {\r
111 x.push(pt);\r
112 } else if (pt <= 0x7FF) {\r
113 x.push(0xC0|((pt>>6)&0x1F));\r
114 x.push(0x80|(pt&0x3F));\r
115 } else if (pt <= 0xFFFF) {\r
116 x.push(0xE0|((pt>>12)&0xF));\r
117 x.push(0x80|((pt>>6)&0x3F));\r
118 x.push(0x80|(pt&0x3F));\r
119 } else {\r
120 x.push(0x3F); // '?'\r
121 }\r
122 }\r
123 return (Int32Array != Array ? new Int32Array(x) : x);\r
124 }}, "~S");\r
125 Clazz.defineStatics (c$,\r
126 "Z_STREAM_ERROR", -2);\r
127 });\r