73 |
73 |
74 copyin, // <java Demo copyin zipfile src dst> |
74 copyin, // <java Demo copyin zipfile src dst> |
75 // copy an external src file into zipfile |
75 // copy an external src file into zipfile |
76 // as entry dst |
76 // as entry dst |
77 |
77 |
|
78 copyin_attrs, // <java Demo copyin_attrs zipfile src dst> |
|
79 // copy an external src file into zipfile |
|
80 // as entry dst, with attributes (timestamp) |
|
81 |
78 copyout, // <java Demo copyout zipfile src dst> |
82 copyout, // <java Demo copyout zipfile src dst> |
79 // copy zipfile entry src" out to file dst |
83 // copy zipfile entry src" out to file dst |
|
84 |
|
85 copyout_attrs, // <java Demo copyout_attrs zipfile src dst> |
80 |
86 |
81 zzmove, // <java Demo zzmove zfsrc zfdst path> |
87 zzmove, // <java Demo zzmove zfsrc zfdst path> |
82 // move entry path/dir from zfsrc to zfdst |
88 // move entry path/dir from zfsrc to zfdst |
83 |
89 |
84 zzcopy, // <java Demo zzcopy zfsrc zfdst path> |
90 zzcopy, // <java Demo zzcopy zfsrc zfdst path> |
92 // printout the storespace attrs of entry path |
98 // printout the storespace attrs of entry path |
93 |
99 |
94 setmtime, // <java Demo setmtime zipfile "MM/dd/yy-HH:mm:ss" path...> |
100 setmtime, // <java Demo setmtime zipfile "MM/dd/yy-HH:mm:ss" path...> |
95 // set the lastModifiedTime of entry path |
101 // set the lastModifiedTime of entry path |
96 |
102 |
|
103 setatime, // <java Demo setatime zipfile "MM/dd/yy-HH:mm:ss" path...> |
|
104 setctime, // <java Demo setctime zipfile "MM/dd/yy-HH:mm:ss" path...> |
|
105 |
97 lsdir, // <java Demo lsdir zipfile dir> |
106 lsdir, // <java Demo lsdir zipfile dir> |
98 // list dir's direct child files/dirs |
107 // list dir's direct child files/dirs |
99 |
108 |
100 mkdir, // <java Demo mkdir zipfile dir> |
109 mkdir, // <java Demo mkdir zipfile dir> |
101 |
110 |
133 // create a new zipfile if it doesn't exit |
142 // create a new zipfile if it doesn't exit |
134 // and then add the file(s) into it. |
143 // and then add the file(s) into it. |
135 |
144 |
136 attrs2, // <java Demo attrs2 zipfile file [...]> |
145 attrs2, // <java Demo attrs2 zipfile file [...]> |
137 // test different ways to print attrs |
146 // test different ways to print attrs |
|
147 |
|
148 prof, |
138 } |
149 } |
139 |
150 |
140 public static void main(String[] args) throws Throwable { |
151 public static void main(String[] args) throws Throwable { |
141 |
152 |
142 Action action = Action.valueOf(args[0]);; |
153 Action action = Action.valueOf(args[0]); |
143 Map<String, Object> env = env = new HashMap<String, Object>(); |
154 Map<String, Object> env = env = new HashMap<>(); |
144 if (action == Action.create) |
155 if (action == Action.create) |
145 env.put("createNew", true); |
156 env.put("createNew", true); |
146 if (action == Action.tlist || action == Action.twalk) |
157 if (action == Action.tlist || action == Action.twalk) |
147 env.put("buildDirTree", true); |
158 env.put("buildDirTree", true); |
148 |
159 |
183 case copyin: |
194 case copyin: |
184 src = Paths.get(args[2]); |
195 src = Paths.get(args[2]); |
185 dst = fs.getPath(args[3]); |
196 dst = fs.getPath(args[3]); |
186 src.copyTo(dst); |
197 src.copyTo(dst); |
187 break; |
198 break; |
|
199 case copyin_attrs: |
|
200 src = Paths.get(args[2]); |
|
201 dst = fs.getPath(args[3]); |
|
202 src.copyTo(dst, COPY_ATTRIBUTES); |
|
203 break; |
|
204 case copyout_attrs: |
|
205 src = fs.getPath(args[2]); |
|
206 dst = Paths.get(args[3]); |
|
207 src.copyTo(dst, COPY_ATTRIBUTES); |
|
208 break; |
188 case zzmove: |
209 case zzmove: |
189 fs2 = FileSystems.newFileSystem( |
210 fs2 = FileSystems.newFileSystem( |
190 URI.create("zip" + Paths.get(args[2]).toUri().toString().substring(4)), |
211 URI.create("zip" + Paths.get(args[2]).toUri().toString().substring(4)), |
191 env, |
212 env, |
192 null); |
213 null); |
204 fs2.close(); |
225 fs2.close(); |
205 break; |
226 break; |
206 case attrs: |
227 case attrs: |
207 for (int i = 2; i < args.length; i++) { |
228 for (int i = 2; i < args.length; i++) { |
208 path = fs.getPath(args[i]); |
229 path = fs.getPath(args[i]); |
|
230 System.out.println(path); |
209 System.out.println( |
231 System.out.println( |
210 Attributes.readBasicFileAttributes(path).toString()); |
232 Attributes.readBasicFileAttributes(path).toString()); |
211 } |
233 } |
212 break; |
234 break; |
213 case setmtime: |
235 case setmtime: |
214 DateFormat df = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss"); |
236 DateFormat df = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss"); |
215 Date newDatetime = df.parse(args[2]); |
237 Date newDatetime = df.parse(args[2]); |
216 for (int i = 3; i < args.length; i++) { |
238 for (int i = 3; i < args.length; i++) { |
217 path = fs.getPath(args[i]); |
239 path = fs.getPath(args[i]); |
218 path.setAttribute("lastModifiedTime", |
240 path.setAttribute("lastModifiedTime", |
|
241 FileTime.fromMillis(newDatetime.getTime())); |
|
242 System.out.println( |
|
243 Attributes.readBasicFileAttributes(path).toString()); |
|
244 } |
|
245 break; |
|
246 case setctime: |
|
247 df = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss"); |
|
248 newDatetime = df.parse(args[2]); |
|
249 for (int i = 3; i < args.length; i++) { |
|
250 path = fs.getPath(args[i]); |
|
251 path.setAttribute("creationTime", |
|
252 FileTime.fromMillis(newDatetime.getTime())); |
|
253 System.out.println( |
|
254 Attributes.readBasicFileAttributes(path).toString()); |
|
255 } |
|
256 break; |
|
257 case setatime: |
|
258 df = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss"); |
|
259 newDatetime = df.parse(args[2]); |
|
260 for (int i = 3; i < args.length; i++) { |
|
261 path = fs.getPath(args[i]); |
|
262 path.setAttribute("lastAccessTime", |
219 FileTime.fromMillis(newDatetime.getTime())); |
263 FileTime.fromMillis(newDatetime.getTime())); |
220 System.out.println( |
264 System.out.println( |
221 Attributes.readBasicFileAttributes(path).toString()); |
265 Attributes.readBasicFileAttributes(path).toString()); |
222 } |
266 } |
223 break; |
267 break; |
291 mkdirs(fs.getPath(args[2])); |
335 mkdirs(fs.getPath(args[2])); |
292 break; |
336 break; |
293 case attrs2: |
337 case attrs2: |
294 for (int i = 2; i < args.length; i++) { |
338 for (int i = 2; i < args.length; i++) { |
295 path = fs.getPath(args[i]); |
339 path = fs.getPath(args[i]); |
|
340 System.out.printf("%n%s%n", path); |
296 System.out.println("-------(1)---------"); |
341 System.out.println("-------(1)---------"); |
297 System.out.println( |
342 System.out.println( |
298 Attributes.readBasicFileAttributes(path).toString()); |
343 Attributes.readBasicFileAttributes(path).toString()); |
299 System.out.println("-------(2)---------"); |
344 System.out.println("-------(2)---------"); |
300 Map<String, ?> map = path.readAttributes("zip:*"); |
345 Map<String, ?> map = path.readAttributes("zip:*"); |
306 for (Map.Entry<String, ?> e : map.entrySet()) { |
351 for (Map.Entry<String, ?> e : map.entrySet()) { |
307 System.out.printf(" %s : %s%n", e.getKey(), e.getValue()); |
352 System.out.printf(" %s : %s%n", e.getKey(), e.getValue()); |
308 } |
353 } |
309 } |
354 } |
310 break; |
355 break; |
|
356 case prof: |
|
357 list(fs.getPath("/"), false); |
|
358 while (true) { |
|
359 Thread.sleep(10000); |
|
360 //list(fs.getPath("/"), true); |
|
361 System.out.println("sleeping..."); |
|
362 } |
311 } |
363 } |
312 } catch (Exception x) { |
364 } catch (Exception x) { |
313 x.printStackTrace(); |
365 x.printStackTrace(); |
314 } finally { |
366 } finally { |
315 if (fs != null) |
367 if (fs != null) |
499 path = path.getParent(); |
551 path = path.getParent(); |
500 } |
552 } |
501 } |
553 } |
502 |
554 |
503 private static void list(Path path, boolean verbose ) throws IOException { |
555 private static void list(Path path, boolean verbose ) throws IOException { |
504 if (verbose) |
556 if (!"/".equals(path.toString())) { |
505 System.out.println(Attributes.readBasicFileAttributes(path).toString()); |
557 System.out.printf(" %s%n", path.toString()); |
506 else |
558 if (verbose) |
507 System.out.printf(" %s%n", path.toString()); |
559 System.out.println(Attributes.readBasicFileAttributes(path).toString()); |
|
560 } |
508 if (path.notExists()) |
561 if (path.notExists()) |
509 return; |
562 return; |
510 if (Attributes.readBasicFileAttributes(path).isDirectory()) { |
563 if (Attributes.readBasicFileAttributes(path).isDirectory()) { |
511 DirectoryStream<Path> ds = path.newDirectoryStream(); |
564 DirectoryStream<Path> ds = path.newDirectoryStream(); |
512 for (Path child : ds) |
565 for (Path child : ds) |