author | juh |
Wed, 10 Jul 2013 18:01:22 -0700 | |
changeset 18800 | e7fa560afcfb |
parent 18150 | 237f3c2875aa |
child 21596 | 0e3a39f29dbc |
permissions | -rw-r--r-- |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1 |
/* |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2 |
* Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
4 |
* |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
8 |
* |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
13 |
* accompanied this code). |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
14 |
* |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
18 |
* |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
21 |
* questions. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
22 |
*/ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
23 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
24 |
import java.io.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
25 |
import java.nio.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
26 |
import java.nio.channels.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
27 |
import java.nio.file.*; |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
28 |
import java.nio.file.spi.*; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
29 |
import java.nio.file.attribute.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
30 |
import java.net.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
31 |
import java.util.*; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
32 |
import java.util.concurrent.TimeUnit; |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
33 |
import java.util.zip.*; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
34 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
35 |
import static java.nio.file.StandardOpenOption.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
36 |
import static java.nio.file.StandardCopyOption.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
37 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
38 |
/* |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
39 |
* Tests various zipfs operations. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
40 |
*/ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
41 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
42 |
public class ZipFSTester { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
43 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
44 |
public static void main(String[] args) throws Throwable { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
45 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
46 |
try (FileSystem fs = newZipFileSystem(Paths.get(args[0]), |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
47 |
new HashMap<String, Object>())) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
48 |
{ |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
49 |
test0(fs); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
50 |
test1(fs); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
51 |
test2(fs); // more tests |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
52 |
testTime(Paths.get(args[0])); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
53 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
54 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
55 |
|
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
56 |
static void test0(FileSystem fs) |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
57 |
throws Exception |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
58 |
{ |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
59 |
List<String> list = new LinkedList<>(); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
60 |
try (ZipFile zf = new ZipFile(fs.toString())) { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
61 |
Enumeration<? extends ZipEntry> zes = zf.entries(); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
62 |
while (zes.hasMoreElements()) { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
63 |
list.add(zes.nextElement().getName()); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
64 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
65 |
for (String pname : list) { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
66 |
Path path = fs.getPath(pname); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
67 |
if (!Files.exists(path)) |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
68 |
throw new RuntimeException("path existence check failed!"); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
69 |
while ((path = path.getParent()) != null) { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
70 |
if (!Files.exists(path)) |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
71 |
throw new RuntimeException("parent existence check failed!"); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
72 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
73 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
74 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
75 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
76 |
|
8190
c8cdf811a171
7017840: (zipfs) test/demo/zipfs/basic.sh needs to be updated due to 7013420
sherman
parents:
8165
diff
changeset
|
77 |
static void test1(FileSystem fs0) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
78 |
throws Exception |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
79 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
80 |
Random rdm = new Random(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
81 |
// clone a fs and test on it |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
82 |
Path tmpfsPath = getTempPath(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
83 |
Map<String, Object> env = new HashMap<String, Object>(); |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
84 |
env.put("create", "true"); |
8190
c8cdf811a171
7017840: (zipfs) test/demo/zipfs/basic.sh needs to be updated due to 7013420
sherman
parents:
8165
diff
changeset
|
85 |
try (FileSystem copy = newZipFileSystem(tmpfsPath, env)) { |
c8cdf811a171
7017840: (zipfs) test/demo/zipfs/basic.sh needs to be updated due to 7013420
sherman
parents:
8165
diff
changeset
|
86 |
z2zcopy(fs0, copy, "/", 0); |
c8cdf811a171
7017840: (zipfs) test/demo/zipfs/basic.sh needs to be updated due to 7013420
sherman
parents:
8165
diff
changeset
|
87 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
88 |
|
8190
c8cdf811a171
7017840: (zipfs) test/demo/zipfs/basic.sh needs to be updated due to 7013420
sherman
parents:
8165
diff
changeset
|
89 |
try (FileSystem fs = newZipFileSystem(tmpfsPath, new HashMap<String, Object>())) { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
90 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
91 |
FileSystemProvider provider = fs.provider(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
92 |
// newFileSystem(path...) should not throw exception |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
93 |
try (FileSystem fsPath = provider.newFileSystem(tmpfsPath, new HashMap<String, Object>())){} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
94 |
try (FileSystem fsUri = provider.newFileSystem( |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
95 |
new URI("jar", tmpfsPath.toUri().toString(), null), |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
96 |
new HashMap<String, Object>())) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
97 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
98 |
throw new RuntimeException("newFileSystem(uri...) does not throw exception"); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
99 |
} catch (FileSystemAlreadyExistsException fsaee) {} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
100 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
101 |
// prepare a src |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
102 |
Path src = getTempPath(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
103 |
String tmpName = src.toString(); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
104 |
OutputStream os = Files.newOutputStream(src); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
105 |
byte[] bits = new byte[12345]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
106 |
rdm.nextBytes(bits); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
107 |
os.write(bits); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
108 |
os.close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
109 |
|
8386
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
110 |
try { |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
111 |
provider.newFileSystem(new File(System.getProperty("test.src", ".")).toPath(), |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
112 |
new HashMap<String, Object>()); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
113 |
throw new RuntimeException("newFileSystem() opens a directory as zipfs"); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
114 |
} catch (UnsupportedOperationException uoe) {} |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
115 |
|
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
116 |
try { |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
117 |
provider.newFileSystem(src, new HashMap<String, Object>()); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
118 |
throw new RuntimeException("newFileSystem() opens a non-zip file as zipfs"); |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
119 |
} catch (UnsupportedOperationException uoe) {} |
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
120 |
|
4a1a689a32e0
7007596: (zipfs) FileSystems.newFileSystem(FileRef...) always employs zipfs regardless the real Path type.
sherman
parents:
8190
diff
changeset
|
121 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
122 |
// copyin |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
123 |
Path dst = getPathWithParents(fs, tmpName); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
124 |
Files.copy(src, dst); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
125 |
checkEqual(src, dst); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
126 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
127 |
// copy |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
128 |
Path dst2 = getPathWithParents(fs, "/xyz" + rdm.nextInt(100) + |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
129 |
"/efg" + rdm.nextInt(100) + "/foo.class"); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
130 |
Files.copy(dst, dst2); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
131 |
//dst.moveTo(dst2); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
132 |
checkEqual(src, dst2); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
133 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
134 |
// delete |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
135 |
Files.delete(dst); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
136 |
if (Files.exists(dst)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
137 |
throw new RuntimeException("Failed!"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
138 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
139 |
// moveout |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
140 |
Path dst3 = Paths.get(tmpName + "_Tmp"); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
141 |
Files.move(dst2, dst3); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
142 |
checkEqual(src, dst3); |
16857
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
143 |
if (Files.exists(dst2)) |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
144 |
throw new RuntimeException("Failed!"); |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
145 |
|
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
146 |
// copyback + move |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
147 |
Files.copy(dst3, dst); |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
148 |
Path dst4 = getPathWithParents(fs, tmpName + "_Tmp0"); |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
149 |
Files.move(dst, dst4); |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
150 |
checkEqual(src, dst4); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
151 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
152 |
// delete |
16857
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
153 |
Files.delete(dst4); |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
154 |
if (Files.exists(dst4)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
155 |
throw new RuntimeException("Failed!"); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
156 |
Files.delete(dst3); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
157 |
if (Files.exists(dst3)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
158 |
throw new RuntimeException("Failed!"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
159 |
|
16857
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
160 |
// move (existing entry) |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
161 |
Path dst5 = fs.getPath("META-INF/MANIFEST.MF"); |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
162 |
if (Files.exists(dst5)) { |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
163 |
Path dst6 = fs.getPath("META-INF/MANIFEST.MF_TMP"); |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
164 |
Files.move(dst5, dst6); |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
165 |
walk(fs.getPath("/")); |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
166 |
} |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
12676
diff
changeset
|
167 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
168 |
// newInputStream on dir |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
169 |
Path parent = dst2.getParent(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
170 |
try { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
171 |
Files.newInputStream(parent); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
172 |
throw new RuntimeException("Failed"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
173 |
} catch (FileSystemException e) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
174 |
e.printStackTrace(); // expected fse |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
175 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
176 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
177 |
// rmdirs |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
178 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
179 |
rmdirs(parent); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
180 |
} catch (IOException x) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
181 |
x.printStackTrace(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
182 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
183 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
184 |
// newFileChannel() copy in, out and verify via fch |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
185 |
fchCopy(src, dst); // in |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
186 |
checkEqual(src, dst); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
187 |
Path tmp = Paths.get(tmpName + "_Tmp"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
188 |
fchCopy(dst, tmp); // out |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
189 |
checkEqual(src, tmp); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
190 |
Files.delete(tmp); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
191 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
192 |
// test channels |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
193 |
channel(fs, dst); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
194 |
Files.delete(dst); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
195 |
Files.delete(src); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
196 |
} finally { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
197 |
if (Files.exists(tmpfsPath)) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
198 |
Files.delete(tmpfsPath); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
199 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
200 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
201 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
202 |
static void test2(FileSystem fs) throws Exception { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
203 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
204 |
Path fs1Path = getTempPath(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
205 |
Path fs2Path = getTempPath(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
206 |
Path fs3Path = getTempPath(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
207 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
208 |
// create a new filesystem, copy everything from fs |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
209 |
Map<String, Object> env = new HashMap<String, Object>(); |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
210 |
env.put("create", "true"); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
211 |
FileSystem fs0 = newZipFileSystem(fs1Path, env); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
212 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
213 |
final FileSystem fs2 = newZipFileSystem(fs2Path, env); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
214 |
final FileSystem fs3 = newZipFileSystem(fs3Path, env); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
215 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
216 |
System.out.println("copy src: fs -> fs0..."); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
217 |
z2zcopy(fs, fs0, "/", 0); // copy fs -> fs1 |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
218 |
fs0.close(); // dump to file |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
219 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
220 |
System.out.println("open fs0 as fs1"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
221 |
env = new HashMap<String, Object>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
222 |
final FileSystem fs1 = newZipFileSystem(fs1Path, env); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
223 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
224 |
System.out.println("listing..."); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
225 |
final ArrayList<String> files = new ArrayList<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
226 |
final ArrayList<String> dirs = new ArrayList<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
227 |
list(fs1.getPath("/"), files, dirs); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
228 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
229 |
Thread t0 = new Thread(new Runnable() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
230 |
public void run() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
231 |
List<String> list = new ArrayList<>(dirs); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
232 |
Collections.shuffle(list); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
233 |
for (String path : list) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
234 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
235 |
z2zcopy(fs1, fs2, path, 0); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
236 |
} catch (Exception x) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
237 |
x.printStackTrace(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
238 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
239 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
240 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
241 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
242 |
}); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
243 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
244 |
Thread t1 = new Thread(new Runnable() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
245 |
public void run() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
246 |
List<String> list = new ArrayList<>(dirs); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
247 |
Collections.shuffle(list); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
248 |
for (String path : list) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
249 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
250 |
z2zcopy(fs1, fs2, path, 1); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
251 |
} catch (Exception x) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
252 |
x.printStackTrace(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
253 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
254 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
255 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
256 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
257 |
}); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
258 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
259 |
Thread t2 = new Thread(new Runnable() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
260 |
public void run() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
261 |
List<String> list = new ArrayList<>(dirs); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
262 |
Collections.shuffle(list); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
263 |
for (String path : list) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
264 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
265 |
z2zcopy(fs1, fs2, path, 2); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
266 |
} catch (Exception x) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
267 |
x.printStackTrace(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
268 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
269 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
270 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
271 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
272 |
}); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
273 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
274 |
Thread t3 = new Thread(new Runnable() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
275 |
public void run() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
276 |
List<String> list = new ArrayList<>(files); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
277 |
Collections.shuffle(list); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
278 |
while (!list.isEmpty()) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
279 |
Iterator<String> itr = list.iterator(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
280 |
while (itr.hasNext()) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
281 |
String path = itr.next(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
282 |
try { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
283 |
if (Files.exists(fs2.getPath(path))) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
284 |
z2zmove(fs2, fs3, path); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
285 |
itr.remove(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
286 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
287 |
} catch (FileAlreadyExistsException x){ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
288 |
itr.remove(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
289 |
} catch (Exception x) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
290 |
x.printStackTrace(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
291 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
292 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
293 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
294 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
295 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
296 |
}); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
297 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
298 |
System.out.println("copying/removing..."); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
299 |
t0.start(); t1.start(); t2.start(); t3.start(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
300 |
t0.join(); t1.join(); t2.join(); t3.join(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
301 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
302 |
System.out.println("closing: fs1, fs2"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
303 |
fs1.close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
304 |
fs2.close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
305 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
306 |
int failed = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
307 |
System.out.println("checkEqual: fs vs fs3"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
308 |
for (String path : files) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
309 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
310 |
checkEqual(fs.getPath(path), fs3.getPath(path)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
311 |
} catch (IOException x) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
312 |
//x.printStackTrace(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
313 |
failed++; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
314 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
315 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
316 |
System.out.println("closing: fs3"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
317 |
fs3.close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
318 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
319 |
System.out.println("opening: fs3 as fs4"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
320 |
FileSystem fs4 = newZipFileSystem(fs3Path, env); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
321 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
322 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
323 |
ArrayList<String> files2 = new ArrayList<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
324 |
ArrayList<String> dirs2 = new ArrayList<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
325 |
list(fs4.getPath("/"), files2, dirs2); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
326 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
327 |
System.out.println("checkEqual: fs vs fs4"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
328 |
for (String path : files2) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
329 |
checkEqual(fs.getPath(path), fs4.getPath(path)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
330 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
331 |
System.out.println("walking: fs4"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
332 |
walk(fs4.getPath("/")); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
333 |
System.out.println("closing: fs4"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
334 |
fs4.close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
335 |
System.out.printf("failed=%d%n", failed); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
336 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
337 |
Files.delete(fs1Path); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
338 |
Files.delete(fs2Path); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
339 |
Files.delete(fs3Path); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
340 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
341 |
|
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
342 |
// test file stamp |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
343 |
static void testTime(Path src) throws Exception { |
18150 | 344 |
BasicFileAttributes attrs = Files |
345 |
.getFileAttributeView(src, BasicFileAttributeView.class) |
|
346 |
.readAttributes(); |
|
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
347 |
// create a new filesystem, copy this file into it |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
348 |
Map<String, Object> env = new HashMap<String, Object>(); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
349 |
env.put("create", "true"); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
350 |
Path fsPath = getTempPath(); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
351 |
FileSystem fs = newZipFileSystem(fsPath, env); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
352 |
|
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
353 |
System.out.println("test copy with timestamps..."); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
354 |
// copyin |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
355 |
Path dst = getPathWithParents(fs, "me"); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
356 |
Files.copy(src, dst, COPY_ATTRIBUTES); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
357 |
checkEqual(src, dst); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
358 |
System.out.println("mtime: " + attrs.lastModifiedTime()); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
359 |
System.out.println("ctime: " + attrs.creationTime()); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
360 |
System.out.println("atime: " + attrs.lastAccessTime()); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
361 |
System.out.println(" ==============>"); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
362 |
BasicFileAttributes dstAttrs = Files |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
363 |
.getFileAttributeView(dst, BasicFileAttributeView.class) |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
364 |
.readAttributes(); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
365 |
System.out.println("mtime: " + dstAttrs.lastModifiedTime()); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
366 |
System.out.println("ctime: " + dstAttrs.creationTime()); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
367 |
System.out.println("atime: " + dstAttrs.lastAccessTime()); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
368 |
|
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
369 |
// 1-second granularity |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
370 |
if (attrs.lastModifiedTime().to(TimeUnit.SECONDS) != |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
371 |
dstAttrs.lastModifiedTime().to(TimeUnit.SECONDS) || |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
372 |
attrs.lastAccessTime().to(TimeUnit.SECONDS) != |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
373 |
dstAttrs.lastAccessTime().to(TimeUnit.SECONDS) || |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
374 |
attrs.creationTime().to(TimeUnit.SECONDS) != |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
375 |
dstAttrs.creationTime().to(TimeUnit.SECONDS)) { |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
376 |
throw new RuntimeException("Timestamp Copy Failed!"); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
377 |
} |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
378 |
Files.delete(fsPath); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
379 |
} |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
16857
diff
changeset
|
380 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
381 |
private static FileSystem newZipFileSystem(Path path, Map<String, ?> env) |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
382 |
throws Exception |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
383 |
{ |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
384 |
return FileSystems.newFileSystem( |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
385 |
new URI("jar", path.toUri().toString(), null), env, null); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
386 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
387 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
388 |
private static Path getTempPath() throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
389 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
390 |
File tmp = File.createTempFile("testzipfs_", "zip"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
391 |
tmp.delete(); // we need a clean path, no file |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
392 |
return tmp.toPath(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
393 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
394 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
395 |
private static void list(Path path, List<String> files, List<String> dirs ) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
396 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
397 |
{ |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
398 |
if (Files.isDirectory(path)) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
399 |
try (DirectoryStream<Path> ds = Files.newDirectoryStream(path)) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
400 |
for (Path child : ds) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
401 |
list(child, files, dirs); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
402 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
403 |
dirs.add(path.toString()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
404 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
405 |
files.add(path.toString()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
406 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
407 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
408 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
409 |
private static void z2zcopy(FileSystem src, FileSystem dst, String path, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
410 |
int method) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
411 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
412 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
413 |
Path srcPath = src.getPath(path); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
414 |
Path dstPath = dst.getPath(path); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
415 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
416 |
if (Files.isDirectory(srcPath)) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
417 |
if (!Files.exists(dstPath)) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
418 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
419 |
mkdirs(dstPath); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
420 |
} catch (FileAlreadyExistsException x) {} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
421 |
} |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
422 |
try (DirectoryStream<Path> ds = Files.newDirectoryStream(srcPath)) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
423 |
for (Path child : ds) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
424 |
z2zcopy(src, dst, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
425 |
path + (path.endsWith("/")?"":"/") + child.getFileName(), |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
426 |
method); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
427 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
428 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
429 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
430 |
try { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
431 |
if (Files.exists(dstPath)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
432 |
return; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
433 |
switch (method) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
434 |
case 0: |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
435 |
Files.copy(srcPath, dstPath); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
436 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
437 |
case 1: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
438 |
chCopy(srcPath, dstPath); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
439 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
440 |
case 2: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
441 |
//fchCopy(srcPath, dstPath); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
442 |
streamCopy(srcPath, dstPath); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
443 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
444 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
445 |
} catch (FileAlreadyExistsException x) {} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
446 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
447 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
448 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
449 |
private static void z2zmove(FileSystem src, FileSystem dst, String path) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
450 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
451 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
452 |
Path srcPath = src.getPath(path); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
453 |
Path dstPath = dst.getPath(path); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
454 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
455 |
if (Files.isDirectory(srcPath)) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
456 |
if (!Files.exists(dstPath)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
457 |
mkdirs(dstPath); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
458 |
try (DirectoryStream<Path> ds = Files.newDirectoryStream(srcPath)) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
459 |
for (Path child : ds) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
460 |
z2zmove(src, dst, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
461 |
path + (path.endsWith("/")?"":"/") + child.getFileName()); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
462 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
463 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
464 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
465 |
//System.out.println("moving..." + path); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
466 |
Path parent = dstPath.getParent(); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
467 |
if (parent != null && Files.notExists(parent)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
468 |
mkdirs(parent); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
469 |
Files.move(srcPath, dstPath); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
470 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
471 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
472 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
473 |
private static void walk(Path path) throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
474 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
475 |
Files.walkFileTree( |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
476 |
path, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
477 |
new SimpleFileVisitor<Path>() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
478 |
private int indent = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
479 |
private void indent() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
480 |
int n = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
481 |
while (n++ < indent) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
482 |
System.out.printf(" "); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
483 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
484 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
485 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
486 |
public FileVisitResult visitFile(Path file, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
487 |
BasicFileAttributes attrs) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
488 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
489 |
indent(); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
490 |
System.out.printf("%s%n", file.getFileName().toString()); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
491 |
return FileVisitResult.CONTINUE; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
492 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
493 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
494 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
495 |
public FileVisitResult preVisitDirectory(Path dir, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
496 |
BasicFileAttributes attrs) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
497 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
498 |
indent(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
499 |
System.out.printf("[%s]%n", dir.toString()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
500 |
indent += 2; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
501 |
return FileVisitResult.CONTINUE; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
502 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
503 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
504 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
505 |
public FileVisitResult postVisitDirectory(Path dir, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
506 |
IOException ioe) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
507 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
508 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
509 |
indent -= 2; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
510 |
return FileVisitResult.CONTINUE; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
511 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
512 |
}); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
513 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
514 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
515 |
private static void mkdirs(Path path) throws IOException { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
516 |
if (Files.exists(path)) |
7189 | 517 |
return; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
518 |
path = path.toAbsolutePath(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
519 |
Path parent = path.getParent(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
520 |
if (parent != null) { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
521 |
if (Files.notExists(parent)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
522 |
mkdirs(parent); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
523 |
} |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
524 |
Files.createDirectory(path); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
525 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
526 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
527 |
private static void rmdirs(Path path) throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
528 |
while (path != null && path.getNameCount() != 0) { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
529 |
Files.delete(path); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
530 |
path = path.getParent(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
531 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
532 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
533 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
534 |
// check the content of two paths are equal |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
535 |
private static void checkEqual(Path src, Path dst) throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
536 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
537 |
//System.out.printf("checking <%s> vs <%s>...%n", |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
538 |
// src.toString(), dst.toString()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
539 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
540 |
//streams |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
541 |
byte[] bufSrc = new byte[8192]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
542 |
byte[] bufDst = new byte[8192]; |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
543 |
try (InputStream isSrc = Files.newInputStream(src); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
544 |
InputStream isDst = Files.newInputStream(dst)) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
545 |
{ |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
546 |
int nSrc = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
547 |
while ((nSrc = isSrc.read(bufSrc)) != -1) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
548 |
int nDst = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
549 |
while (nDst < nSrc) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
550 |
int n = isDst.read(bufDst, nDst, nSrc - nDst); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
551 |
if (n == -1) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
552 |
System.out.printf("checking <%s> vs <%s>...%n", |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
553 |
src.toString(), dst.toString()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
554 |
throw new RuntimeException("CHECK FAILED!"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
555 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
556 |
nDst += n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
557 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
558 |
while (--nSrc >= 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
559 |
if (bufSrc[nSrc] != bufDst[nSrc]) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
560 |
System.out.printf("checking <%s> vs <%s>...%n", |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
561 |
src.toString(), dst.toString()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
562 |
throw new RuntimeException("CHECK FAILED!"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
563 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
564 |
nSrc--; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
565 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
566 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
567 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
568 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
569 |
// channels |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
570 |
try (SeekableByteChannel chSrc = Files.newByteChannel(src); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
571 |
SeekableByteChannel chDst = Files.newByteChannel(dst)) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
572 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
573 |
if (chSrc.size() != chDst.size()) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
574 |
System.out.printf("src[%s].size=%d, dst[%s].size=%d%n", |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
575 |
chSrc.toString(), chSrc.size(), |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
576 |
chDst.toString(), chDst.size()); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
577 |
throw new RuntimeException("CHECK FAILED!"); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
578 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
579 |
ByteBuffer bbSrc = ByteBuffer.allocate(8192); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
580 |
ByteBuffer bbDst = ByteBuffer.allocate(8192); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
581 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
582 |
int nSrc = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
583 |
while ((nSrc = chSrc.read(bbSrc)) != -1) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
584 |
int nDst = chDst.read(bbDst); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
585 |
if (nSrc != nDst) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
586 |
System.out.printf("checking <%s> vs <%s>...%n", |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
587 |
src.toString(), dst.toString()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
588 |
throw new RuntimeException("CHECK FAILED!"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
589 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
590 |
while (--nSrc >= 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
591 |
if (bbSrc.get(nSrc) != bbDst.get(nSrc)) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
592 |
System.out.printf("checking <%s> vs <%s>...%n", |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
593 |
src.toString(), dst.toString()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
594 |
throw new RuntimeException("CHECK FAILED!"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
595 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
596 |
nSrc--; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
597 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
598 |
bbSrc.flip(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
599 |
bbDst.flip(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
600 |
} |
12676
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
601 |
|
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
602 |
// Check if source read position is at the end |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
603 |
if (chSrc.position() != chSrc.size()) { |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
604 |
System.out.printf("src[%s]: size=%d, position=%d%n", |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
605 |
chSrc.toString(), chSrc.size(), chSrc.position()); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
606 |
throw new RuntimeException("CHECK FAILED!"); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
607 |
} |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
608 |
|
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
609 |
// Check if destination read position is at the end |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
610 |
if (chDst.position() != chDst.size()) { |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
611 |
System.out.printf("dst[%s]: size=%d, position=%d%n", |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
612 |
chDst.toString(), chDst.size(), chDst.position()); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
613 |
throw new RuntimeException("CHECK FAILED!"); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
614 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
615 |
} catch (IOException x) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
616 |
x.printStackTrace(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
617 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
618 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
619 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
620 |
private static void fchCopy(Path src, Path dst) throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
621 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
622 |
Set<OpenOption> read = new HashSet<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
623 |
read.add(READ); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
624 |
Set<OpenOption> openwrite = new HashSet<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
625 |
openwrite.add(CREATE_NEW); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
626 |
openwrite.add(WRITE); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
627 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
628 |
try (FileChannel srcFc = src.getFileSystem() |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
629 |
.provider() |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
630 |
.newFileChannel(src, read); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
631 |
FileChannel dstFc = dst.getFileSystem() |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
632 |
.provider() |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
633 |
.newFileChannel(dst, openwrite)) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
634 |
{ |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
635 |
ByteBuffer bb = ByteBuffer.allocate(8192); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
636 |
while (srcFc.read(bb) >= 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
637 |
bb.flip(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
638 |
dstFc.write(bb); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
639 |
bb.clear(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
640 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
641 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
642 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
643 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
644 |
private static void chCopy(Path src, Path dst) throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
645 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
646 |
Set<OpenOption> read = new HashSet<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
647 |
read.add(READ); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
648 |
Set<OpenOption> openwrite = new HashSet<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
649 |
openwrite.add(CREATE_NEW); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
650 |
openwrite.add(WRITE); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
651 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
652 |
try (SeekableByteChannel srcCh = Files.newByteChannel(src, read); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
653 |
SeekableByteChannel dstCh = Files.newByteChannel(dst, openwrite)) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
654 |
{ |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
655 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
656 |
ByteBuffer bb = ByteBuffer.allocate(8192); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
657 |
while (srcCh.read(bb) >= 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
658 |
bb.flip(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
659 |
dstCh.write(bb); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
660 |
bb.clear(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
661 |
} |
12676
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
662 |
|
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
663 |
// Check if source read position is at the end |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
664 |
if (srcCh.position() != srcCh.size()) { |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
665 |
System.out.printf("src[%s]: size=%d, position=%d%n", |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
666 |
srcCh.toString(), srcCh.size(), srcCh.position()); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
667 |
throw new RuntimeException("CHECK FAILED!"); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
668 |
} |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
669 |
|
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
670 |
// Check if destination write position is at the end |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
671 |
if (dstCh.position() != dstCh.size()) { |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
672 |
System.out.printf("dst[%s]: size=%d, position=%d%n", |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
673 |
dstCh.toString(), dstCh.size(), dstCh.position()); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
674 |
throw new RuntimeException("CHECK FAILED!"); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
675 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
676 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
677 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
678 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
679 |
private static void streamCopy(Path src, Path dst) throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
680 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
681 |
byte[] buf = new byte[8192]; |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
682 |
try (InputStream isSrc = Files.newInputStream(src); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
683 |
OutputStream osDst = Files.newOutputStream(dst)) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
684 |
{ |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
685 |
int n = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
686 |
while ((n = isSrc.read(buf)) != -1) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
687 |
osDst.write(buf, 0, n); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
688 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
689 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
690 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
691 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
692 |
static void channel(FileSystem fs, Path path) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
693 |
throws Exception |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
694 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
695 |
System.out.println("test ByteChannel..."); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
696 |
Set<OpenOption> read = new HashSet<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
697 |
read.add(READ); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
698 |
int n = 0; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
699 |
ByteBuffer bb = null; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
700 |
ByteBuffer bb2 = null; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
701 |
int N = 120; |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
702 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
703 |
try (SeekableByteChannel sbc = Files.newByteChannel(path)) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
704 |
System.out.printf(" sbc[0]: pos=%d, size=%d%n", sbc.position(), sbc.size()); |
12676
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
705 |
if (sbc.position() != 0) { |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
706 |
throw new RuntimeException("CHECK FAILED!"); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
707 |
} |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
708 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
709 |
bb = ByteBuffer.allocate((int)sbc.size()); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
710 |
n = sbc.read(bb); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
711 |
System.out.printf(" sbc[1]: read=%d, pos=%d, size=%d%n", |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
712 |
n, sbc.position(), sbc.size()); |
12676
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
713 |
if (sbc.position() != sbc.size()) { |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
714 |
throw new RuntimeException("CHECK FAILED!"); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
715 |
} |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
716 |
bb2 = ByteBuffer.allocate((int)sbc.size()); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
717 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
718 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
719 |
// sbc.position(pos) is not supported in current version |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
720 |
// try the FileChannel |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
721 |
try (SeekableByteChannel sbc = fs.provider().newFileChannel(path, read)) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
722 |
sbc.position(N); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
723 |
System.out.printf(" sbc[2]: pos=%d, size=%d%n", |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
724 |
sbc.position(), sbc.size()); |
12676
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
725 |
if (sbc.position() != N) { |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
726 |
throw new RuntimeException("CHECK FAILED!"); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
727 |
} |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
728 |
bb2.limit(100); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
729 |
n = sbc.read(bb2); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
730 |
System.out.printf(" sbc[3]: read=%d, pos=%d, size=%d%n", |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
731 |
n, sbc.position(), sbc.size()); |
12676
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
732 |
if (n < 0 || sbc.position() != (N + n)) { |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
733 |
throw new RuntimeException("CHECK FAILED!"); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
8386
diff
changeset
|
734 |
} |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
735 |
System.out.printf(" sbc[4]: bb[%d]=%d, bb1[0]=%d%n", |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
736 |
N, bb.get(N) & 0xff, bb2.get(0) & 0xff); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
737 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
738 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
739 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
740 |
// create parents if does not exist |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
741 |
static Path getPathWithParents(FileSystem fs, String name) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
742 |
throws Exception |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
743 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
744 |
Path path = fs.getPath(name); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
745 |
Path parent = path.getParent(); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
746 |
if (parent != null && Files.notExists(parent)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
747 |
mkdirs(parent); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
748 |
return path; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
749 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
750 |
} |