author | sherman |
Mon, 06 Dec 2010 13:18:16 -0800 | |
changeset 7531 | 77870839c857 |
permissions | -rw-r--r-- |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
1 |
/* |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
2 |
* Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
3 |
* |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
4 |
* Redistribution and use in source and binary forms, with or without |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
5 |
* modification, are permitted provided that the following conditions |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
6 |
* are met: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
7 |
* |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
8 |
* - Redistributions of source code must retain the above copyright |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
9 |
* notice, this list of conditions and the following disclaimer. |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
10 |
* |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
11 |
* - Redistributions in binary form must reproduce the above copyright |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
12 |
* notice, this list of conditions and the following disclaimer in the |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
13 |
* documentation and/or other materials provided with the distribution. |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
14 |
* |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
15 |
* - Neither the name of Oracle nor the names of its |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
16 |
* contributors may be used to endorse or promote products derived |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
17 |
* from this software without specific prior written permission. |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
18 |
* |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
19 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
20 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
21 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
22 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
23 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
24 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
25 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
26 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
27 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
28 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
29 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
30 |
*/ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
31 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
32 |
import java.io.*; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
33 |
import java.nio.*; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
34 |
import java.nio.channels.*; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
35 |
import java.nio.file.*; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
36 |
import java.nio.file.attribute.*; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
37 |
import java.net.*; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
38 |
import java.text.DateFormat; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
39 |
import java.text.SimpleDateFormat; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
40 |
import java.util.*; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
41 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
42 |
import static java.nio.file.StandardOpenOption.*; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
43 |
import static java.nio.file.StandardCopyOption.*; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
44 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
45 |
/* |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
46 |
* ZipFileSystem usage demo |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
47 |
* |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
48 |
* java Demo action ZipfileName [...] |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
49 |
* |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
50 |
* @author Xueming Shen |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
51 |
*/ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
52 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
53 |
public class Demo { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
54 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
55 |
static enum Action { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
56 |
rename, // <java Demo rename zipfile src dst> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
57 |
// rename entry src to dst inside zipfile |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
58 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
59 |
movein, // <java Demo movein zipfile src dst> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
60 |
// move an external src file into zipfile |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
61 |
// as entry dst |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
62 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
63 |
moveout, // <java Demo moveout zipfile src dst> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
64 |
// move a zipfile entry src out to dst |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
65 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
66 |
copy, // <java Demo copy zipfile src dst> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
67 |
// copy entry src to dst inside zipfile |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
68 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
69 |
copyin, // <java Demo copyin zipfile src dst> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
70 |
// copy an external src file into zipfile |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
71 |
// as entry dst |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
72 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
73 |
copyin_attrs, // <java Demo copyin_attrs zipfile src dst> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
74 |
// copy an external src file into zipfile |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
75 |
// as entry dst, with attributes (timestamp) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
76 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
77 |
copyout, // <java Demo copyout zipfile src dst> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
78 |
// copy zipfile entry src" out to file dst |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
79 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
80 |
copyout_attrs, // <java Demo copyout_attrs zipfile src dst> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
81 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
82 |
zzmove, // <java Demo zzmove zfsrc zfdst path> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
83 |
// move entry path/dir from zfsrc to zfdst |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
84 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
85 |
zzcopy, // <java Demo zzcopy zfsrc zfdst path> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
86 |
// copy path from zipfile zfsrc to zipfile |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
87 |
// zfdst |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
88 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
89 |
attrs, // <java Demo attrs zipfile path> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
90 |
// printout the attributes of entry path |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
91 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
92 |
attrsspace, // <java Demo attrsspace zipfile path> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
93 |
// printout the storespace attrs of entry path |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
94 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
95 |
setmtime, // <java Demo setmtime zipfile "MM/dd/yy-HH:mm:ss" path...> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
96 |
// set the lastModifiedTime of entry path |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
97 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
98 |
setatime, // <java Demo setatime zipfile "MM/dd/yy-HH:mm:ss" path...> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
99 |
setctime, // <java Demo setctime zipfile "MM/dd/yy-HH:mm:ss" path...> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
100 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
101 |
lsdir, // <java Demo lsdir zipfile dir> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
102 |
// list dir's direct child files/dirs |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
103 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
104 |
mkdir, // <java Demo mkdir zipfile dir> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
105 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
106 |
mkdirs, // <java Demo mkdirs zipfile dir> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
107 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
108 |
rmdirs, // <java Demo rmdirs zipfile dir> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
109 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
110 |
list, // <java Demo list zipfile [dir]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
111 |
// recursively list all entries of dir |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
112 |
// via DirectoryStream |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
113 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
114 |
tlist, // <java Demo tlist zipfile [dir]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
115 |
// list with buildDirTree=true |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
116 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
117 |
vlist, // <java Demo vlist zipfile [dir]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
118 |
// recursively verbose list all entries of |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
119 |
// dir via DirectoryStream |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
120 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
121 |
walk, // <java Demo walk zipfile [dir]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
122 |
// recursively walk all entries of dir |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
123 |
// via Files.walkFileTree |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
124 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
125 |
twalk, // <java Demo twalk zipfile [dir]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
126 |
// walk with buildDirTree=true |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
127 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
128 |
extract, // <java Demo extract zipfile file [...]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
129 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
130 |
update, // <java Demo extract zipfile file [...]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
131 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
132 |
delete, // <java Demo delete zipfile file [...]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
133 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
134 |
add, // <java Demo add zipfile file [...]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
135 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
136 |
create, // <java Demo create zipfile file [...]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
137 |
// create a new zipfile if it doesn't exit |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
138 |
// and then add the file(s) into it. |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
139 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
140 |
attrs2, // <java Demo attrs2 zipfile file [...]> |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
141 |
// test different ways to print attrs |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
142 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
143 |
prof, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
144 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
145 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
146 |
public static void main(String[] args) throws Throwable { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
147 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
148 |
Action action = Action.valueOf(args[0]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
149 |
Map<String, Object> env = env = new HashMap<>(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
150 |
if (action == Action.create) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
151 |
env.put("create", "true"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
152 |
if (action == Action.tlist || action == Action.twalk) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
153 |
env.put("buildDirTree", true); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
154 |
FileSystem fs = FileSystems.newFileSystem(Paths.get(args[1]), env, null); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
155 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
156 |
try { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
157 |
FileSystem fs2; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
158 |
Path path, src, dst; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
159 |
boolean isRename = false; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
160 |
switch (action) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
161 |
case rename: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
162 |
src = fs.getPath(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
163 |
dst = fs.getPath(args[3]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
164 |
src.moveTo(dst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
165 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
166 |
case moveout: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
167 |
src = fs.getPath(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
168 |
dst = Paths.get(args[3]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
169 |
src.moveTo(dst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
170 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
171 |
case movein: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
172 |
src = Paths.get(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
173 |
dst = fs.getPath(args[3]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
174 |
src.moveTo(dst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
175 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
176 |
case copy: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
177 |
src = fs.getPath(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
178 |
dst = fs.getPath(args[3]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
179 |
src.copyTo(dst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
180 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
181 |
case copyout: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
182 |
src = fs.getPath(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
183 |
dst = Paths.get(args[3]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
184 |
src.copyTo(dst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
185 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
186 |
case copyin: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
187 |
src = Paths.get(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
188 |
dst = fs.getPath(args[3]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
189 |
src.copyTo(dst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
190 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
191 |
case copyin_attrs: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
192 |
src = Paths.get(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
193 |
dst = fs.getPath(args[3]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
194 |
src.copyTo(dst, COPY_ATTRIBUTES); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
195 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
196 |
case copyout_attrs: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
197 |
src = fs.getPath(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
198 |
dst = Paths.get(args[3]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
199 |
src.copyTo(dst, COPY_ATTRIBUTES); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
200 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
201 |
case zzmove: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
202 |
fs2 = FileSystems.newFileSystem(Paths.get(args[2]), env, null); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
203 |
//sf1.getPath(args[3]).moveTo(fs2.getPath(args[3])); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
204 |
z2zmove(fs, fs2, args[3]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
205 |
fs2.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
206 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
207 |
case zzcopy: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
208 |
fs2 = FileSystems.newFileSystem(Paths.get(args[2]), env, null); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
209 |
//sf1.getPath(args[3]).copyTo(fs2.getPath(args[3])); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
210 |
z2zcopy(fs, fs2, args[3]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
211 |
fs2.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
212 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
213 |
case attrs: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
214 |
for (int i = 2; i < args.length; i++) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
215 |
path = fs.getPath(args[i]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
216 |
System.out.println(path); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
217 |
System.out.println( |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
218 |
Attributes.readBasicFileAttributes(path).toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
219 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
220 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
221 |
case setmtime: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
222 |
DateFormat df = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
223 |
Date newDatetime = df.parse(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
224 |
for (int i = 3; i < args.length; i++) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
225 |
path = fs.getPath(args[i]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
226 |
path.setAttribute("lastModifiedTime", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
227 |
FileTime.fromMillis(newDatetime.getTime())); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
228 |
System.out.println( |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
229 |
Attributes.readBasicFileAttributes(path).toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
230 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
231 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
232 |
case setctime: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
233 |
df = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
234 |
newDatetime = df.parse(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
235 |
for (int i = 3; i < args.length; i++) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
236 |
path = fs.getPath(args[i]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
237 |
path.setAttribute("creationTime", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
238 |
FileTime.fromMillis(newDatetime.getTime())); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
239 |
System.out.println( |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
240 |
Attributes.readBasicFileAttributes(path).toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
241 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
242 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
243 |
case setatime: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
244 |
df = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
245 |
newDatetime = df.parse(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
246 |
for (int i = 3; i < args.length; i++) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
247 |
path = fs.getPath(args[i]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
248 |
path.setAttribute("lastAccessTime", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
249 |
FileTime.fromMillis(newDatetime.getTime())); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
250 |
System.out.println( |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
251 |
Attributes.readBasicFileAttributes(path).toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
252 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
253 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
254 |
case attrsspace: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
255 |
path = fs.getPath("/"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
256 |
FileStore fstore = path.getFileStore(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
257 |
//System.out.println(fstore.getFileStoreAttributeView(FileStoreSpaceAttributeView.class) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
258 |
// .readAttributes()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
259 |
// or |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
260 |
System.out.printf("filestore[%s]%n", fstore.name()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
261 |
System.out.printf(" totalSpace: %d%n", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
262 |
(Long)fstore.getAttribute("space:totalSpace")); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
263 |
System.out.printf(" usableSpace: %d%n", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
264 |
(Long)fstore.getAttribute("space:usableSpace")); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
265 |
System.out.printf(" unallocSpace: %d%n", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
266 |
(Long)fstore.getAttribute("space:unallocatedSpace")); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
267 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
268 |
case list: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
269 |
case tlist: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
270 |
if (args.length < 3) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
271 |
list(fs.getPath("/"), false); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
272 |
else |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
273 |
list(fs.getPath(args[2]), false); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
274 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
275 |
case vlist: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
276 |
if (args.length < 3) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
277 |
list(fs.getPath("/"), true); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
278 |
else |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
279 |
list(fs.getPath(args[2]), true); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
280 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
281 |
case twalk: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
282 |
case walk: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
283 |
walk(fs.getPath((args.length > 2)? args[2] : "/")); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
284 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
285 |
case extract: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
286 |
if (args.length == 2) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
287 |
extract(fs, "/"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
288 |
} else { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
289 |
for (int i = 2; i < args.length; i++) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
290 |
extract(fs, args[i]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
291 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
292 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
293 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
294 |
case delete: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
295 |
for (int i = 2; i < args.length; i++) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
296 |
fs.getPath(args[i]).delete(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
297 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
298 |
case create: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
299 |
case add: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
300 |
case update: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
301 |
for (int i = 2; i < args.length; i++) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
302 |
update(fs, args[i]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
303 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
304 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
305 |
case lsdir: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
306 |
path = fs.getPath(args[2]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
307 |
final String fStr = (args.length > 3)?args[3]:""; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
308 |
DirectoryStream<Path> ds = path.newDirectoryStream( |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
309 |
new DirectoryStream.Filter<Path>() { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
310 |
public boolean accept(Path path) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
311 |
return path.toString().contains(fStr); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
312 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
313 |
}); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
314 |
for (Path p : ds) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
315 |
System.out.println(p); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
316 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
317 |
case mkdir: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
318 |
fs.getPath(args[2]).createDirectory(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
319 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
320 |
case mkdirs: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
321 |
mkdirs(fs.getPath(args[2])); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
322 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
323 |
case attrs2: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
324 |
for (int i = 2; i < args.length; i++) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
325 |
path = fs.getPath(args[i]); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
326 |
System.out.printf("%n%s%n", path); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
327 |
System.out.println("-------(1)---------"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
328 |
System.out.println( |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
329 |
Attributes.readBasicFileAttributes(path).toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
330 |
System.out.println("-------(2)---------"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
331 |
Map<String, ?> map = path.readAttributes("zip:*"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
332 |
for (Map.Entry<String, ?> e : map.entrySet()) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
333 |
System.out.printf(" %s : %s%n", e.getKey(), e.getValue()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
334 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
335 |
System.out.println("-------(3)---------"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
336 |
map = path.readAttributes("size,lastModifiedTime,isDirectory"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
337 |
for (Map.Entry<String, ?> e : map.entrySet()) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
338 |
System.out.printf(" %s : %s%n", e.getKey(), e.getValue()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
339 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
340 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
341 |
break; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
342 |
case prof: |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
343 |
list(fs.getPath("/"), false); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
344 |
while (true) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
345 |
Thread.sleep(10000); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
346 |
//list(fs.getPath("/"), true); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
347 |
System.out.println("sleeping..."); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
348 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
349 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
350 |
} catch (Exception x) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
351 |
x.printStackTrace(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
352 |
} finally { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
353 |
if (fs != null) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
354 |
fs.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
355 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
356 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
357 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
358 |
private static byte[] getBytes(String name) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
359 |
return name.getBytes(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
360 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
361 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
362 |
private static String getString(byte[] name) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
363 |
return new String(name); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
364 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
365 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
366 |
private static void walk(Path path) throws IOException |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
367 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
368 |
Files.walkFileTree( |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
369 |
path, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
370 |
new SimpleFileVisitor<Path>() { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
371 |
private int indent = 0; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
372 |
private void indent() { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
373 |
int n = 0; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
374 |
while (n++ < indent) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
375 |
System.out.printf(" "); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
376 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
377 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
378 |
@Override |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
379 |
public FileVisitResult visitFile(Path file, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
380 |
BasicFileAttributes attrs) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
381 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
382 |
indent(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
383 |
System.out.printf("%s%n", file.getName().toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
384 |
return FileVisitResult.CONTINUE; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
385 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
386 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
387 |
@Override |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
388 |
public FileVisitResult preVisitDirectory(Path dir, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
389 |
BasicFileAttributes attrs) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
390 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
391 |
indent(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
392 |
System.out.printf("[%s]%n", dir.toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
393 |
indent += 2; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
394 |
return FileVisitResult.CONTINUE; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
395 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
396 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
397 |
@Override |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
398 |
public FileVisitResult postVisitDirectory(Path dir, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
399 |
IOException ioe) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
400 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
401 |
indent -= 2; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
402 |
return FileVisitResult.CONTINUE; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
403 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
404 |
}); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
405 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
406 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
407 |
private static void update(FileSystem fs, String path) throws Throwable{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
408 |
Path src = FileSystems.getDefault().getPath(path); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
409 |
if (Boolean.TRUE.equals(src.getAttribute("isDirectory"))) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
410 |
DirectoryStream<Path> ds = src.newDirectoryStream(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
411 |
for (Path child : ds) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
412 |
update(fs, child.toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
413 |
ds.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
414 |
} else { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
415 |
Path dst = fs.getPath(path); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
416 |
Path parent = dst.getParent(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
417 |
if (parent != null && parent.notExists()) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
418 |
mkdirs(parent); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
419 |
src.copyTo(dst, REPLACE_EXISTING); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
420 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
421 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
422 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
423 |
private static void extract(FileSystem fs, String path) throws Throwable{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
424 |
Path src = fs.getPath(path); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
425 |
if (Boolean.TRUE.equals(src.getAttribute("isDirectory"))) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
426 |
DirectoryStream<Path> ds = src.newDirectoryStream(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
427 |
for (Path child : ds) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
428 |
extract(fs, child.toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
429 |
ds.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
430 |
} else { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
431 |
if (path.startsWith("/")) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
432 |
path = path.substring(1); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
433 |
Path dst = FileSystems.getDefault().getPath(path); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
434 |
Path parent = dst.getParent(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
435 |
if (parent.notExists()) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
436 |
mkdirs(parent); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
437 |
src.copyTo(dst, REPLACE_EXISTING); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
438 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
439 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
440 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
441 |
// use DirectoryStream |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
442 |
private static void z2zcopy(FileSystem src, FileSystem dst, String path) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
443 |
throws IOException |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
444 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
445 |
Path srcPath = src.getPath(path); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
446 |
Path dstPath = dst.getPath(path); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
447 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
448 |
if (Boolean.TRUE.equals(srcPath.getAttribute("isDirectory"))) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
449 |
if (!dstPath.exists()) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
450 |
try { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
451 |
mkdirs(dstPath); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
452 |
} catch (FileAlreadyExistsException x) {} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
453 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
454 |
DirectoryStream<Path> ds = srcPath.newDirectoryStream(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
455 |
for (Path child : ds) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
456 |
z2zcopy(src, dst, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
457 |
path + (path.endsWith("/")?"":"/") + child.getName()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
458 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
459 |
ds.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
460 |
} else { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
461 |
//System.out.println("copying..." + path); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
462 |
srcPath.copyTo(dstPath); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
463 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
464 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
465 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
466 |
// use TreeWalk to move |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
467 |
private static void z2zmove(FileSystem src, FileSystem dst, String path) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
468 |
throws IOException |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
469 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
470 |
final Path srcPath = src.getPath(path).toAbsolutePath(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
471 |
final Path dstPath = dst.getPath(path).toAbsolutePath(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
472 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
473 |
Files.walkFileTree(srcPath, new SimpleFileVisitor<Path>() { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
474 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
475 |
@Override |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
476 |
public FileVisitResult visitFile(Path file, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
477 |
BasicFileAttributes attrs) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
478 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
479 |
Path dst = srcPath.relativize(file); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
480 |
dst = dstPath.resolve(dst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
481 |
try { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
482 |
Path parent = dstPath.getParent(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
483 |
if (parent != null && parent.notExists()) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
484 |
mkdirs(parent); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
485 |
file.moveTo(dst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
486 |
} catch (IOException x) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
487 |
x.printStackTrace(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
488 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
489 |
return FileVisitResult.CONTINUE; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
490 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
491 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
492 |
@Override |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
493 |
public FileVisitResult preVisitDirectory(Path dir, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
494 |
BasicFileAttributes attrs) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
495 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
496 |
Path dst = srcPath.relativize(dir); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
497 |
dst = dstPath.resolve(dst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
498 |
try { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
499 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
500 |
if (dst.notExists()) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
501 |
mkdirs(dst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
502 |
} catch (IOException x) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
503 |
x.printStackTrace(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
504 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
505 |
return FileVisitResult.CONTINUE; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
506 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
507 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
508 |
@Override |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
509 |
public FileVisitResult postVisitDirectory(Path dir, |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
510 |
IOException ioe) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
511 |
throws IOException |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
512 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
513 |
try { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
514 |
dir.delete(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
515 |
} catch (IOException x) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
516 |
//x.printStackTrace(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
517 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
518 |
return FileVisitResult.CONTINUE; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
519 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
520 |
}); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
521 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
522 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
523 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
524 |
private static void mkdirs(Path path) throws IOException { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
525 |
path = path.toAbsolutePath(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
526 |
Path parent = path.getParent(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
527 |
if (parent != null) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
528 |
if (parent.notExists()) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
529 |
mkdirs(parent); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
530 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
531 |
path.createDirectory(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
532 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
533 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
534 |
private static void rmdirs(Path path) throws IOException { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
535 |
while (path != null && path.getNameCount() != 0) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
536 |
path.delete(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
537 |
path = path.getParent(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
538 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
539 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
540 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
541 |
private static void list(Path path, boolean verbose ) throws IOException { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
542 |
if (!"/".equals(path.toString())) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
543 |
System.out.printf(" %s%n", path.toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
544 |
if (verbose) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
545 |
System.out.println(Attributes.readBasicFileAttributes(path).toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
546 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
547 |
if (path.notExists()) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
548 |
return; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
549 |
if (Attributes.readBasicFileAttributes(path).isDirectory()) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
550 |
DirectoryStream<Path> ds = path.newDirectoryStream(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
551 |
for (Path child : ds) |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
552 |
list(child, verbose); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
553 |
ds.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
554 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
555 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
556 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
557 |
// check the content of two paths are equal |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
558 |
private static void checkEqual(Path src, Path dst) throws IOException |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
559 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
560 |
//System.out.printf("checking <%s> vs <%s>...%n", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
561 |
// src.toString(), dst.toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
562 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
563 |
//streams |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
564 |
InputStream isSrc = src.newInputStream(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
565 |
InputStream isDst = dst.newInputStream(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
566 |
byte[] bufSrc = new byte[8192]; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
567 |
byte[] bufDst = new byte[8192]; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
568 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
569 |
try { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
570 |
int nSrc = 0; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
571 |
while ((nSrc = isSrc.read(bufSrc)) != -1) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
572 |
int nDst = 0; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
573 |
while (nDst < nSrc) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
574 |
int n = isDst.read(bufDst, nDst, nSrc - nDst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
575 |
if (n == -1) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
576 |
System.out.printf("checking <%s> vs <%s>...%n", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
577 |
src.toString(), dst.toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
578 |
throw new RuntimeException("CHECK FAILED!"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
579 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
580 |
nDst += n; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
581 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
582 |
while (--nSrc >= 0) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
583 |
if (bufSrc[nSrc] != bufDst[nSrc]) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
584 |
System.out.printf("checking <%s> vs <%s>...%n", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
585 |
src.toString(), dst.toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
586 |
throw new RuntimeException("CHECK FAILED!"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
587 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
588 |
nSrc--; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
589 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
590 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
591 |
} finally { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
592 |
isSrc.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
593 |
isDst.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
594 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
595 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
596 |
// channels |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
597 |
SeekableByteChannel chSrc = src.newByteChannel(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
598 |
SeekableByteChannel chDst = dst.newByteChannel(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
599 |
if (chSrc.size() != chDst.size()) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
600 |
System.out.printf("src[%s].size=%d, dst[%s].size=%d%n", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
601 |
chSrc.toString(), chSrc.size(), |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
602 |
chDst.toString(), chDst.size()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
603 |
throw new RuntimeException("CHECK FAILED!"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
604 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
605 |
ByteBuffer bbSrc = ByteBuffer.allocate(8192); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
606 |
ByteBuffer bbDst = ByteBuffer.allocate(8192); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
607 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
608 |
try { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
609 |
int nSrc = 0; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
610 |
while ((nSrc = chSrc.read(bbSrc)) != -1) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
611 |
int nDst = chDst.read(bbDst); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
612 |
if (nSrc != nDst) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
613 |
System.out.printf("checking <%s> vs <%s>...%n", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
614 |
src.toString(), dst.toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
615 |
throw new RuntimeException("CHECK FAILED!"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
616 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
617 |
while (--nSrc >= 0) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
618 |
if (bbSrc.get(nSrc) != bbDst.get(nSrc)) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
619 |
System.out.printf("checking <%s> vs <%s>...%n", |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
620 |
src.toString(), dst.toString()); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
621 |
throw new RuntimeException("CHECK FAILED!"); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
622 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
623 |
nSrc--; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
624 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
625 |
bbSrc.flip(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
626 |
bbDst.flip(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
627 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
628 |
} catch (IOException x) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
629 |
x.printStackTrace(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
630 |
} finally { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
631 |
chSrc.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
632 |
chDst.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
633 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
634 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
635 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
636 |
private static void fchCopy(Path src, Path dst) throws IOException |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
637 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
638 |
Set<OpenOption> read = new HashSet<>(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
639 |
read.add(READ); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
640 |
Set<OpenOption> openwrite = new HashSet<>(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
641 |
openwrite.add(CREATE_NEW); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
642 |
openwrite.add(WRITE); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
643 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
644 |
FileChannel srcFc = src.getFileSystem() |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
645 |
.provider() |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
646 |
.newFileChannel(src, read); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
647 |
FileChannel dstFc = dst.getFileSystem() |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
648 |
.provider() |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
649 |
.newFileChannel(dst, openwrite); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
650 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
651 |
try { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
652 |
ByteBuffer bb = ByteBuffer.allocate(8192); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
653 |
while (srcFc.read(bb) >= 0) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
654 |
bb.flip(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
655 |
dstFc.write(bb); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
656 |
bb.clear(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
657 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
658 |
} finally { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
659 |
srcFc.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
660 |
dstFc.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
661 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
662 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
663 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
664 |
private static void chCopy(Path src, Path dst) throws IOException |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
665 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
666 |
Set<OpenOption> read = new HashSet<>(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
667 |
read.add(READ); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
668 |
Set<OpenOption> openwrite = new HashSet<>(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
669 |
openwrite.add(CREATE_NEW); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
670 |
openwrite.add(WRITE); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
671 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
672 |
SeekableByteChannel srcCh = src.newByteChannel(read); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
673 |
SeekableByteChannel dstCh = dst.newByteChannel(openwrite); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
674 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
675 |
try { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
676 |
ByteBuffer bb = ByteBuffer.allocate(8192); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
677 |
while (srcCh.read(bb) >= 0) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
678 |
bb.flip(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
679 |
dstCh.write(bb); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
680 |
bb.clear(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
681 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
682 |
} finally { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
683 |
srcCh.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
684 |
dstCh.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
685 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
686 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
687 |
|
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
688 |
private static void streamCopy(Path src, Path dst) throws IOException |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
689 |
{ |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
690 |
InputStream isSrc = src.newInputStream(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
691 |
OutputStream osDst = dst.newOutputStream(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
692 |
byte[] buf = new byte[8192]; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
693 |
try { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
694 |
int n = 0; |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
695 |
while ((n = isSrc.read(buf)) != -1) { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
696 |
osDst.write(buf, 0, n); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
697 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
698 |
} finally { |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
699 |
isSrc.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
700 |
osDst.close(); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
701 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
702 |
} |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
diff
changeset
|
703 |
} |