more zipfs patches

Joel Uckelman uckelman at nomic.net
Sun Dec 6 11:42:58 PST 2009


Two more zipfs patches:

* Added ZipFileAttributeView.getAttribute().
* Renamed ZipFileAttributes.getExternalAttrs() to externalAttrs() for
  consistency.
* Bug: Must clear milliseconds before using Calendar for converting DOS time.
* Bug: isSameFile() now handles nonexistent files properly

-------------- next part --------------
# HG changeset patch
# User Joel Uckelman <uckelman at nomic.net>
# Date 1260105113 -3600
# Node ID b713729d52c0afb8181ee21206bcc6298996438a
# Parent  4cf3aee1209b5c2ef886ee7f66a96ccb352af98f
* Added ZipFileAttributeView.getAttribute().
* Renamed ZipFileAttributes.getExternalAttrs() to externalAttrs() for
  consistency.
* Must clear milliseconds before using Calendar for converting DOS time.

diff --git a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileAttributeView.java b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileAttributeView.java
--- a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileAttributeView.java
+++ b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileAttributeView.java
@@ -50,4 +50,47 @@
             throws IOException {
         return new ZipFileAttributes(file);
     }
+
+    @Override
+    public Object getAttribute(String attribute) throws IOException {
+        final ZipFileAttributes zfa = readAttributes();
+
+        if (attribute.equals("comment")) {
+            return zfa.comment();
+        }
+
+        if (attribute.equals("compressedSize")) {
+            return zfa.compressedSize();
+        }
+
+        if (attribute.equals("crc")) {
+            return zfa.crc();
+        }
+
+        if (attribute.equals("extra")) {
+            return zfa.extra();
+        }
+
+        if (attribute.equals("method")) {
+            return zfa.method();
+        }
+
+        if (attribute.equals("name")) {
+            return zfa.name();    
+        }
+  
+        if (attribute.equals("isArchiveFile")) {
+            return zfa.isArchiveFile();
+        }
+
+        if (attribute.equals("versionMadeBy")) {
+            return zfa.versionMadeBy();
+        }
+
+        if (attribute.equals("extAttrs")) {
+            return zfa.externalAttrs();
+        }
+
+        return null;
+    }
 }
diff --git a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileAttributes.java b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileAttributes.java
--- a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileAttributes.java
+++ b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileAttributes.java
@@ -37,9 +37,25 @@
 public class ZipFileAttributes extends ZipFileBasicAttributes {
 
     /** Creates a new instance of ZipFileAttributes */
-    private String[] version = {"FAT file system (DOS, OS/2, NT)", "Amiga", "VMS (VAX or Alpha AXP)", "Unix", "VM/CMS", "Atari", "HPFS file system (OS/2, NT 3.x)",
-        "Macintosh", "Z-System", "CP/M", "TOPS-20", "NTFS file system (NT)", "SMS/QDOS", "Acorn RISC OS", "VFAT file system (Win95, NT)",
-        "MVS", "BeOS (BeBox or PowerMac)", "Tandem"
+    private String[] version = {
+        "FAT file system (DOS, OS/2, NT)",
+        "Amiga",
+        "VMS (VAX or Alpha AXP)",
+        "UNIX",
+        "VM/CMS",
+        "Atari",
+        "HPFS file system (OS/2, NT 3.x)",
+        "Macintosh",
+        "Z-System",
+        "CP/M",
+        "TOPS-20",
+        "NTFS file system (NT)",
+        "SMS/QDOS",
+        "Acorn RISC OS",
+        "VFAT file system (Win95, NT)",
+        "MVS",
+        "BeOS (BeBox or PowerMac)",
+        "Tandem"
     };
 
     public ZipFileAttributes(FileRef file)
@@ -85,7 +101,7 @@
         }
     }
 
-    public int getExternalAttrs() {
+    public int externalAttrs() {
         return ze.extAttrs;
     }
 }
diff --git a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileBasicAttributes.java b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileBasicAttributes.java
--- a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileBasicAttributes.java
+++ b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFileBasicAttributes.java
@@ -78,13 +78,13 @@
 
     @Override
     public FileTime lastModifiedTime() {
-        long time = ze.lastModifiedTime;
-        Calendar cal = dosTimeToJavaTime(time);
+        final Calendar cal = dosTimeToJavaTime(ze.lastModifiedTime);
         return FileTime.fromMillis(cal.getTimeInMillis());
     }
 
     private Calendar dosTimeToJavaTime(long time) {
-        Calendar cal = Calendar.getInstance();
+        final Calendar cal = Calendar.getInstance();
+        cal.clear();  // to set the milliseconds 0
         cal.set((int) (((time >> 25) & 0x7f) + 1980),
                 (int) (((time >> 21) & 0x0f) - 1),
                 (int) ((time >> 16) & 0x1f),
-------------- next part --------------
# HG changeset patch
# User Joel Uckelman <uckelman at nomic.net>
# Date 1260114056 -3600
# Node ID 36841187ed0717208ca2862bd60d4519d18a9b17
# Parent  b713729d52c0afb8181ee21206bcc6298996438a
isSameFile() now handles nonexistent files properly

diff --git a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java
--- a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java
+++ b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java
@@ -966,28 +966,28 @@
 
     @Override
     public boolean isSameFile(Path other) throws IOException {
+        if (this.equals(other)) {
+            return true;
+        }
 
-        if ((other != null) && (other instanceof ZipFilePath)) {
+        if (other == null || (!(other instanceof ZipFilePath))) {
+            return false;
+        }
+  
+        final ZipFilePath other1 = (ZipFilePath) other;
 
-            // check both file systems are same.
+        // check whether we have a common file system
+        if (!this.getFileSystem().getZipFileSystemFile().equals(
+                other1.getFileSystem().getZipFileSystemFile())) {
+            return false;
+        }
 
-            ZipFilePath other1 = (ZipFilePath) other;
-            String fileSystem1 = this.getFileSystem().getZipFileSystemFile();
-            String fileSystem2 = other1.getFileSystem().getZipFileSystemFile();
-            boolean isSameFileSystem = fileSystem1.equals(fileSystem2);
-            if (!isSameFileSystem) {
-                return false;
-            }
+        // check whether both (or neither) exist
+        if (this.exists() != other1.exists()) {
+            return false;
+        }
 
-            // if file systems are same then do they exist
-            // finally compare the paths
-            // compare the real paths
-            ZipFilePath thisZip = this.toRealPath(false);
-            ZipFilePath otherZip = other1.toRealPath(false);
-            return (thisZip.startsWith(otherZip) && thisZip.endsWith(otherZip));
-        }
-        return false;
-
+        return this.toAbsolutePath().equals(other1.toAbsolutePath());
     }
 
     public WatchKey register(


More information about the nio-dev mailing list