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