src/share/classes/com/sun/tools/javac/zip/ZipFileIndexEntry.java

Wed, 09 Apr 2008 13:41:45 +0100

author
mcimadamore
date
Wed, 09 Apr 2008 13:41:45 +0100
changeset 24
d032d5090fd5
parent 1
9a66ca7c79fa
child 36
58e352559a41
permissions
-rw-r--r--

5009937: hiding versus generics versus binary compatibility
Summary: missing implementation of JLS 8.4.8.3 (different arguments with same erasure not always triggering a compiler error)
Reviewed-by: jjg

     1 package com.sun.tools.javac.zip;
     3 import java.io.File;
     5 public final class ZipFileIndexEntry implements Comparable<ZipFileIndexEntry> {
     6     public static final ZipFileIndexEntry[] EMPTY_ARRAY = {};
     8     // Directory related
     9     String dir;
    10     boolean isDir;
    12     // File related
    13     String name;
    15     int offset;
    16     int size;
    17     int compressedSize;
    18     long javatime;
    20     private int nativetime;
    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     }
    33     public ZipFileIndexEntry(String directory, String name) {
    34         this.dir = directory.intern();
    35         this.name = name;
    36     }
    38     public String getName() {
    39         if (dir == null || dir.length() == 0) {
    40             return name;
    41         }
    43         StringBuilder sb = new StringBuilder();
    44         sb.append(dir);
    45         sb.append(File.separatorChar);
    46         sb.append(name);
    47         return sb.toString();
    48     }
    50     public String getFileName() {
    51         return name;
    52     }
    54     public long getLastModified() {
    55         if (javatime == 0) {
    56                 javatime = dosToJavaTime(nativetime);
    57         }
    58         return javatime;
    59     }
    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     }
    68     void setNativeTime(int natTime) {
    69         nativetime = natTime;
    70     }
    72     public boolean isDirectory() {
    73         return isDir;
    74     }
    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     }
    87     public String toString() {
    88         return isDir ? ("Dir:" + dir + " : " + name) :
    89             (dir + ":" + name);
    90     }
    91 }

mercurial