File size: 3,749 Bytes
233f6d4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | Clazz.declarePackage ("JSV.common");
Clazz.load (["java.io.BufferedReader", "JSV.api.JSVZipReader"], "JSV.common.JSVZipFileSequentialReader", ["java.io.StringReader", "java.util.zip.ZipInputStream", "JU.SB", "JU.Logger"], function () {
c$ = Clazz.decorateAsClass (function () {
this.subFileList = null;
this.zis = null;
this.ze = null;
this.ptMark = 0;
this.data = null;
this.startCode = null;
this.lineCount = 0;
this.buf = null;
this.len = 0;
this.pt = 0;
this.cr = '\0';
Clazz.instantialize (this, arguments);
}, JSV.common, "JSVZipFileSequentialReader", java.io.BufferedReader, JSV.api.JSVZipReader);
Clazz.prepareFields (c$, function () {
this.buf = Clazz.newByteArray (1024, 0);
});
Clazz.makeConstructor (c$,
function () {
Clazz.superConstructor (this, JSV.common.JSVZipFileSequentialReader, [ new java.io.StringReader ("")]);
});
Clazz.overrideMethod (c$, "set",
function (bis, subFileList, startCode) {
this.subFileList = subFileList;
this.zis = new java.util.zip.ZipInputStream (bis);
this.startCode = startCode;
this.nextEntry ();
return this;
}, "java.io.InputStream,~A,~S");
Clazz.overrideMethod (c$, "close",
function () {
try {
this.close ();
this.zis.close ();
} catch (e) {
if (Clazz.exceptionOf (e, java.io.IOException)) {
} else {
throw e;
}
}
});
Clazz.overrideMethod (c$, "mark",
function (limit) {
this.ptMark = this.pt;
if (this.len == 0) {
this.readLine ();
this.pt = this.ptMark;
}}, "~N");
Clazz.overrideMethod (c$, "reset",
function () {
this.pt = this.ptMark;
});
Clazz.overrideMethod (c$, "read",
function (chars, chPt, chLen) {
var l = Math.min (this.len - this.pt, chLen);
this.data.getChars (0, l, chars, chPt);
return l;
}, "~A,~N,~N");
Clazz.overrideMethod (c$, "readLine",
function () {
while (this.ze != null) {
try {
var line = this.getEntryLine ();
if (line != null) return line;
} catch (e) {
if (Clazz.exceptionOf (e, java.io.IOException)) {
break;
} else {
throw e;
}
}
this.nextEntry ();
}
return null;
});
Clazz.defineMethod (c$, "nextEntry",
function () {
this.len = this.pt = 0;
this.cr = '\0';
this.lineCount = 0;
try {
while ((this.ze = this.zis.getNextEntry ()) != null) if (this.isEntryOK (this.ze.getName ())) return;
} catch (e) {
if (Clazz.exceptionOf (e, Exception)) {
this.ze = null;
} else {
throw e;
}
}
});
Clazz.defineMethod (c$, "isEntryOK",
function (name) {
if (this.subFileList == null || this.subFileList.length == 1) return true;
for (var i = this.subFileList.length; --i >= 0; ) if (this.subFileList[i].equals (name)) {
JU.Logger.info ("...reading zip entry " + name);
return true;
}
JU.Logger.info ("...skipping zip entry " + name);
return false;
}, "~S");
Clazz.defineMethod (c$, "getEntryLine",
function () {
var line = null;
while (this.len >= 0 && (this.pt < this.len || this.zis.available () == 1)) {
var pt0 = this.pt;
var ch = ' ';
while (this.pt < this.len && ch != this.cr) {
switch (ch = this.data.charAt (this.pt++)) {
case '\n':
if (this.cr == '\r') {
pt0 = this.pt;
continue;
}this.cr = '\n';
break;
case '\r':
if (this.cr == '\n') continue;
this.cr = '\r';
break;
}
}
if (line == null) line = new JU.SB ();
if (this.pt != pt0) line.append (this.data.substring (pt0, this.pt + (ch == this.cr ? -1 : 0)));
if (ch == this.cr || this.zis.available () != 1 || (this.len = this.zis.read (this.buf, 0, 1024)) < 0) {
if (this.lineCount++ == 0 && this.startCode != null && line.indexOf (this.startCode) < 0) return null;
return line.toString ();
}this.pt = 0;
this.data = String.instantialize (this.buf, 0, this.len);
if (this.data.indexOf ('\0') >= 0) return null;
}
return (line == null ? null : line.toString ());
});
});
|