01: package com.sun.tools.javac.zip;
02:
03: import java.io.File;
04:
05: public final class ZipFileIndexEntry implements
06: Comparable<ZipFileIndexEntry> {
07: public static final ZipFileIndexEntry[] EMPTY_ARRAY = {};
08:
09: // Directory related
10: String dir;
11: boolean isDir;
12:
13: // File related
14: String name;
15:
16: int offset;
17: int size;
18: int compressedSize;
19: long javatime;
20:
21: private int nativetime;
22:
23: public ZipFileIndexEntry(String path) {
24: int separator = path.lastIndexOf(File.separatorChar);
25: if (separator == -1) {
26: dir = "".intern();
27: name = path;
28: } else {
29: dir = path.substring(0, separator).intern();
30: name = path.substring(separator + 1);
31: }
32: }
33:
34: public ZipFileIndexEntry(String directory, String name) {
35: this .dir = directory.intern();
36: this .name = name;
37: }
38:
39: public String getName() {
40: if (dir == null || dir.length() == 0) {
41: return name;
42: }
43:
44: StringBuilder sb = new StringBuilder();
45: sb.append(dir);
46: sb.append(File.separatorChar);
47: sb.append(name);
48: return sb.toString();
49: }
50:
51: public String getFileName() {
52: return name;
53: }
54:
55: public long getLastModified() {
56: if (javatime == 0) {
57: javatime = dosToJavaTime(nativetime);
58: }
59: return javatime;
60: }
61:
62: // From java.util.zip
63: private static long dosToJavaTime(int nativetime) {
64: // Bootstrap build problems prevent me from using the code directly
65: // Convert the raw/native time to a long for now
66: return (long) nativetime;
67: }
68:
69: void setNativeTime(int natTime) {
70: nativetime = natTime;
71: }
72:
73: public boolean isDirectory() {
74: return isDir;
75: }
76:
77: public int compareTo(ZipFileIndexEntry other) {
78: String otherD = other.dir;
79: if (dir != otherD) {
80: int c = dir.compareTo(otherD);
81: if (c != 0)
82: return c;
83: }
84: return name.compareTo(other.name);
85: }
86:
87: public String toString() {
88: return isDir ? ("Dir:" + dir + " : " + name)
89: : (dir + ":" + name);
90: }
91: }
|