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

jjg@36 1 /*
jjg@36 2 * Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved.
jjg@36 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@36 4 *
jjg@36 5 * This code is free software; you can redistribute it and/or modify it
jjg@36 6 * under the terms of the GNU General Public License version 2 only, as
jjg@36 7 * published by the Free Software Foundation. Sun designates this
jjg@36 8 * particular file as subject to the "Classpath" exception as provided
jjg@36 9 * by Sun in the LICENSE file that accompanied this code.
jjg@36 10 *
jjg@36 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@36 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@36 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@36 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@36 15 * accompanied this code).
jjg@36 16 *
jjg@36 17 * You should have received a copy of the GNU General Public License version
jjg@36 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@36 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@36 20 *
jjg@36 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@36 22 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@36 23 * have any questions.
jjg@36 24 */
jjg@36 25
duke@1 26 package com.sun.tools.javac.zip;
duke@1 27
duke@1 28 import java.io.File;
duke@1 29
duke@1 30 public final class ZipFileIndexEntry implements Comparable<ZipFileIndexEntry> {
duke@1 31 public static final ZipFileIndexEntry[] EMPTY_ARRAY = {};
duke@1 32
duke@1 33 // Directory related
duke@1 34 String dir;
duke@1 35 boolean isDir;
duke@1 36
duke@1 37 // File related
duke@1 38 String name;
duke@1 39
duke@1 40 int offset;
duke@1 41 int size;
duke@1 42 int compressedSize;
duke@1 43 long javatime;
duke@1 44
duke@1 45 private int nativetime;
duke@1 46
duke@1 47 public ZipFileIndexEntry(String path) {
duke@1 48 int separator = path.lastIndexOf(File.separatorChar);
duke@1 49 if (separator == -1) {
duke@1 50 dir = "".intern();
duke@1 51 name = path;
duke@1 52 } else {
duke@1 53 dir = path.substring(0, separator).intern();
duke@1 54 name = path.substring(separator + 1);
duke@1 55 }
duke@1 56 }
duke@1 57
duke@1 58 public ZipFileIndexEntry(String directory, String name) {
duke@1 59 this.dir = directory.intern();
duke@1 60 this.name = name;
duke@1 61 }
duke@1 62
duke@1 63 public String getName() {
duke@1 64 if (dir == null || dir.length() == 0) {
duke@1 65 return name;
duke@1 66 }
duke@1 67
duke@1 68 StringBuilder sb = new StringBuilder();
duke@1 69 sb.append(dir);
duke@1 70 sb.append(File.separatorChar);
duke@1 71 sb.append(name);
duke@1 72 return sb.toString();
duke@1 73 }
duke@1 74
duke@1 75 public String getFileName() {
duke@1 76 return name;
duke@1 77 }
duke@1 78
duke@1 79 public long getLastModified() {
duke@1 80 if (javatime == 0) {
duke@1 81 javatime = dosToJavaTime(nativetime);
duke@1 82 }
duke@1 83 return javatime;
duke@1 84 }
duke@1 85
duke@1 86 // From java.util.zip
duke@1 87 private static long dosToJavaTime(int nativetime) {
duke@1 88 // Bootstrap build problems prevent me from using the code directly
duke@1 89 // Convert the raw/native time to a long for now
duke@1 90 return (long)nativetime;
duke@1 91 }
duke@1 92
duke@1 93 void setNativeTime(int natTime) {
duke@1 94 nativetime = natTime;
duke@1 95 }
duke@1 96
duke@1 97 public boolean isDirectory() {
duke@1 98 return isDir;
duke@1 99 }
duke@1 100
duke@1 101 public int compareTo(ZipFileIndexEntry other) {
duke@1 102 String otherD = other.dir;
duke@1 103 if (dir != otherD) {
duke@1 104 int c = dir.compareTo(otherD);
duke@1 105 if (c != 0)
duke@1 106 return c;
duke@1 107 }
duke@1 108 return name.compareTo(other.name);
duke@1 109 }
duke@1 110
duke@1 111
duke@1 112 public String toString() {
duke@1 113 return isDir ? ("Dir:" + dir + " : " + name) :
duke@1 114 (dir + ":" + name);
duke@1 115 }
duke@1 116 }

mercurial