equal
deleted
inserted
replaced
43 import static java.nio.file.StandardCopyOption.*; |
43 import static java.nio.file.StandardCopyOption.*; |
44 |
44 |
45 /* |
45 /* |
46 * ZipFileSystem usage demo |
46 * ZipFileSystem usage demo |
47 * |
47 * |
48 * java [-cp .../zipfs.jar:./] Demo action ZipfileName [...] |
48 * java Demo action ZipfileName [...] |
49 * |
|
50 * To deploy the provider, either copy the zipfs.jar into JDK/JRE |
|
51 * extensions directory or add |
|
52 * <JDK_HOME>/demo/nio/ZipFileSystem/zipfs.jar |
|
53 * into your class path as showed above. |
|
54 * |
49 * |
55 * @author Xueming Shen |
50 * @author Xueming Shen |
56 */ |
51 */ |
57 |
52 |
58 public class Demo { |
53 public class Demo { |
151 public static void main(String[] args) throws Throwable { |
146 public static void main(String[] args) throws Throwable { |
152 |
147 |
153 Action action = Action.valueOf(args[0]); |
148 Action action = Action.valueOf(args[0]); |
154 Map<String, Object> env = env = new HashMap<>(); |
149 Map<String, Object> env = env = new HashMap<>(); |
155 if (action == Action.create) |
150 if (action == Action.create) |
156 env.put("createNew", true); |
151 env.put("create", "true"); |
157 if (action == Action.tlist || action == Action.twalk) |
152 if (action == Action.tlist || action == Action.twalk) |
158 env.put("buildDirTree", true); |
153 env.put("buildDirTree", true); |
159 |
154 FileSystem fs = FileSystems.newFileSystem(Paths.get(args[1]), env, null); |
160 FileSystem fs = FileSystems.newFileSystem( |
155 |
161 URI.create("zip" + Paths.get(args[1]).toUri().toString().substring(4)), |
|
162 env, |
|
163 null); |
|
164 try { |
156 try { |
165 FileSystem fs2; |
157 FileSystem fs2; |
166 Path path, src, dst; |
158 Path path, src, dst; |
167 boolean isRename = false; |
159 boolean isRename = false; |
168 switch (action) { |
160 switch (action) { |
205 src = fs.getPath(args[2]); |
197 src = fs.getPath(args[2]); |
206 dst = Paths.get(args[3]); |
198 dst = Paths.get(args[3]); |
207 src.copyTo(dst, COPY_ATTRIBUTES); |
199 src.copyTo(dst, COPY_ATTRIBUTES); |
208 break; |
200 break; |
209 case zzmove: |
201 case zzmove: |
210 fs2 = FileSystems.newFileSystem( |
202 fs2 = FileSystems.newFileSystem(Paths.get(args[2]), env, null); |
211 URI.create("zip" + Paths.get(args[2]).toUri().toString().substring(4)), |
|
212 env, |
|
213 null); |
|
214 //sf1.getPath(args[3]).moveTo(fs2.getPath(args[3])); |
203 //sf1.getPath(args[3]).moveTo(fs2.getPath(args[3])); |
215 z2zmove(fs, fs2, args[3]); |
204 z2zmove(fs, fs2, args[3]); |
216 fs2.close(); |
205 fs2.close(); |
217 break; |
206 break; |
218 case zzcopy: |
207 case zzcopy: |
219 fs2 = FileSystems.newFileSystem( |
208 fs2 = FileSystems.newFileSystem(Paths.get(args[2]), env, null); |
220 URI.create("zip" + Paths.get(args[2]).toUri().toString().substring(4)), |
|
221 env, |
|
222 null); |
|
223 //sf1.getPath(args[3]).copyTo(fs2.getPath(args[3])); |
209 //sf1.getPath(args[3]).copyTo(fs2.getPath(args[3])); |
224 z2zcopy(fs, fs2, args[3]); |
210 z2zcopy(fs, fs2, args[3]); |
225 fs2.close(); |
211 fs2.close(); |
226 break; |
212 break; |
227 case attrs: |
213 case attrs: |