zipfs patches

Joel Uckelman uckelman at nomic.net
Fri Jan 29 11:37:39 PST 2010


Two more zipfs patches:

* Implemented readAttributes().
* copyTo() should return target, not this.

-------------- next part --------------
# HG changeset patch
# User Joel Uckelman <uckelman at nomic.net>
# Date 1264792812 -3600
# Node ID c057cc149682d4ff84a9aed8e85c0fd8e74b0637
# Parent  36841187ed0717208ca2862bd60d4519d18a9b17
Implemented readAttributes().

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
@@ -944,10 +944,72 @@
     }
 
     @Override
-    public Map<String,?> readAttributes(String attribute, LinkOption... options)
-        throws IOException
-    {
-        throw new RuntimeException("not implemented");
+    public Map<String,?> readAttributes(String attributes,
+                                        LinkOption... options)
+                                                           throws IOException {
+        return readAttributes(attributes.split(","), options);
+    }
+
+    protected Map<String,?> readAttributes(String[] attributes,
+                                           LinkOption... options)
+                                                           throws IOException {
+        final Map<String,Object> map = new HashMap<String,Object>();
+
+        for (String attr : attributes) {
+            final int colon = attr.indexOf(':');
+
+            final String view;
+            final String name;
+
+            if (colon == -1) {
+                view = "basic";
+                name = attr;
+            }
+            else {
+                view = attr.substring(0, colon);
+                name = attr.substring(colon+1, attr.length());
+            }
+
+            if ("*".equals(name)) {
+                if ("basic".equals(view)) {
+                    map.putAll(readAttributes(new String[] {
+                        "basic:lastModifiedTime",
+                        "basic:lastAccessTime",
+                        "basic:creationTime",
+                        "basic:size",
+                        "basic:isRegularFile",
+                        "basic:isDirectory",
+                        "basic:isSymbolicLink",
+                        "basic:isOther",
+                        "basic:fileKey"
+                    }));
+                }
+                else if ("zip".equals(view)) {
+                    map.putAll(readAttributes(new String[] {
+                        "zip:comment",
+                        "zip:compressedSize",
+                        "zip:crc",
+                        "zip:extra",
+                        "zip:method",
+                        "zip:name",
+                        "zip:isArchiveFile",
+                        "zip:versionMadeBy",
+                        "zip:extAttrs"
+                    }));
+                }
+                else if ("jar".equals(view)) {
+                    map.putAll(readAttributes(new String[] {
+                        "jar:manifestAttributes",
+                        "jar:entryAttributes"
+                      }));
+                }
+            }
+            else {
+                map.put(attr, getAttribute(attr));
+            }
+        }
+    
+        return map;
     }
 
     @Override
-------------- next part --------------
# HG changeset patch
# User Joel Uckelman <uckelman at nomic.net>
# Date 1264793497 -3600
# Node ID 8709878d43e6b051d6b7280c2cd51ead5de63eaa
# Parent  c057cc149682d4ff84a9aed8e85c0fd8e74b0637
copyTo() should return target, not this.

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
@@ -1343,7 +1343,7 @@
             }
         }
 
-        return this;
+        return target;
     }
 
     private void copyToTarget(Path target) throws IOException {


More information about the nio-dev mailing list