JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / javajs / util / BinaryDocument.js
1 Clazz.declarePackage ("javajs.util");
2 Clazz.load (["javajs.api.GenericBinaryDocument", "javajs.util.BC"], "javajs.util.BinaryDocument", ["java.io.DataInputStream", "java.lang.Double"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.stream = null;
5 this.isRandom = false;
6 this.isBigEndian = true;
7 this.jzt = null;
8 this.t8 = null;
9 this.nBytes = 0;
10 this.out = null;
11 Clazz.instantialize (this, arguments);
12 }, javajs.util, "BinaryDocument", javajs.util.BC, javajs.api.GenericBinaryDocument);
13 Clazz.prepareFields (c$, function () {
14 this.t8 =  Clazz.newByteArray (8, 0);
15 });
16 Clazz.overrideMethod (c$, "close", 
17 function () {
18 if (this.stream != null) try {
19 this.stream.close ();
20 } catch (e) {
21 if (Clazz.exceptionOf (e, Exception)) {
22 } else {
23 throw e;
24 }
25 }
26 if (this.out != null) this.out.closeChannel ();
27 });
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", 
40 function (TF) {
41 this.isRandom = TF;
42 }, "~B");
43 Clazz.overrideMethod (c$, "readByte", 
44 function () {
45 this.nBytes++;
46 return this.ioReadByte ();
47 });
48 Clazz.defineMethod (c$, "ioReadByte", 
49 ($fz = function () {
50 var b = this.stream.readByte ();
51 if (this.out != null) this.out.writeByteAsInt (b);
52 return b;
53 }, $fz.isPrivate = true, $fz));
54 Clazz.overrideMethod (c$, "readByteArray", 
55 function (b, off, len) {
56 var n = this.ioRead (b, off, len);
57 this.nBytes += n;
58 return n;
59 }, "~A,~N,~N");
60 Clazz.defineMethod (c$, "ioRead", 
61 ($fz = function (b, off, len) {
62 var m = 0;
63 while (len > 0) {
64 var n = this.stream.read (b, off, len);
65 m += n;
66 if (n > 0 && this.out != null) this.writeBytes (b, off, n);
67 if (n >= len) break;
68 off += n;
69 len -= n;
70 }
71 return m;
72 }, $fz.isPrivate = true, $fz), "~A,~N,~N");
73 Clazz.defineMethod (c$, "writeBytes", 
74 function (b, off, n) {
75 this.out.write (b, off, n);
76 }, "~A,~N,~N");
77 Clazz.overrideMethod (c$, "readString", 
78 function (nChar) {
79 var temp =  Clazz.newByteArray (nChar, 0);
80 var n = this.readByteArray (temp, 0, nChar);
81 return  String.instantialize (temp, 0, n, "UTF-8");
82 }, "~N");
83 Clazz.overrideMethod (c$, "readShort", 
84 function () {
85 this.nBytes += 2;
86 var n = (this.isBigEndian ? this.ioReadShort () : ((this.ioReadByte () & 0xff) | (this.ioReadByte () & 0xff) << 8));
87 {
88 return (n > 0x7FFF ? n - 0x10000 : n);
89 }});
90 Clazz.defineMethod (c$, "ioReadShort", 
91 ($fz = function () {
92 var b = this.stream.readShort ();
93 if (this.out != null) this.writeShort (b);
94 return b;
95 }, $fz.isPrivate = true, $fz));
96 Clazz.defineMethod (c$, "writeShort", 
97 function (i) {
98 this.out.writeByteAsInt (i >> 8);
99 this.out.writeByteAsInt (i);
100 }, "~N");
101 Clazz.overrideMethod (c$, "readIntLE", 
102 function () {
103 this.nBytes += 4;
104 return this.readLEInt ();
105 });
106 Clazz.overrideMethod (c$, "readInt", 
107 function () {
108 this.nBytes += 4;
109 return (this.isBigEndian ? this.ioReadInt () : this.readLEInt ());
110 });
111 Clazz.defineMethod (c$, "ioReadInt", 
112 ($fz = function () {
113 var i = this.stream.readInt ();
114 if (this.out != null) this.writeInt (i);
115 return i;
116 }, $fz.isPrivate = true, $fz));
117 Clazz.defineMethod (c$, "writeInt", 
118 function (i) {
119 this.out.writeByteAsInt (i >> 24);
120 this.out.writeByteAsInt (i >> 16);
121 this.out.writeByteAsInt (i >> 8);
122 this.out.writeByteAsInt (i);
123 }, "~N");
124 Clazz.overrideMethod (c$, "swapBytesI", 
125 function (n) {
126 return (((n >> 24) & 0xff) | ((n >> 16) & 0xff) << 8 | ((n >> 8) & 0xff) << 16 | (n & 0xff) << 24);
127 }, "~N");
128 Clazz.overrideMethod (c$, "swapBytesS", 
129 function (n) {
130 return ((((n >> 8) & 0xff) | (n & 0xff) << 8));
131 }, "~N");
132 Clazz.overrideMethod (c$, "readUnsignedShort", 
133 function () {
134 this.nBytes += 2;
135 var a = (this.ioReadByte () & 0xff);
136 var b = (this.ioReadByte () & 0xff);
137 return (this.isBigEndian ? (a << 8) + b : (b << 8) + a);
138 });
139 Clazz.overrideMethod (c$, "readLong", 
140 function () {
141 this.nBytes += 8;
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));
143 });
144 Clazz.defineMethod (c$, "ioReadLong", 
145 ($fz = function () {
146 var b = this.stream.readLong ();
147 if (this.out != null) this.writeLong (b);
148 return b;
149 }, $fz.isPrivate = true, $fz));
150 Clazz.defineMethod (c$, "writeLong", 
151 function (b) {
152 this.writeInt (((b >> 32) & 0xFFFFFFFF));
153 this.writeInt ((b & 0xFFFFFFFF));
154 }, "~N");
155 Clazz.defineMethod (c$, "readLEInt", 
156 ($fz = function () {
157 this.ioRead (this.t8, 0, 4);
158 return javajs.util.BC.bytesToInt (this.t8, 0, false);
159 }, $fz.isPrivate = true, $fz));
160 Clazz.overrideMethod (c$, "readFloat", 
161 function () {
162 return javajs.util.BC.intToFloat (this.readInt ());
163 });
164 Clazz.overrideMethod (c$, "readDouble", 
165 function () {
166 {
167 this.readByteArray(this.t8, 0, 8);
168 return this.bytesToDoubleToFloat(this.t8, 0, this.isBigEndian);
169 }});
170 Clazz.defineMethod (c$, "ioReadDouble", 
171 ($fz = function () {
172 var d = this.stream.readDouble ();
173 if (this.out != null) this.writeLong (Double.doubleToRawLongBits (d));
174 return d;
175 }, $fz.isPrivate = true, $fz));
176 Clazz.defineMethod (c$, "readLELong", 
177 ($fz = function () {
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);
179 }, $fz.isPrivate = true, $fz));
180 Clazz.overrideMethod (c$, "seek", 
181 function (offset) {
182 try {
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 ();
187 this.nBytes = 0;
188 } else {
189 offset -= this.nBytes;
190 }if (this.out == null) {
191 this.stream.skipBytes (offset);
192 } else {
193 this.readByteArray ( Clazz.newByteArray (offset, 0), 0, offset);
194 }this.nBytes += offset;
195 } catch (e) {
196 if (Clazz.exceptionOf (e, Exception)) {
197 System.out.println (e.toString ());
198 } else {
199 throw e;
200 }
201 }
202 }, "~N");
203 Clazz.overrideMethod (c$, "getPosition", 
204 function () {
205 return this.nBytes;
206 });
207 Clazz.overrideMethod (c$, "setOutputChannel", 
208 function (out) {
209 this.out = out;
210 }, "javajs.util.OC");
211 Clazz.overrideMethod (c$, "getAllDataFiles", 
212 function (binaryFileList, firstFile) {
213 return null;
214 }, "~S,~S");
215 Clazz.overrideMethod (c$, "getAllDataMapped", 
216 function (replace, string, fileData) {
217 }, "~S,~S,java.util.Map");
218 });