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