diff -r d0f966792a5d -r 5749df30059b jdk/src/share/demo/nio/zipfs/Demo.java --- a/jdk/src/share/demo/nio/zipfs/Demo.java Mon Nov 15 15:11:04 2010 +0000 +++ b/jdk/src/share/demo/nio/zipfs/Demo.java Mon Nov 15 09:26:49 2010 -0800 @@ -75,9 +75,15 @@ // copy an external src file into zipfile // as entry dst + copyin_attrs, // + // copy an external src file into zipfile + // as entry dst, with attributes (timestamp) + copyout, // // copy zipfile entry src" out to file dst + copyout_attrs, // + zzmove, // // move entry path/dir from zfsrc to zfdst @@ -94,6 +100,9 @@ setmtime, // // set the lastModifiedTime of entry path + setatime, // + setctime, // + lsdir, // // list dir's direct child files/dirs @@ -135,12 +144,14 @@ attrs2, // // test different ways to print attrs + + prof, } public static void main(String[] args) throws Throwable { - Action action = Action.valueOf(args[0]);; - Map env = env = new HashMap(); + Action action = Action.valueOf(args[0]); + Map env = env = new HashMap<>(); if (action == Action.create) env.put("createNew", true); if (action == Action.tlist || action == Action.twalk) @@ -185,6 +196,16 @@ dst = fs.getPath(args[3]); src.copyTo(dst); break; + case copyin_attrs: + src = Paths.get(args[2]); + dst = fs.getPath(args[3]); + src.copyTo(dst, COPY_ATTRIBUTES); + break; + case copyout_attrs: + src = fs.getPath(args[2]); + dst = Paths.get(args[3]); + src.copyTo(dst, COPY_ATTRIBUTES); + break; case zzmove: fs2 = FileSystems.newFileSystem( URI.create("zip" + Paths.get(args[2]).toUri().toString().substring(4)), @@ -206,6 +227,7 @@ case attrs: for (int i = 2; i < args.length; i++) { path = fs.getPath(args[i]); + System.out.println(path); System.out.println( Attributes.readBasicFileAttributes(path).toString()); } @@ -221,6 +243,28 @@ Attributes.readBasicFileAttributes(path).toString()); } break; + case setctime: + df = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss"); + newDatetime = df.parse(args[2]); + for (int i = 3; i < args.length; i++) { + path = fs.getPath(args[i]); + path.setAttribute("creationTime", + FileTime.fromMillis(newDatetime.getTime())); + System.out.println( + Attributes.readBasicFileAttributes(path).toString()); + } + break; + case setatime: + df = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss"); + newDatetime = df.parse(args[2]); + for (int i = 3; i < args.length; i++) { + path = fs.getPath(args[i]); + path.setAttribute("lastAccessTime", + FileTime.fromMillis(newDatetime.getTime())); + System.out.println( + Attributes.readBasicFileAttributes(path).toString()); + } + break; case attrsspace: path = fs.getPath("/"); FileStore fstore = path.getFileStore(); @@ -293,6 +337,7 @@ case attrs2: for (int i = 2; i < args.length; i++) { path = fs.getPath(args[i]); + System.out.printf("%n%s%n", path); System.out.println("-------(1)---------"); System.out.println( Attributes.readBasicFileAttributes(path).toString()); @@ -308,6 +353,13 @@ } } break; + case prof: + list(fs.getPath("/"), false); + while (true) { + Thread.sleep(10000); + //list(fs.getPath("/"), true); + System.out.println("sleeping..."); + } } } catch (Exception x) { x.printStackTrace(); @@ -501,10 +553,11 @@ } private static void list(Path path, boolean verbose ) throws IOException { - if (verbose) - System.out.println(Attributes.readBasicFileAttributes(path).toString()); - else - System.out.printf(" %s%n", path.toString()); + if (!"/".equals(path.toString())) { + System.out.printf(" %s%n", path.toString()); + if (verbose) + System.out.println(Attributes.readBasicFileAttributes(path).toString()); + } if (path.notExists()) return; if (Attributes.readBasicFileAttributes(path).isDirectory()) {