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

Thu, 22 May 2008 15:51:41 -0700

author
jjg
date
Thu, 22 May 2008 15:51:41 -0700
changeset 36
58e352559a41
parent 1
9a66ca7c79fa
permissions
-rw-r--r--

6705945: com.sun.tools.javac.zip files do not have valid copyright
Reviewed-by: mcimadamore

     1 /*
     2  * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    26 package com.sun.tools.javac.zip;
    28 import java.io.File;
    30 public final class ZipFileIndexEntry implements Comparable<ZipFileIndexEntry> {
    31     public static final ZipFileIndexEntry[] EMPTY_ARRAY = {};
    33     // Directory related
    34     String dir;
    35     boolean isDir;
    37     // File related
    38     String name;
    40     int offset;
    41     int size;
    42     int compressedSize;
    43     long javatime;
    45     private int nativetime;
    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     }
    58     public ZipFileIndexEntry(String directory, String name) {
    59         this.dir = directory.intern();
    60         this.name = name;
    61     }
    63     public String getName() {
    64         if (dir == null || dir.length() == 0) {
    65             return name;
    66         }
    68         StringBuilder sb = new StringBuilder();
    69         sb.append(dir);
    70         sb.append(File.separatorChar);
    71         sb.append(name);
    72         return sb.toString();
    73     }
    75     public String getFileName() {
    76         return name;
    77     }
    79     public long getLastModified() {
    80         if (javatime == 0) {
    81                 javatime = dosToJavaTime(nativetime);
    82         }
    83         return javatime;
    84     }
    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     }
    93     void setNativeTime(int natTime) {
    94         nativetime = natTime;
    95     }
    97     public boolean isDirectory() {
    98         return isDir;
    99     }
   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     }
   112     public String toString() {
   113         return isDir ? ("Dir:" + dir + " : " + name) :
   114             (dir + ":" + name);
   115     }
   116 }

mercurial