JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / JU / GZIPHeader.js
1 Clazz.declarePackage ("JU");\r
2 Clazz.load (null, "JU.GZIPHeader", ["JU.ZStream", "java.lang.IllegalArgumentException", "$.InternalError"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.text = false;\r
5 this.fhcrc = false;\r
6 this.time = 0;\r
7 this.xflags = 0;\r
8 this.os = 255;\r
9 this.extra = null;\r
10 this.name = null;\r
11 this.comment = null;\r
12 this.hcrc = 0;\r
13 this.crc = 0;\r
14 this.done = false;\r
15 this.mtime = 0;\r
16 Clazz.instantialize (this, arguments);\r
17 }, JU, "GZIPHeader", null, Cloneable);\r
18 Clazz.defineMethod (c$, "setModifiedTime", \r
19 function (mtime) {\r
20 this.mtime = mtime;\r
21 }, "~N");\r
22 Clazz.defineMethod (c$, "getModifiedTime", \r
23 function () {\r
24 return this.mtime;\r
25 });\r
26 Clazz.defineMethod (c$, "setOS", \r
27 function (os) {\r
28 if ((0 <= os && os <= 13) || os == 255) this.os = os;\r
29  else throw  new IllegalArgumentException ("os: " + os);\r
30 }, "~N");\r
31 Clazz.defineMethod (c$, "getOS", \r
32 function () {\r
33 return this.os;\r
34 });\r
35 Clazz.defineMethod (c$, "setName", \r
36 function (name) {\r
37 this.name = JU.ZStream.getBytes (name);\r
38 }, "~S");\r
39 Clazz.defineMethod (c$, "getName", \r
40 function () {\r
41 if (this.name == null) return "";\r
42 try {\r
43 return  String.instantialize (this.name, "ISO-8859-1");\r
44 } catch (e) {\r
45 if (Clazz.exceptionOf (e, java.io.UnsupportedEncodingException)) {\r
46 throw  new InternalError (e.toString ());\r
47 } else {\r
48 throw e;\r
49 }\r
50 }\r
51 });\r
52 Clazz.defineMethod (c$, "setComment", \r
53 function (comment) {\r
54 this.comment = JU.ZStream.getBytes (comment);\r
55 }, "~S");\r
56 Clazz.defineMethod (c$, "getComment", \r
57 function () {\r
58 if (this.comment == null) return "";\r
59 try {\r
60 return  String.instantialize (this.comment, "ISO-8859-1");\r
61 } catch (e) {\r
62 if (Clazz.exceptionOf (e, java.io.UnsupportedEncodingException)) {\r
63 throw  new InternalError (e.toString ());\r
64 } else {\r
65 throw e;\r
66 }\r
67 }\r
68 });\r
69 Clazz.defineMethod (c$, "setCRC", \r
70 function (crc) {\r
71 this.crc = crc;\r
72 }, "~N");\r
73 Clazz.defineMethod (c$, "getCRC", \r
74 function () {\r
75 return this.crc;\r
76 });\r
77 Clazz.defineMethod (c$, "put", \r
78 function (d) {\r
79 var flag = 0;\r
80 if (this.text) {\r
81 flag |= 1;\r
82 }if (this.fhcrc) {\r
83 flag |= 2;\r
84 }if (this.extra != null) {\r
85 flag |= 4;\r
86 }if (this.name != null) {\r
87 flag |= 8;\r
88 }if (this.comment != null) {\r
89 flag |= 16;\r
90 }var xfl = 0;\r
91 if (d.level == 1) {\r
92 xfl |= 4;\r
93 } else if (d.level == 9) {\r
94 xfl |= 2;\r
95 }d.put_short (0x8b1f);\r
96 d.put_byteB (8);\r
97 d.put_byteB (flag);\r
98 d.put_byteB (this.mtime);\r
99 d.put_byteB ((this.mtime >> 8));\r
100 d.put_byteB ((this.mtime >> 16));\r
101 d.put_byteB ((this.mtime >> 24));\r
102 d.put_byteB (xfl);\r
103 d.put_byteB (this.os);\r
104 if (this.extra != null) {\r
105 d.put_byteB (this.extra.length);\r
106 d.put_byteB ((this.extra.length >> 8));\r
107 d.put_byte (this.extra, 0, this.extra.length);\r
108 }if (this.name != null) {\r
109 d.put_byte (this.name, 0, this.name.length);\r
110 d.put_byteB (0);\r
111 }if (this.comment != null) {\r
112 d.put_byte (this.comment, 0, this.comment.length);\r
113 d.put_byteB (0);\r
114 }}, "JU.Deflate");\r
115 Clazz.defineMethod (c$, "clone", \r
116 function () {\r
117 var gheader = Clazz.superCall (this, JU.GZIPHeader, "clone", []);\r
118 var tmp;\r
119 if (gheader.extra != null) {\r
120 tmp =  Clazz.newByteArray (gheader.extra.length, 0);\r
121 System.arraycopy (gheader.extra, 0, tmp, 0, tmp.length);\r
122 gheader.extra = tmp;\r
123 }if (gheader.name != null) {\r
124 tmp =  Clazz.newByteArray (gheader.name.length, 0);\r
125 System.arraycopy (gheader.name, 0, tmp, 0, tmp.length);\r
126 gheader.name = tmp;\r
127 }if (gheader.comment != null) {\r
128 tmp =  Clazz.newByteArray (gheader.comment.length, 0);\r
129 System.arraycopy (gheader.comment, 0, tmp, 0, tmp.length);\r
130 gheader.comment = tmp;\r
131 }return gheader;\r
132 });\r
133 Clazz.defineStatics (c$,\r
134 "OS_MSDOS", 0x00,\r
135 "OS_AMIGA", 0x01,\r
136 "OS_VMS", 0x02,\r
137 "OS_UNIX", 0x03,\r
138 "OS_ATARI", 0x05,\r
139 "OS_OS2", 0x06,\r
140 "OS_MACOS", 0x07,\r
141 "OS_TOPS20", 0x0a,\r
142 "OS_WIN32", 0x0b,\r
143 "OS_VMCMS", 0x04,\r
144 "OS_ZSYSTEM", 0x08,\r
145 "OS_CPM", 0x09,\r
146 "OS_QDOS", 0x0c,\r
147 "OS_RISCOS", 0x0d,\r
148 "OS_UNKNOWN", 0xff);\r
149 });\r