Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / util / zip / ZipEntry.js
1 Clazz.declarePackage ("java.util.zip");
2 Clazz.load (["java.util.zip.ZipConstants"], "java.util.zip.ZipEntry", ["java.lang.IllegalArgumentException", "$.InternalError", "$.NullPointerException", "java.util.Date"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.offset = 0;
5 this.name = null;
6 this.time = -1;
7 this.crc = -1;
8 this.size = -1;
9 this.csize = -1;
10 this.method = -1;
11 this.flag = 0;
12 this.extra = null;
13 this.comment = null;
14 Clazz.instantialize (this, arguments);
15 }, java.util.zip, "ZipEntry", null, [java.util.zip.ZipConstants, Cloneable]);
16 Clazz.makeConstructor (c$, 
17 function (name) {
18 if (name == null) {
19 throw  new NullPointerException ();
20 }if (name.length > 0xFFFF) {
21 throw  new IllegalArgumentException ("entry name too long");
22 }this.name = name;
23 }, "~S");
24 Clazz.defineMethod (c$, "getName", 
25 function () {
26 return this.name;
27 });
28 Clazz.defineMethod (c$, "setTime", 
29 function (time) {
30 this.time = java.util.zip.ZipEntry.javaToDosTime (time);
31 }, "~N");
32 Clazz.defineMethod (c$, "getTime", 
33 function () {
34 return this.time != -1 ? java.util.zip.ZipEntry.dosToJavaTime (this.time) : -1;
35 });
36 Clazz.defineMethod (c$, "setSize", 
37 function (size) {
38 if (size < 0) {
39 throw  new IllegalArgumentException ("invalid entry size");
40 }this.size = size;
41 }, "~N");
42 Clazz.defineMethod (c$, "getSize", 
43 function () {
44 return this.size;
45 });
46 Clazz.defineMethod (c$, "getCompressedSize", 
47 function () {
48 return this.csize;
49 });
50 Clazz.defineMethod (c$, "setCompressedSize", 
51 function (csize) {
52 this.csize = csize;
53 }, "~N");
54 Clazz.defineMethod (c$, "setCrc", 
55 function (crc) {
56 if (crc < 0 || crc > 0xFFFFFFFF) {
57 throw  new IllegalArgumentException ("invalid entry crc-32");
58 }this.crc = crc;
59 }, "~N");
60 Clazz.defineMethod (c$, "getCrc", 
61 function () {
62 return this.crc;
63 });
64 Clazz.defineMethod (c$, "setMethod", 
65 function (method) {
66 if (method != 0 && method != 8) {
67 throw  new IllegalArgumentException ("invalid compression method");
68 }this.method = method;
69 }, "~N");
70 Clazz.defineMethod (c$, "getMethod", 
71 function () {
72 return this.method;
73 });
74 Clazz.defineMethod (c$, "setExtra", 
75 function (extra) {
76 if (extra != null && extra.length > 0xFFFF) {
77 throw  new IllegalArgumentException ("invalid extra field length");
78 }this.extra = extra;
79 }, "~A");
80 Clazz.defineMethod (c$, "getExtra", 
81 function () {
82 return this.extra;
83 });
84 Clazz.defineMethod (c$, "setComment", 
85 function (comment) {
86 this.comment = comment;
87 }, "~S");
88 Clazz.defineMethod (c$, "getComment", 
89 function () {
90 return this.comment;
91 });
92 Clazz.defineMethod (c$, "isDirectory", 
93 function () {
94 return this.name.endsWith ("/");
95 });
96 Clazz.overrideMethod (c$, "toString", 
97 function () {
98 return this.getName ();
99 });
100 c$.dosToJavaTime = Clazz.defineMethod (c$, "dosToJavaTime", 
101  function (dtime) {
102 var d =  new java.util.Date ((((dtime >> 25) & 0x7f) + 80), (((dtime >> 21) & 0x0f) - 1), ((dtime >> 16) & 0x1f), ((dtime >> 11) & 0x1f), ((dtime >> 5) & 0x3f), ((dtime << 1) & 0x3e));
103 return d.getTime ();
104 }, "~N");
105 c$.javaToDosTime = Clazz.defineMethod (c$, "javaToDosTime", 
106  function (time) {
107 var d =  new java.util.Date (time);
108 var year = d.getYear () + 1900;
109 if (year < 1980) {
110 return 2162688;
111 }return (year - 1980) << 25 | (d.getMonth () + 1) << 21 | d.getDate () << 16 | d.getHours () << 11 | d.getMinutes () << 5 | d.getSeconds () >> 1;
112 }, "~N");
113 Clazz.overrideMethod (c$, "hashCode", 
114 function () {
115 return this.name.hashCode ();
116 });
117 Clazz.defineMethod (c$, "clone", 
118 function () {
119 try {
120 var e = Clazz.superCall (this, java.util.zip.ZipEntry, "clone", []);
121 if (this.extra != null) {
122 e.extra =  Clazz.newByteArray (this.extra.length, 0);
123 System.arraycopy (this.extra, 0, e.extra, 0, this.extra.length);
124 }return e;
125 } catch (e) {
126 if (Clazz.exceptionOf (e, CloneNotSupportedException)) {
127 throw  new InternalError ();
128 } else {
129 throw e;
130 }
131 }
132 });
133 Clazz.defineStatics (c$,
134 "STORED", 0,
135 "DEFLATED", 8);
136 });