1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/zip/ZipFileIndexEntry.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,91 @@ 1.4 +package com.sun.tools.javac.zip; 1.5 + 1.6 +import java.io.File; 1.7 + 1.8 +public final class ZipFileIndexEntry implements Comparable<ZipFileIndexEntry> { 1.9 + public static final ZipFileIndexEntry[] EMPTY_ARRAY = {}; 1.10 + 1.11 + // Directory related 1.12 + String dir; 1.13 + boolean isDir; 1.14 + 1.15 + // File related 1.16 + String name; 1.17 + 1.18 + int offset; 1.19 + int size; 1.20 + int compressedSize; 1.21 + long javatime; 1.22 + 1.23 + private int nativetime; 1.24 + 1.25 + public ZipFileIndexEntry(String path) { 1.26 + int separator = path.lastIndexOf(File.separatorChar); 1.27 + if (separator == -1) { 1.28 + dir = "".intern(); 1.29 + name = path; 1.30 + } else { 1.31 + dir = path.substring(0, separator).intern(); 1.32 + name = path.substring(separator + 1); 1.33 + } 1.34 + } 1.35 + 1.36 + public ZipFileIndexEntry(String directory, String name) { 1.37 + this.dir = directory.intern(); 1.38 + this.name = name; 1.39 + } 1.40 + 1.41 + public String getName() { 1.42 + if (dir == null || dir.length() == 0) { 1.43 + return name; 1.44 + } 1.45 + 1.46 + StringBuilder sb = new StringBuilder(); 1.47 + sb.append(dir); 1.48 + sb.append(File.separatorChar); 1.49 + sb.append(name); 1.50 + return sb.toString(); 1.51 + } 1.52 + 1.53 + public String getFileName() { 1.54 + return name; 1.55 + } 1.56 + 1.57 + public long getLastModified() { 1.58 + if (javatime == 0) { 1.59 + javatime = dosToJavaTime(nativetime); 1.60 + } 1.61 + return javatime; 1.62 + } 1.63 + 1.64 + // From java.util.zip 1.65 + private static long dosToJavaTime(int nativetime) { 1.66 + // Bootstrap build problems prevent me from using the code directly 1.67 + // Convert the raw/native time to a long for now 1.68 + return (long)nativetime; 1.69 + } 1.70 + 1.71 + void setNativeTime(int natTime) { 1.72 + nativetime = natTime; 1.73 + } 1.74 + 1.75 + public boolean isDirectory() { 1.76 + return isDir; 1.77 + } 1.78 + 1.79 + public int compareTo(ZipFileIndexEntry other) { 1.80 + String otherD = other.dir; 1.81 + if (dir != otherD) { 1.82 + int c = dir.compareTo(otherD); 1.83 + if (c != 0) 1.84 + return c; 1.85 + } 1.86 + return name.compareTo(other.name); 1.87 + } 1.88 + 1.89 + 1.90 + public String toString() { 1.91 + return isDir ? ("Dir:" + dir + " : " + name) : 1.92 + (dir + ":" + name); 1.93 + } 1.94 +}