author | dholmes |
Mon, 09 Jul 2018 20:17:32 -0400 | |
changeset 51020 | 1835f9fca157 |
parent 47216 | 71c04702a3d5 |
child 53043 | fd2e8f941ded |
permissions | -rw-r--r-- |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1 |
/* |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2 |
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
4 |
* |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
10 |
* |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
15 |
* accompanied this code). |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
16 |
* |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
20 |
* |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
23 |
* questions. |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
24 |
*/ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
25 |
|
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
10292
diff
changeset
|
26 |
package jdk.nio.zipfs; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
27 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
28 |
import java.io.*; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
29 |
import java.net.URI; |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
30 |
import java.nio.channels.*; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
31 |
import java.nio.file.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
32 |
import java.nio.file.DirectoryStream.Filter; |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
33 |
import java.nio.file.attribute.*; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
34 |
import java.util.*; |
32306
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
35 |
import static java.nio.charset.StandardCharsets.UTF_8; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
36 |
import static java.nio.file.StandardOpenOption.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
37 |
import static java.nio.file.StandardCopyOption.*; |
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 |
/** |
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 |
* @author Xueming Shen, Rajendra Gutupalli,Jaya Hangal |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
42 |
*/ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
43 |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
44 |
final class ZipPath implements Path { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
45 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
46 |
private final ZipFileSystem zfs; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
47 |
private final byte[] path; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
48 |
private volatile int[] offsets; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
49 |
private int hashcode = 0; // cached hashcode (created lazily) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
50 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
51 |
ZipPath(ZipFileSystem zfs, byte[] path) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
52 |
this(zfs, path, false); |
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 |
|
38769
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
55 |
ZipPath(ZipFileSystem zfs, byte[] path, boolean normalized) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
56 |
this.zfs = zfs; |
38769
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
57 |
if (normalized) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
58 |
this.path = path; |
38769
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
59 |
} else { |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
60 |
if (zfs.zc.isUTF8()) { |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
61 |
this.path = normalize(path); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
62 |
} else { // see normalize(String); |
38769
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
63 |
this.path = normalize(zfs.getString(path)); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
64 |
} |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
65 |
} |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
66 |
} |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
67 |
|
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
68 |
ZipPath(ZipFileSystem zfs, String path) { |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
69 |
this.zfs = zfs; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
70 |
this.path = normalize(path); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
71 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
72 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
73 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
74 |
public ZipPath getRoot() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
75 |
if (this.isAbsolute()) |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
76 |
return zfs.getRootDir(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
77 |
else |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
78 |
return null; |
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 |
|
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
81 |
@Override |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
82 |
public Path getFileName() { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
83 |
int off = path.length; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
84 |
if (off == 0 || off == 1 && path[0] == '/') |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
85 |
return null; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
86 |
while (--off >= 0 && path[off] != '/') {} |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
87 |
if (off < 0) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
88 |
return this; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
89 |
off++; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
90 |
byte[] result = new byte[path.length - off]; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
91 |
System.arraycopy(path, off, result, 0, result.length); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
92 |
return new ZipPath(getFileSystem(), result, true); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
93 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
94 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
95 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
96 |
public ZipPath getParent() { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
97 |
int off = path.length; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
98 |
if (off == 0 || off == 1 && path[0] == '/') |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
99 |
return null; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
100 |
while (--off >= 0 && path[off] != '/') {} |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
101 |
if (off <= 0) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
102 |
return getRoot(); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
103 |
byte[] result = new byte[off]; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
104 |
System.arraycopy(path, 0, result, 0, off); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
105 |
return new ZipPath(getFileSystem(), result, true); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
106 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
107 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
108 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
109 |
public int getNameCount() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
110 |
initOffsets(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
111 |
return offsets.length; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
112 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
113 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
114 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
115 |
public ZipPath getName(int index) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
116 |
initOffsets(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
117 |
if (index < 0 || index >= offsets.length) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
118 |
throw new IllegalArgumentException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
119 |
int begin = offsets[index]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
120 |
int len; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
121 |
if (index == (offsets.length-1)) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
122 |
len = path.length - begin; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
123 |
else |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
124 |
len = offsets[index+1] - begin - 1; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
125 |
// construct result |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
126 |
byte[] result = new byte[len]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
127 |
System.arraycopy(path, begin, result, 0, len); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
128 |
return new ZipPath(zfs, result); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
129 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
130 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
131 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
132 |
public ZipPath subpath(int beginIndex, int endIndex) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
133 |
initOffsets(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
134 |
if (beginIndex < 0 || |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
135 |
beginIndex >= offsets.length || |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
136 |
endIndex > offsets.length || |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
137 |
beginIndex >= endIndex) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
138 |
throw new IllegalArgumentException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
139 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
140 |
// starting offset and length |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
141 |
int begin = offsets[beginIndex]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
142 |
int len; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
143 |
if (endIndex == offsets.length) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
144 |
len = path.length - begin; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
145 |
else |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
146 |
len = offsets[endIndex] - begin - 1; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
147 |
// construct result |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
148 |
byte[] result = new byte[len]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
149 |
System.arraycopy(path, begin, result, 0, len); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
150 |
return new ZipPath(zfs, result); |
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 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
153 |
@Override |
9025
a72fc1fc4b71
7029979: (fs) Path.toRealPath(boolean) should be toRealPath(LinkOption...)
alanb
parents:
8570
diff
changeset
|
154 |
public ZipPath toRealPath(LinkOption... options) throws IOException { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
155 |
ZipPath realPath; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
156 |
byte[] resolved = getResolvedPath(); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
157 |
// resolved is always absolute and normalized |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
158 |
if (resolved == path) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
159 |
realPath = this; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
160 |
} else { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
161 |
realPath = new ZipPath(zfs, resolved, true); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
162 |
realPath.resolved = resolved; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
163 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
164 |
realPath.checkAccess(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
165 |
return realPath; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
166 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
167 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
168 |
boolean isHidden() { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
169 |
return false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
170 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
171 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
172 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
173 |
public ZipPath toAbsolutePath() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
174 |
if (isAbsolute()) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
175 |
return this; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
176 |
} else { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
177 |
// add '/' before the existing path |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
178 |
byte[] tmp = new byte[path.length + 1]; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
179 |
System.arraycopy(path, 0, tmp, 1, path.length); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
180 |
tmp[0] = '/'; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
181 |
return new ZipPath(zfs, tmp, true); // normalized |
6699
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 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
185 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
186 |
public URI toUri() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
187 |
try { |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
188 |
return new URI("jar", |
32306
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
189 |
decodeUri(zfs.getZipFile().toUri().toString()) + |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
190 |
"!" + |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
191 |
zfs.getString(toAbsolutePath().path), |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
192 |
null); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
193 |
} catch (Exception ex) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
194 |
throw new AssertionError(ex); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
195 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
196 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
197 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
198 |
private boolean equalsNameAt(ZipPath other, int index) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
199 |
int mbegin = offsets[index]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
200 |
int mlen = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
201 |
if (index == (offsets.length-1)) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
202 |
mlen = path.length - mbegin; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
203 |
else |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
204 |
mlen = offsets[index + 1] - mbegin - 1; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
205 |
int obegin = other.offsets[index]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
206 |
int olen = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
207 |
if (index == (other.offsets.length - 1)) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
208 |
olen = other.path.length - obegin; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
209 |
else |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
210 |
olen = other.offsets[index + 1] - obegin - 1; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
211 |
if (mlen != olen) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
212 |
return false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
213 |
int n = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
214 |
while(n < mlen) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
215 |
if (path[mbegin + n] != other.path[obegin + n]) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
216 |
return false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
217 |
n++; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
218 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
219 |
return true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
220 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
221 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
222 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
223 |
public Path relativize(Path other) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
224 |
final ZipPath o = checkPath(other); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
225 |
if (o.equals(this)) |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
226 |
return new ZipPath(zfs, new byte[0], true); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
227 |
if (this.path.length == 0) |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
228 |
return o; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
229 |
if (this.zfs != o.zfs || this.isAbsolute() != o.isAbsolute()) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
230 |
throw new IllegalArgumentException(); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
231 |
if (this.path.length == 1 && this.path[0] == '/') |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
232 |
return new ZipPath(zfs, |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
233 |
Arrays.copyOfRange(o.path, 1, o.path.length), |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
234 |
true); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
235 |
int mc = this.getNameCount(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
236 |
int oc = o.getNameCount(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
237 |
int n = Math.min(mc, oc); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
238 |
int i = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
239 |
while (i < n) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
240 |
if (!equalsNameAt(o, i)) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
241 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
242 |
i++; |
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 |
int dotdots = mc - i; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
245 |
int len = dotdots * 3 - 1; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
246 |
if (i < oc) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
247 |
len += (o.path.length - o.offsets[i] + 1); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
248 |
byte[] result = new byte[len]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
249 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
250 |
int pos = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
251 |
while (dotdots > 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
252 |
result[pos++] = (byte)'.'; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
253 |
result[pos++] = (byte)'.'; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
254 |
if (pos < len) // no tailing slash at the end |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
255 |
result[pos++] = (byte)'/'; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
256 |
dotdots--; |
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 |
if (i < oc) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
259 |
System.arraycopy(o.path, o.offsets[i], |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
260 |
result, pos, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
261 |
o.path.length - o.offsets[i]); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
262 |
return new ZipPath(zfs, result); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
263 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
264 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
265 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
266 |
public ZipFileSystem getFileSystem() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
267 |
return zfs; |
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 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
271 |
public boolean isAbsolute() { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
272 |
return path.length > 0 && path[0] == '/'; |
6699
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 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
275 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
276 |
public ZipPath resolve(Path other) { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
277 |
ZipPath o = checkPath(other); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
278 |
if (o.path.length == 0) |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
279 |
return this; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
280 |
if (o.isAbsolute() || this.path.length == 0) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
281 |
return o; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
282 |
return resolve(o.path); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
283 |
} |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
284 |
|
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
285 |
// opath is normalized, just concat |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
286 |
private ZipPath resolve(byte[] opath) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
287 |
byte[] resolved = null; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
288 |
byte[] tpath = this.path; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
289 |
int tlen = tpath.length; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
290 |
int olen = opath.length; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
291 |
if (path[tlen - 1] == '/') { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
292 |
resolved = new byte[tlen + olen]; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
293 |
System.arraycopy(tpath, 0, resolved, 0, tlen); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
294 |
System.arraycopy(opath, 0, resolved, tlen, olen); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
295 |
} else { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
296 |
resolved = new byte[tlen + 1 + olen]; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
297 |
System.arraycopy(tpath, 0, resolved, 0, tlen); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
298 |
resolved[tlen] = '/'; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
299 |
System.arraycopy(opath, 0, resolved, tlen + 1, olen); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
300 |
} |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
301 |
return new ZipPath(zfs, resolved, true); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
302 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
303 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
304 |
@Override |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
305 |
public Path resolveSibling(Path other) { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
306 |
Objects.requireNonNull(other, "other"); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
307 |
Path parent = getParent(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
308 |
return (parent == null) ? other : parent.resolve(other); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
309 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
310 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
311 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
312 |
public boolean startsWith(Path other) { |
46901
f63587417ae6
8186142: ZipPath.{starts,ends}With(nonZipPath) throws an exception, but should return false
sherman
parents:
43193
diff
changeset
|
313 |
Objects.requireNonNull(other, "other"); |
f63587417ae6
8186142: ZipPath.{starts,ends}With(nonZipPath) throws an exception, but should return false
sherman
parents:
43193
diff
changeset
|
314 |
if (!(other instanceof ZipPath)) |
f63587417ae6
8186142: ZipPath.{starts,ends}With(nonZipPath) throws an exception, but should return false
sherman
parents:
43193
diff
changeset
|
315 |
return false; |
f63587417ae6
8186142: ZipPath.{starts,ends}With(nonZipPath) throws an exception, but should return false
sherman
parents:
43193
diff
changeset
|
316 |
final ZipPath o = (ZipPath)other; |
8180
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
317 |
if (o.isAbsolute() != this.isAbsolute() || |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
318 |
o.path.length > this.path.length) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
319 |
return false; |
8180
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
320 |
int olast = o.path.length; |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
321 |
for (int i = 0; i < olast; i++) { |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
322 |
if (o.path[i] != this.path[i]) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
323 |
return false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
324 |
} |
8180
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
325 |
olast--; |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
326 |
return o.path.length == this.path.length || |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
327 |
o.path[olast] == '/' || |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
328 |
this.path[olast + 1] == '/'; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
329 |
} |
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 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
332 |
public boolean endsWith(Path other) { |
46901
f63587417ae6
8186142: ZipPath.{starts,ends}With(nonZipPath) throws an exception, but should return false
sherman
parents:
43193
diff
changeset
|
333 |
Objects.requireNonNull(other, "other"); |
f63587417ae6
8186142: ZipPath.{starts,ends}With(nonZipPath) throws an exception, but should return false
sherman
parents:
43193
diff
changeset
|
334 |
if (!(other instanceof ZipPath)) |
f63587417ae6
8186142: ZipPath.{starts,ends}With(nonZipPath) throws an exception, but should return false
sherman
parents:
43193
diff
changeset
|
335 |
return false; |
f63587417ae6
8186142: ZipPath.{starts,ends}With(nonZipPath) throws an exception, but should return false
sherman
parents:
43193
diff
changeset
|
336 |
final ZipPath o = (ZipPath)other; |
8180
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
337 |
int olast = o.path.length - 1; |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
338 |
if (olast > 0 && o.path[olast] == '/') |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
339 |
olast--; |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
340 |
int last = this.path.length - 1; |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
341 |
if (last > 0 && this.path[last] == '/') |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
342 |
last--; |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
343 |
if (olast == -1) // o.path.length == 0 |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
344 |
return last == -1; |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
345 |
if ((o.isAbsolute() &&(!this.isAbsolute() || olast != last)) || |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
346 |
(last < olast)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
347 |
return false; |
8180
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
348 |
for (; olast >= 0; olast--, last--) { |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
349 |
if (o.path[olast] != this.path[last]) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
350 |
return false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
351 |
} |
8180
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
352 |
return o.path[olast + 1] == '/' || |
ac21bc160e79
7005986: (zipfs) ZipPath.startsWith() fails because of the implementation of getName(index)
sherman
parents:
8165
diff
changeset
|
353 |
last == -1 || this.path[last] == '/'; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
354 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
355 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
356 |
@Override |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
357 |
public ZipPath resolve(String other) { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
358 |
byte[] opath = normalize(other); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
359 |
if (opath.length == 0) |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
360 |
return this; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
361 |
if (opath[0] == '/' || this.path.length == 0) |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
362 |
return new ZipPath(zfs, opath, true); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
363 |
return resolve(opath); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
364 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
365 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
366 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
367 |
public final Path resolveSibling(String other) { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
368 |
return resolveSibling(zfs.getPath(other)); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
369 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
370 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
371 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
372 |
public final boolean startsWith(String other) { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
373 |
return startsWith(zfs.getPath(other)); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
374 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
375 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
376 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
377 |
public final boolean endsWith(String other) { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
378 |
return endsWith(zfs.getPath(other)); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
379 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
380 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
381 |
@Override |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
382 |
public Path normalize() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
383 |
byte[] resolved = getResolved(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
384 |
if (resolved == path) // no change |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
385 |
return this; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
386 |
return new ZipPath(zfs, resolved, true); |
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 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
389 |
private ZipPath checkPath(Path path) { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
390 |
Objects.requireNonNull(path, "path"); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
391 |
if (!(path instanceof ZipPath)) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
392 |
throw new ProviderMismatchException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
393 |
return (ZipPath) path; |
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 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
396 |
// create offset list if not already created |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
397 |
private void initOffsets() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
398 |
if (offsets == null) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
399 |
int count, index; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
400 |
// count names |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
401 |
count = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
402 |
index = 0; |
38568
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
403 |
if (path.length == 0) { |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
404 |
// empty path has one name |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
405 |
count = 1; |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
406 |
} else { |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
407 |
while (index < path.length) { |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
408 |
byte c = path[index++]; |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
409 |
if (c != '/') { |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
410 |
count++; |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
411 |
while (index < path.length && path[index] != '/') |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
412 |
index++; |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
413 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
414 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
415 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
416 |
// populate offsets |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
417 |
int[] result = new int[count]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
418 |
count = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
419 |
index = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
420 |
while (index < path.length) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
421 |
byte c = path[index]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
422 |
if (c == '/') { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
423 |
index++; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
424 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
425 |
result[count++] = index++; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
426 |
while (index < path.length && path[index] != '/') |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
427 |
index++; |
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 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
430 |
synchronized (this) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
431 |
if (offsets == null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
432 |
offsets = result; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
433 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
434 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
435 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
436 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
437 |
// resolved path for locating zip entry inside the zip file, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
438 |
// the result path does not contain ./ and .. components |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
439 |
private volatile byte[] resolved = null; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
440 |
byte[] getResolvedPath() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
441 |
byte[] r = resolved; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
442 |
if (r == null) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
443 |
if (isAbsolute()) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
444 |
r = getResolved(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
445 |
else |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
446 |
r = toAbsolutePath().getResolvedPath(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
447 |
resolved = r; |
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 |
return resolved; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
450 |
} |
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 |
// removes redundant slashs, replace "\" to zip separator "/" |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
453 |
// and check for invalid characters |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
454 |
private byte[] normalize(byte[] path) { |
38568
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
455 |
int len = path.length; |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
456 |
if (len == 0) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
457 |
return path; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
458 |
byte prevC = 0; |
38568
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
459 |
for (int i = 0; i < len; i++) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
460 |
byte c = path[i]; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
461 |
if (c == '\\' || c == '\u0000') |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
462 |
return normalize(path, i); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
463 |
if (c == (byte)'/' && prevC == '/') |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
464 |
return normalize(path, i - 1); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
465 |
prevC = c; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
466 |
} |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
467 |
if (len > 1 && prevC == '/') { |
38568
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
468 |
return Arrays.copyOf(path, len - 1); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
469 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
470 |
return path; |
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 byte[] normalize(byte[] path, int off) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
474 |
byte[] to = new byte[path.length]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
475 |
int n = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
476 |
while (n < off) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
477 |
to[n] = path[n]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
478 |
n++; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
479 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
480 |
int m = n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
481 |
byte prevC = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
482 |
while (n < path.length) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
483 |
byte c = path[n++]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
484 |
if (c == (byte)'\\') |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
485 |
c = (byte)'/'; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
486 |
if (c == (byte)'/' && prevC == (byte)'/') |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
487 |
continue; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
488 |
if (c == '\u0000') |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
489 |
throw new InvalidPathException(zfs.getString(path), |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
490 |
"Path: nul character not allowed"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
491 |
to[m++] = c; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
492 |
prevC = c; |
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 |
if (m > 1 && to[m - 1] == '/') |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
495 |
m--; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
496 |
return (m == to.length)? to : Arrays.copyOf(to, m); |
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 |
|
38769
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
499 |
// if zfs is NOT in utf8, normalize the path as "String" |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
500 |
// to avoid incorrectly normalizing byte '0x5c' (as '\') |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
501 |
// to '/'. |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
502 |
private byte[] normalize(String path) { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
503 |
if (zfs.zc.isUTF8()) |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
504 |
return normalize(zfs.getBytes(path)); |
38769
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
505 |
int len = path.length(); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
506 |
if (len == 0) |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
507 |
return new byte[0]; |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
508 |
char prevC = 0; |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
509 |
for (int i = 0; i < len; i++) { |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
510 |
char c = path.charAt(i); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
511 |
if (c == '\\' || c == '\u0000') |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
512 |
return normalize(path, i, len); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
513 |
if (c == '/' && prevC == '/') |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
514 |
return normalize(path, i - 1, len); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
515 |
prevC = c; |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
516 |
} |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
517 |
if (len > 1 && prevC == '/') |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
518 |
path = path.substring(0, len - 1); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
519 |
return zfs.getBytes(path); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
520 |
} |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
521 |
|
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
522 |
private byte[] normalize(String path, int off, int len) { |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
523 |
StringBuilder to = new StringBuilder(len); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
524 |
to.append(path, 0, off); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
525 |
int m = off; |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
526 |
char prevC = 0; |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
527 |
while (off < len) { |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
528 |
char c = path.charAt(off++); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
529 |
if (c == '\\') |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
530 |
c = '/'; |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
531 |
if (c == '/' && prevC == '/') |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
532 |
continue; |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
533 |
if (c == '\u0000') |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
534 |
throw new InvalidPathException(path, |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
535 |
"Path: nul character not allowed"); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
536 |
to.append(c); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
537 |
prevC = c; |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
538 |
} |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
539 |
len = to.length(); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
540 |
if (len > 1 && prevC == '/') |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
541 |
to.delete(len -1, len); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
542 |
return zfs.getBytes(to.toString()); |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
543 |
} |
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
38568
diff
changeset
|
544 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
545 |
// Remove DotSlash(./) and resolve DotDot (..) components |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
546 |
private byte[] getResolved() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
547 |
for (int i = 0; i < path.length; i++) { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
548 |
if (path[i] == (byte)'.' && |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
549 |
(i + 1 == path.length || path[i + 1] == '/')) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
550 |
return resolve0(); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
551 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
552 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
553 |
return path; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
554 |
} |
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 |
// TBD: performance, avoid initOffsets |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
557 |
private byte[] resolve0() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
558 |
byte[] to = new byte[path.length]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
559 |
int nc = getNameCount(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
560 |
int[] lastM = new int[nc]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
561 |
int lastMOff = -1; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
562 |
int m = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
563 |
for (int i = 0; i < nc; i++) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
564 |
int n = offsets[i]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
565 |
int len = (i == offsets.length - 1)? |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
566 |
(path.length - n):(offsets[i + 1] - n - 1); |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
567 |
if (len == 1 && path[n] == (byte)'.') { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
568 |
if (m == 0 && path[0] == '/') // absolute path |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
569 |
to[m++] = '/'; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
570 |
continue; |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
571 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
572 |
if (len == 2 && path[n] == '.' && path[n + 1] == '.') { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
573 |
if (lastMOff >= 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
574 |
m = lastM[lastMOff--]; // retreat |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
575 |
continue; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
576 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
577 |
if (path[0] == '/') { // "/../xyz" skip |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
578 |
if (m == 0) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
579 |
to[m++] = '/'; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
580 |
} else { // "../xyz" -> "../xyz" |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
581 |
if (m != 0 && to[m-1] != '/') |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
582 |
to[m++] = '/'; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
583 |
while (len-- > 0) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
584 |
to[m++] = path[n++]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
585 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
586 |
continue; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
587 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
588 |
if (m == 0 && path[0] == '/' || // absolute path |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
589 |
m != 0 && to[m-1] != '/') { // not the first name |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
590 |
to[m++] = '/'; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
591 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
592 |
lastM[++lastMOff] = m; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
593 |
while (len-- > 0) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
594 |
to[m++] = path[n++]; |
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 |
if (m > 1 && to[m - 1] == '/') |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
597 |
m--; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
598 |
return (m == to.length)? to : Arrays.copyOf(to, m); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
599 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
600 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
601 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
602 |
public String toString() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
603 |
return zfs.getString(path); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
604 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
605 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
606 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
607 |
public int hashCode() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
608 |
int h = hashcode; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
609 |
if (h == 0) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
610 |
hashcode = h = Arrays.hashCode(path); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
611 |
return h; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
612 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
613 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
614 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
615 |
public boolean equals(Object obj) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
616 |
return obj != null && |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
617 |
obj instanceof ZipPath && |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
618 |
this.zfs == ((ZipPath)obj).zfs && |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
619 |
compareTo((Path) obj) == 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
620 |
} |
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 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
623 |
public int compareTo(Path other) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
624 |
final ZipPath o = checkPath(other); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
625 |
int len1 = this.path.length; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
626 |
int len2 = o.path.length; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
627 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
628 |
int n = Math.min(len1, len2); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
629 |
byte v1[] = this.path; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
630 |
byte v2[] = o.path; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
631 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
632 |
int k = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
633 |
while (k < n) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
634 |
int c1 = v1[k] & 0xff; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
635 |
int c2 = v2[k] & 0xff; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
636 |
if (c1 != c2) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
637 |
return c1 - c2; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
638 |
k++; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
639 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
640 |
return len1 - len2; |
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 |
public WatchKey register( |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
644 |
WatchService watcher, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
645 |
WatchEvent.Kind<?>[] events, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
646 |
WatchEvent.Modifier... modifiers) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
647 |
if (watcher == null || events == null || modifiers == null) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
648 |
throw new NullPointerException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
649 |
} |
38568
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
650 |
// watcher must be associated with a different provider |
f992c34c85b3
8147539: (zipfs) ZipPath should throw ProviderMismatchException when invoking register()
sherman
parents:
37803
diff
changeset
|
651 |
throw new ProviderMismatchException(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
652 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
653 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
654 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
655 |
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
656 |
return register(watcher, events, new WatchEvent.Modifier[0]); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
657 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
658 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
659 |
@Override |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
660 |
public final File toFile() { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
661 |
throw new UnsupportedOperationException(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
662 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
663 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
664 |
@Override |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
665 |
public Iterator<Path> iterator() { |
8570
c9767adab3d2
7023963: (misc) fix diamond anon instances in the jdk
ksrini
parents:
8180
diff
changeset
|
666 |
return new Iterator<Path>() { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
667 |
private int i = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
668 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
669 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
670 |
public boolean hasNext() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
671 |
return (i < getNameCount()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
672 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
673 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
674 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
675 |
public Path next() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
676 |
if (i < getNameCount()) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
677 |
Path result = getName(i); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
678 |
i++; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
679 |
return result; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
680 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
681 |
throw new NoSuchElementException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
682 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
683 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
684 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
685 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
686 |
public void remove() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
687 |
throw new ReadOnlyFileSystemException(); |
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 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
692 |
///////////////////////////////////////////////////////////////////// |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
693 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
694 |
void createDirectory(FileAttribute<?>... attrs) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
695 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
696 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
697 |
zfs.createDirectory(getResolvedPath(), attrs); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
698 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
699 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
700 |
InputStream newInputStream(OpenOption... options) throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
701 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
702 |
if (options.length > 0) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
703 |
for (OpenOption opt : options) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
704 |
if (opt != READ) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
705 |
throw new UnsupportedOperationException("'" + opt + "' not allowed"); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
706 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
707 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
708 |
return zfs.newInputStream(getResolvedPath()); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
709 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
710 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
711 |
DirectoryStream<Path> newDirectoryStream(Filter<? super Path> filter) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
712 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
713 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
714 |
return new ZipDirectoryStream(this, filter); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
715 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
716 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
717 |
void delete() throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
718 |
zfs.deleteFile(getResolvedPath(), true); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
719 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
720 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
721 |
void deleteIfExists() throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
722 |
zfs.deleteFile(getResolvedPath(), false); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
723 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
724 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
725 |
ZipFileAttributes getAttributes() throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
726 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
727 |
ZipFileAttributes zfas = zfs.getFileAttributes(getResolvedPath()); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
728 |
if (zfas == null) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
729 |
throw new NoSuchFileException(toString()); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
730 |
return zfas; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
731 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
732 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
733 |
void setAttribute(String attribute, Object value, LinkOption... options) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
734 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
735 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
736 |
String type = null; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
737 |
String attr = null; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
738 |
int colonPos = attribute.indexOf(':'); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
739 |
if (colonPos == -1) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
740 |
type = "basic"; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
741 |
attr = attribute; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
742 |
} else { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
743 |
type = attribute.substring(0, colonPos++); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
744 |
attr = attribute.substring(colonPos); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
745 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
746 |
ZipFileAttributeView view = ZipFileAttributeView.get(this, type); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
747 |
if (view == null) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
748 |
throw new UnsupportedOperationException("view <" + view + "> is not supported"); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
749 |
view.setAttribute(attr, value); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
750 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
751 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
752 |
void setTimes(FileTime mtime, FileTime atime, FileTime ctime) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
753 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
754 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
755 |
zfs.setTimes(getResolvedPath(), mtime, atime, ctime); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
756 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
757 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
758 |
Map<String, Object> readAttributes(String attributes, LinkOption... options) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
759 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
760 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
761 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
762 |
String view = null; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
763 |
String attrs = null; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
764 |
int colonPos = attributes.indexOf(':'); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
765 |
if (colonPos == -1) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
766 |
view = "basic"; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
767 |
attrs = attributes; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
768 |
} else { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
769 |
view = attributes.substring(0, colonPos++); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
770 |
attrs = attributes.substring(colonPos); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
771 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
772 |
ZipFileAttributeView zfv = ZipFileAttributeView.get(this, view); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
773 |
if (zfv == null) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
774 |
throw new UnsupportedOperationException("view not supported"); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
775 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
776 |
return zfv.readAttributes(attrs); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
777 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
778 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
779 |
FileStore getFileStore() throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
780 |
// each ZipFileSystem only has one root (as requested for now) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
781 |
if (exists()) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
782 |
return zfs.getFileStore(this); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
783 |
throw new NoSuchFileException(zfs.getString(path)); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
784 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
785 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
786 |
boolean isSameFile(Path other) throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
787 |
if (this.equals(other)) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
788 |
return true; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
789 |
if (other == null || |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
790 |
this.getFileSystem() != other.getFileSystem()) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
791 |
return false; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
792 |
this.checkAccess(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
793 |
((ZipPath)other).checkAccess(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
794 |
return Arrays.equals(this.getResolvedPath(), |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
795 |
((ZipPath)other).getResolvedPath()); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
796 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
797 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
798 |
SeekableByteChannel newByteChannel(Set<? extends OpenOption> options, |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
799 |
FileAttribute<?>... attrs) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
800 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
801 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
802 |
return zfs.newByteChannel(getResolvedPath(), options, attrs); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
803 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
804 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
805 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
806 |
FileChannel newFileChannel(Set<? extends OpenOption> options, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
807 |
FileAttribute<?>... attrs) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
808 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
809 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
810 |
return zfs.newFileChannel(getResolvedPath(), options, attrs); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
811 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
812 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
813 |
void checkAccess(AccessMode... modes) throws IOException { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
814 |
boolean w = false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
815 |
boolean x = false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
816 |
for (AccessMode mode : modes) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
817 |
switch (mode) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
818 |
case READ: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
819 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
820 |
case WRITE: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
821 |
w = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
822 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
823 |
case EXECUTE: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
824 |
x = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
825 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
826 |
default: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
827 |
throw new UnsupportedOperationException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
828 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
829 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
830 |
zfs.checkAccess(getResolvedPath()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
831 |
if ((w && zfs.isReadOnly()) || x) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
32306
diff
changeset
|
832 |
throw new AccessDeniedException(toString()); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
833 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
834 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
835 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
836 |
boolean exists() { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
837 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
838 |
return zfs.exists(getResolvedPath()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
839 |
} catch (IOException x) {} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
840 |
return false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
841 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
842 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
843 |
OutputStream newOutputStream(OpenOption... options) throws IOException |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
844 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
845 |
if (options.length == 0) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
846 |
return zfs.newOutputStream(getResolvedPath(), |
30811
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
25859
diff
changeset
|
847 |
CREATE, TRUNCATE_EXISTING, WRITE); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
848 |
return zfs.newOutputStream(getResolvedPath(), options); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
849 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
850 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
851 |
void move(ZipPath target, CopyOption... options) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
852 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
853 |
{ |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
854 |
if (Files.isSameFile(this.zfs.getZipFile(), target.zfs.getZipFile())) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
855 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
856 |
zfs.copyFile(true, |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
857 |
getResolvedPath(), target.getResolvedPath(), |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
858 |
options); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
859 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
860 |
copyToTarget(target, options); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
861 |
delete(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
862 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
863 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
864 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
865 |
void copy(ZipPath target, CopyOption... options) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
866 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
867 |
{ |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
868 |
if (Files.isSameFile(this.zfs.getZipFile(), target.zfs.getZipFile())) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
869 |
zfs.copyFile(false, |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
870 |
getResolvedPath(), target.getResolvedPath(), |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
871 |
options); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
872 |
else |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
873 |
copyToTarget(target, options); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
874 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
875 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
876 |
private void copyToTarget(ZipPath target, CopyOption... options) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
877 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
878 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
879 |
boolean replaceExisting = false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
880 |
boolean copyAttrs = false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
881 |
for (CopyOption opt : options) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
882 |
if (opt == REPLACE_EXISTING) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
883 |
replaceExisting = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
884 |
else if (opt == COPY_ATTRIBUTES) |
7189 | 885 |
copyAttrs = true; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
886 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
887 |
// attributes of source file |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
888 |
ZipFileAttributes zfas = getAttributes(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
889 |
// check if target exists |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
890 |
boolean exists; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
891 |
if (replaceExisting) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
892 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
893 |
target.deleteIfExists(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
894 |
exists = false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
895 |
} catch (DirectoryNotEmptyException x) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
896 |
exists = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
897 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
898 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
899 |
exists = target.exists(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
900 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
901 |
if (exists) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
902 |
throw new FileAlreadyExistsException(target.toString()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
903 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
904 |
if (zfas.isDirectory()) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
905 |
// create directory or file |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
906 |
target.createDirectory(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
907 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
908 |
InputStream is = zfs.newInputStream(getResolvedPath()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
909 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
910 |
OutputStream os = target.newOutputStream(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
911 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
912 |
byte[] buf = new byte[8192]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
913 |
int n = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
914 |
while ((n = is.read(buf)) != -1) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
915 |
os.write(buf, 0, n); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
916 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
917 |
} finally { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
918 |
os.close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
919 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
920 |
} finally { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
921 |
is.close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
922 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
923 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
924 |
if (copyAttrs) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
925 |
BasicFileAttributeView view = |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
926 |
ZipFileAttributeView.get(target, BasicFileAttributeView.class); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
927 |
try { |
7189 | 928 |
view.setTimes(zfas.lastModifiedTime(), |
929 |
zfas.lastAccessTime(), |
|
930 |
zfas.creationTime()); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
931 |
} catch (IOException x) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
932 |
// rollback? |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
933 |
try { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
934 |
target.delete(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
935 |
} catch (IOException ignore) { } |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
936 |
throw x; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
937 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
938 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
939 |
} |
32306
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
940 |
|
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
941 |
private static int decode(char c) { |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
942 |
if ((c >= '0') && (c <= '9')) |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
943 |
return c - '0'; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
944 |
if ((c >= 'a') && (c <= 'f')) |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
945 |
return c - 'a' + 10; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
946 |
if ((c >= 'A') && (c <= 'F')) |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
947 |
return c - 'A' + 10; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
948 |
assert false; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
949 |
return -1; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
950 |
} |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
951 |
|
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
952 |
// to avoid double escape |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
953 |
static String decodeUri(String s) { |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
954 |
if (s == null) |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
955 |
return s; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
956 |
int n = s.length(); |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
957 |
if (n == 0) |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
958 |
return s; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
959 |
if (s.indexOf('%') < 0) |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
960 |
return s; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
961 |
|
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
962 |
StringBuilder sb = new StringBuilder(n); |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
963 |
byte[] bb = new byte[n]; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
964 |
boolean betweenBrackets = false; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
965 |
|
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
966 |
for (int i = 0; i < n;) { |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
967 |
char c = s.charAt(i); |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
968 |
if (c == '[') { |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
969 |
betweenBrackets = true; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
970 |
} else if (betweenBrackets && c == ']') { |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
971 |
betweenBrackets = false; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
972 |
} |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
973 |
if (c != '%' || betweenBrackets ) { |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
974 |
sb.append(c); |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
975 |
i++; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
976 |
continue; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
977 |
} |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
978 |
int nb = 0; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
979 |
while (c == '%') { |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
980 |
assert (n - i >= 2); |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
981 |
bb[nb++] = (byte)(((decode(s.charAt(++i)) & 0xf) << 4) | |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
982 |
(decode(s.charAt(++i)) & 0xf)); |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
983 |
if (++i >= n) { |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
984 |
break; |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
985 |
} |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
986 |
c = s.charAt(i); |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
987 |
} |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
988 |
sb.append(new String(bb, 0, nb, UTF_8)); |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
989 |
} |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
990 |
return sb.toString(); |
d08fa5944065
8131067: (zipfs) Zip File System Provider returns doubly-encoded Path URIs
sherman
parents:
30811
diff
changeset
|
991 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
992 |
} |