1 Clazz.declarePackage ("JU");
2 Clazz.load (["javajs.api.GenericBinaryDocument", "JU.BC"], "JU.BinaryDocument", ["java.io.DataInputStream", "java.lang.Double"], function () {
3 c$ = Clazz.decorateAsClass (function () {
6 this.isBigEndian = true;
11 Clazz.instantialize (this, arguments);
12 }, JU, "BinaryDocument", JU.BC, javajs.api.GenericBinaryDocument);
13 Clazz.prepareFields (c$, function () {
14 this.t8 = Clazz.newByteArray (8, 0);
16 Clazz.overrideMethod (c$, "close",
18 if (this.stream != null) try {
21 if (Clazz.exceptionOf (e, Exception)) {
26 if (this.out != null) this.out.closeChannel ();
28 Clazz.overrideMethod (c$, "setStream",
29 function (jzt, bis, isBigEndian) {
30 if (jzt != null) this.jzt = jzt;
31 if (bis != null) this.stream = new java.io.DataInputStream (bis);
32 this.isBigEndian = isBigEndian;
33 }, "javajs.api.GenericZipTools,java.io.BufferedInputStream,~B");
34 Clazz.overrideMethod (c$, "setStreamData",
35 function (stream, isBigEndian) {
36 if (stream != null) this.stream = stream;
37 this.isBigEndian = isBigEndian;
38 }, "java.io.DataInputStream,~B");
39 Clazz.defineMethod (c$, "setRandom",
43 Clazz.overrideMethod (c$, "readByte",
46 return this.ioReadByte ();
48 Clazz.defineMethod (c$, "ioReadByte",
50 var b = this.stream.readByte ();
51 if (this.out != null) this.out.writeByteAsInt (b);
54 Clazz.overrideMethod (c$, "readByteArray",
55 function (b, off, len) {
56 var n = this.ioRead (b, off, len);
60 Clazz.defineMethod (c$, "ioRead",
61 function (b, off, len) {
64 var n = this.stream.read (b, off, len);
66 if (n > 0 && this.out != null) this.writeBytes (b, off, n);
73 Clazz.defineMethod (c$, "writeBytes",
74 function (b, off, n) {
75 this.out.write (b, off, n);
77 Clazz.overrideMethod (c$, "readString",
79 var temp = Clazz.newByteArray (nChar, 0);
80 var n = this.readByteArray (temp, 0, nChar);
81 return String.instantialize (temp, 0, n, "UTF-8");
83 Clazz.overrideMethod (c$, "readShort",
86 var n = (this.isBigEndian ? this.ioReadShort () : ((this.ioReadByte () & 0xff) | (this.ioReadByte () & 0xff) << 8));
88 return (n > 0x7FFF ? n - 0x10000 : n);
90 Clazz.defineMethod (c$, "ioReadShort",
92 var b = this.stream.readShort ();
93 if (this.out != null) this.writeShort (b);
96 Clazz.defineMethod (c$, "writeShort",
98 this.out.writeByteAsInt (i >> 8);
99 this.out.writeByteAsInt (i);
101 Clazz.overrideMethod (c$, "readIntLE",
104 return this.readLEInt ();
106 Clazz.overrideMethod (c$, "readInt",
109 return (this.isBigEndian ? this.ioReadInt () : this.readLEInt ());
111 Clazz.defineMethod (c$, "ioReadInt",
113 var i = this.stream.readInt ();
114 if (this.out != null) this.writeInt (i);
117 Clazz.defineMethod (c$, "writeInt",
119 this.out.writeByteAsInt (i >> 24);
120 this.out.writeByteAsInt (i >> 16);
121 this.out.writeByteAsInt (i >> 8);
122 this.out.writeByteAsInt (i);
124 Clazz.overrideMethod (c$, "swapBytesI",
126 return (((n >> 24) & 0xff) | ((n >> 16) & 0xff) << 8 | ((n >> 8) & 0xff) << 16 | (n & 0xff) << 24);
128 Clazz.overrideMethod (c$, "swapBytesS",
130 return ((((n >> 8) & 0xff) | (n & 0xff) << 8));
132 Clazz.overrideMethod (c$, "readUnsignedShort",
135 var a = (this.ioReadByte () & 0xff);
136 var b = (this.ioReadByte () & 0xff);
137 return (this.isBigEndian ? (a << 8) + b : (b << 8) + a);
139 Clazz.overrideMethod (c$, "readLong",
142 return (this.isBigEndian ? this.ioReadLong () : (((this.ioReadByte ()) & 0xff) | ((this.ioReadByte ()) & 0xff) << 8 | ((this.ioReadByte ()) & 0xff) << 16 | ((this.ioReadByte ()) & 0xff) << 24 | ((this.ioReadByte ()) & 0xff) << 32 | ((this.ioReadByte ()) & 0xff) << 40 | ((this.ioReadByte ()) & 0xff) << 48 | ((this.ioReadByte ()) & 0xff) << 54));
144 Clazz.defineMethod (c$, "ioReadLong",
146 var b = this.stream.readLong ();
147 if (this.out != null) this.writeLong (b);
150 Clazz.defineMethod (c$, "writeLong",
152 this.writeInt (((b >> 32) & 0xFFFFFFFF));
153 this.writeInt ((b & 0xFFFFFFFF));
155 Clazz.defineMethod (c$, "readLEInt",
157 this.ioRead (this.t8, 0, 4);
158 return JU.BC.bytesToInt (this.t8, 0, false);
160 Clazz.overrideMethod (c$, "readFloat",
162 return JU.BC.intToFloat (this.readInt ());
164 Clazz.overrideMethod (c$, "readDouble",
167 this.readByteArray(this.t8, 0, 8);
168 return this.bytesToDoubleToFloat(this.t8, 0, this.isBigEndian);
170 Clazz.defineMethod (c$, "ioReadDouble",
172 var d = this.stream.readDouble ();
173 if (this.out != null) this.writeLong (Double.doubleToRawLongBits (d));
176 Clazz.defineMethod (c$, "readLELong",
178 return (((this.ioReadByte ()) & 0xff) | ((this.ioReadByte ()) & 0xff) << 8 | ((this.ioReadByte ()) & 0xff) << 16 | ((this.ioReadByte ()) & 0xff) << 24 | ((this.ioReadByte ()) & 0xff) << 32 | ((this.ioReadByte ()) & 0xff) << 40 | ((this.ioReadByte ()) & 0xff) << 48 | ((this.ioReadByte ()) & 0xff) << 56);
180 Clazz.overrideMethod (c$, "seek",
183 if (offset == this.nBytes) return;
184 if (offset < this.nBytes) {
185 this.stream.reset ();
186 if (this.out != null && this.nBytes != 0) this.out.reset ();
189 offset -= this.nBytes;
190 }if (this.out == null) {
191 this.stream.skipBytes (offset);
193 this.readByteArray ( Clazz.newByteArray (offset, 0), 0, offset);
194 }this.nBytes += offset;
196 if (Clazz.exceptionOf (e, Exception)) {
197 System.out.println (e.toString ());
203 Clazz.overrideMethod (c$, "getPosition",
207 Clazz.overrideMethod (c$, "setOutputChannel",
211 Clazz.overrideMethod (c$, "getAllDataFiles",
212 function (binaryFileList, firstFile) {
215 Clazz.overrideMethod (c$, "getAllDataMapped",
216 function (replace, string, fileData) {
217 }, "~S,~S,java.util.Map");