author | jjg |
Mon, 16 Jun 2008 13:28:00 -0700 | |
changeset 731 | 1dd22bdb9ca5 |
parent 655 | langtools/src/share/classes/com/sun/tools/javac/zip/ZipFileIndexEntry.java@1ebc7ce89018 |
permissions | -rw-r--r-- |
655
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
1 |
/* |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
2 |
* Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
4 |
* |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
7 |
* published by the Free Software Foundation. Sun designates this |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
10 |
* |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
15 |
* accompanied this code). |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
16 |
* |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
20 |
* |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
23 |
* have any questions. |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
24 |
*/ |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
25 |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
10 | 27 |
|
28 |
import java.io.File; |
|
29 |
||
30 |
public final class ZipFileIndexEntry implements Comparable<ZipFileIndexEntry> { |
|
31 |
public static final ZipFileIndexEntry[] EMPTY_ARRAY = {}; |
|
32 |
||
33 |
// Directory related |
|
34 |
String dir; |
|
35 |
boolean isDir; |
|
36 |
||
37 |
// File related |
|
38 |
String name; |
|
39 |
||
40 |
int offset; |
|
41 |
int size; |
|
42 |
int compressedSize; |
|
43 |
long javatime; |
|
44 |
||
45 |
private int nativetime; |
|
46 |
||
47 |
public ZipFileIndexEntry(String path) { |
|
48 |
int separator = path.lastIndexOf(File.separatorChar); |
|
49 |
if (separator == -1) { |
|
50 |
dir = "".intern(); |
|
51 |
name = path; |
|
52 |
} else { |
|
53 |
dir = path.substring(0, separator).intern(); |
|
54 |
name = path.substring(separator + 1); |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
public ZipFileIndexEntry(String directory, String name) { |
|
59 |
this.dir = directory.intern(); |
|
60 |
this.name = name; |
|
61 |
} |
|
62 |
||
63 |
public String getName() { |
|
64 |
if (dir == null || dir.length() == 0) { |
|
65 |
return name; |
|
66 |
} |
|
67 |
||
68 |
StringBuilder sb = new StringBuilder(); |
|
69 |
sb.append(dir); |
|
70 |
sb.append(File.separatorChar); |
|
71 |
sb.append(name); |
|
72 |
return sb.toString(); |
|
73 |
} |
|
74 |
||
75 |
public String getFileName() { |
|
76 |
return name; |
|
77 |
} |
|
78 |
||
79 |
public long getLastModified() { |
|
80 |
if (javatime == 0) { |
|
81 |
javatime = dosToJavaTime(nativetime); |
|
82 |
} |
|
83 |
return javatime; |
|
84 |
} |
|
85 |
||
86 |
// From java.util.zip |
|
87 |
private static long dosToJavaTime(int nativetime) { |
|
88 |
// Bootstrap build problems prevent me from using the code directly |
|
89 |
// Convert the raw/native time to a long for now |
|
90 |
return (long)nativetime; |
|
91 |
} |
|
92 |
||
93 |
void setNativeTime(int natTime) { |
|
94 |
nativetime = natTime; |
|
95 |
} |
|
96 |
||
97 |
public boolean isDirectory() { |
|
98 |
return isDir; |
|
99 |
} |
|
100 |
||
101 |
public int compareTo(ZipFileIndexEntry other) { |
|
102 |
String otherD = other.dir; |
|
103 |
if (dir != otherD) { |
|
104 |
int c = dir.compareTo(otherD); |
|
105 |
if (c != 0) |
|
106 |
return c; |
|
107 |
} |
|
108 |
return name.compareTo(other.name); |
|
109 |
} |
|
110 |
||
111 |
||
112 |
public String toString() { |
|
113 |
return isDir ? ("Dir:" + dir + " : " + name) : |
|
114 |
(dir + ":" + name); |
|
115 |
} |
|
116 |
} |