JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / javajs / util / ZipData.js
1 Clazz.declarePackage ("javajs.util");
2 Clazz.load (null, "javajs.util.ZipData", ["javajs.util.Rdr", "$.ZipTools"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.isEnabled = true;
5 this.buf = null;
6 this.pt = 0;
7 this.nBytes = 0;
8 Clazz.instantialize (this, arguments);
9 }, javajs.util, "ZipData");
10 Clazz.makeConstructor (c$, 
11 function (nBytes) {
12 this.nBytes = nBytes;
13 }, "~N");
14 Clazz.defineMethod (c$, "addBytes", 
15 function (byteBuf, nSectorBytes, nBytesRemaining) {
16 if (this.pt == 0) {
17 if (!javajs.util.Rdr.isGzipB (byteBuf)) {
18 this.isEnabled = false;
19 return -1;
20 }this.buf =  Clazz.newByteArray (nBytesRemaining, 0);
21 }var nToAdd = Math.min (nSectorBytes, nBytesRemaining);
22 System.arraycopy (byteBuf, 0, this.buf, this.pt, nToAdd);
23 this.pt += nToAdd;
24 return nBytesRemaining - nToAdd;
25 }, "~A,~N,~N");
26 Clazz.defineMethod (c$, "addTo", 
27 function (jzt, data) {
28 data.append (javajs.util.ZipData.getGzippedBytesAsString (jzt, this.buf));
29 }, "javajs.api.GenericZipTools,javajs.util.SB");
30 c$.getGzippedBytesAsString = Clazz.defineMethod (c$, "getGzippedBytesAsString", 
31 function (jzt, bytes) {
32 try {
33 var bis = jzt.getUnGzippedInputStream (bytes);
34 var s = javajs.util.ZipTools.getStreamAsString (bis);
35 bis.close ();
36 return s;
37 } catch (e) {
38 if (Clazz.exceptionOf (e, Exception)) {
39 return "";
40 } else {
41 throw e;
42 }
43 }
44 }, "javajs.api.GenericZipTools,~A");
45 });