author | chegar |
Fri, 02 Mar 2018 10:18:48 +0000 | |
branch | http-client-branch |
changeset 56225 | 348ae78efb60 |
parent 47223 | 723486922bfe |
child 50238 | a9307f400f5a |
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
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:
23010
diff
changeset
|
20 |
* |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
23010
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:
23010
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:
23010
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:
23010
diff
changeset
|
26 |
package jdk.nio.zipfs; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
27 |
|
10365
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
28 |
import java.io.BufferedOutputStream; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
29 |
import java.io.ByteArrayInputStream; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
30 |
import java.io.ByteArrayOutputStream; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
31 |
import java.io.EOFException; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
32 |
import java.io.File; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
33 |
import java.io.IOException; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
34 |
import java.io.InputStream; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
35 |
import java.io.OutputStream; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
36 |
import java.nio.ByteBuffer; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
37 |
import java.nio.MappedByteBuffer; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
38 |
import java.nio.channels.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
39 |
import java.nio.file.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
40 |
import java.nio.file.attribute.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
41 |
import java.nio.file.spi.*; |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
23010
diff
changeset
|
42 |
import java.security.AccessController; |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
23010
diff
changeset
|
43 |
import java.security.PrivilegedAction; |
24364
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
44 |
import java.security.PrivilegedActionException; |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
45 |
import java.security.PrivilegedExceptionAction; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
46 |
import java.util.*; |
7189 | 47 |
import java.util.concurrent.locks.ReadWriteLock; |
48 |
import java.util.concurrent.locks.ReentrantReadWriteLock; |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
49 |
import java.util.regex.Pattern; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
50 |
import java.util.zip.CRC32; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
51 |
import java.util.zip.Inflater; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
52 |
import java.util.zip.Deflater; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
53 |
import java.util.zip.InflaterInputStream; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
54 |
import java.util.zip.DeflaterOutputStream; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
55 |
import java.util.zip.ZipException; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
56 |
import static java.lang.Boolean.*; |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
23010
diff
changeset
|
57 |
import static jdk.nio.zipfs.ZipConstants.*; |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
23010
diff
changeset
|
58 |
import static jdk.nio.zipfs.ZipUtils.*; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
59 |
import static java.nio.file.StandardOpenOption.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
60 |
import static java.nio.file.StandardCopyOption.*; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
61 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
62 |
/** |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
63 |
* A FileSystem built on a zip file |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
64 |
* |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
65 |
* @author Xueming Shen |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
66 |
*/ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
67 |
|
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
23010
diff
changeset
|
68 |
class ZipFileSystem extends FileSystem { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
69 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
70 |
private final ZipFileSystemProvider provider; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
71 |
private final Path zfpath; |
38769
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
37803
diff
changeset
|
72 |
final ZipCoder zc; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
73 |
private final boolean noExtt; // see readExtra() |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
74 |
private final ZipPath rootdir; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
75 |
// configurable by env map |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
76 |
private final boolean useTempFile; // use a temp file for newOS, default |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
77 |
// is to use BAOS for better performance |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
78 |
private boolean readOnly = false; // readonly file system |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
23010
diff
changeset
|
79 |
private static final boolean isWindows = AccessController.doPrivileged( |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
23010
diff
changeset
|
80 |
(PrivilegedAction<Boolean>) () -> System.getProperty("os.name") |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
23010
diff
changeset
|
81 |
.startsWith("Windows")); |
47223
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
82 |
private final boolean forceEnd64; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
83 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
84 |
ZipFileSystem(ZipFileSystemProvider provider, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
85 |
Path zfpath, |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
86 |
Map<String, ?> env) throws IOException |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
87 |
{ |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
88 |
// create a new zip if not exists |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
89 |
boolean createNew = "true".equals(env.get("create")); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
90 |
// default encoding for name/comment |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
91 |
String nameEncoding = env.containsKey("encoding") ? |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
92 |
(String)env.get("encoding") : "UTF-8"; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
93 |
this.noExtt = "false".equals(env.get("zipinfo-time")); |
7189 | 94 |
this.useTempFile = TRUE.equals(env.get("useTempFile")); |
47223
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
95 |
this.forceEnd64 = "true".equals(env.get("forceZIP64End")); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
96 |
this.provider = provider; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
97 |
this.zfpath = zfpath; |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
98 |
if (Files.notExists(zfpath)) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
99 |
if (createNew) { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
100 |
try (OutputStream os = Files.newOutputStream(zfpath, CREATE_NEW, WRITE)) { |
47223
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
101 |
new END().write(os, 0, forceEnd64); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
102 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
103 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
104 |
throw new FileSystemNotFoundException(zfpath.toString()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
105 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
106 |
} |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
107 |
// sm and existence check |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
108 |
zfpath.getFileSystem().provider().checkAccess(zfpath, AccessMode.READ); |
24364
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
109 |
boolean writeable = AccessController.doPrivileged( |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
110 |
(PrivilegedAction<Boolean>) () -> Files.isWritable(zfpath)); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
111 |
this.readOnly = !writeable; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
112 |
this.zc = ZipCoder.get(nameEncoding); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
113 |
this.rootdir = new ZipPath(this, new byte[]{'/'}); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
114 |
this.ch = Files.newByteChannel(zfpath, READ); |
28562
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
115 |
try { |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
116 |
this.cen = initCEN(); |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
117 |
} catch (IOException x) { |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
118 |
try { |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
119 |
this.ch.close(); |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
120 |
} catch (IOException xx) { |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
121 |
x.addSuppressed(xx); |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
122 |
} |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
123 |
throw x; |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
124 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
125 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
126 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
127 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
128 |
public FileSystemProvider provider() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
129 |
return provider; |
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 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
132 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
133 |
public String getSeparator() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
134 |
return "/"; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
135 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
136 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
137 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
138 |
public boolean isOpen() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
139 |
return isOpen; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
140 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
141 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
142 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
143 |
public boolean isReadOnly() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
144 |
return readOnly; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
145 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
146 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
147 |
private void checkWritable() throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
148 |
if (readOnly) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
149 |
throw new ReadOnlyFileSystemException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
150 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
151 |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
152 |
void setReadOnly() { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
153 |
this.readOnly = true; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
154 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
155 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
156 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
157 |
public Iterable<Path> getRootDirectories() { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
158 |
return List.of(rootdir); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
159 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
160 |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
161 |
ZipPath getRootDir() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
162 |
return rootdir; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
163 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
164 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
165 |
@Override |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
166 |
public ZipPath getPath(String first, String... more) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
167 |
if (more.length == 0) { |
38769
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
37803
diff
changeset
|
168 |
return new ZipPath(this, first); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
169 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
170 |
StringBuilder sb = new StringBuilder(); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
171 |
sb.append(first); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
172 |
for (String path : more) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
173 |
if (path.length() > 0) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
174 |
if (sb.length() > 0) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
175 |
sb.append('/'); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
176 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
177 |
sb.append(path); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
178 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
179 |
} |
38769
8046caf79f1c
8061777: (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
sherman
parents:
37803
diff
changeset
|
180 |
return new ZipPath(this, sb.toString()); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
181 |
} |
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 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
184 |
public UserPrincipalLookupService getUserPrincipalLookupService() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
185 |
throw new UnsupportedOperationException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
186 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
187 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
188 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
189 |
public WatchService newWatchService() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
190 |
throw new UnsupportedOperationException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
191 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
192 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
193 |
FileStore getFileStore(ZipPath path) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
194 |
return new ZipFileStore(path); |
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 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
198 |
public Iterable<FileStore> getFileStores() { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
199 |
return List.of(new ZipFileStore(rootdir)); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
200 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
201 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
202 |
private static final Set<String> supportedFileAttributeViews = |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
203 |
Set.of("basic", "zip"); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
204 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
205 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
206 |
public Set<String> supportedFileAttributeViews() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
207 |
return supportedFileAttributeViews; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
208 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
209 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
210 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
211 |
public String toString() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
212 |
return zfpath.toString(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
213 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
214 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
215 |
Path getZipFile() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
216 |
return zfpath; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
217 |
} |
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 |
private static final String GLOB_SYNTAX = "glob"; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
220 |
private static final String REGEX_SYNTAX = "regex"; |
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 PathMatcher getPathMatcher(String syntaxAndInput) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
224 |
int pos = syntaxAndInput.indexOf(':'); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
225 |
if (pos <= 0 || pos == syntaxAndInput.length()) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
226 |
throw new IllegalArgumentException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
227 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
228 |
String syntax = syntaxAndInput.substring(0, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
229 |
String input = syntaxAndInput.substring(pos + 1); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
230 |
String expr; |
29270
0f65e3c44659
8073445: (fs) FileSystem.getPathMatcher(...) should check syntax component without regard to case
bpb
parents:
28562
diff
changeset
|
231 |
if (syntax.equalsIgnoreCase(GLOB_SYNTAX)) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
232 |
expr = toRegexPattern(input); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
233 |
} else { |
29270
0f65e3c44659
8073445: (fs) FileSystem.getPathMatcher(...) should check syntax component without regard to case
bpb
parents:
28562
diff
changeset
|
234 |
if (syntax.equalsIgnoreCase(REGEX_SYNTAX)) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
235 |
expr = input; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
236 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
237 |
throw new UnsupportedOperationException("Syntax '" + syntax + |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
238 |
"' not recognized"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
239 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
240 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
241 |
// return matcher |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
242 |
final Pattern pattern = Pattern.compile(expr); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
243 |
return new PathMatcher() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
244 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
245 |
public boolean matches(Path path) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
246 |
return pattern.matcher(path.toString()).matches(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
247 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
248 |
}; |
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 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
251 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
252 |
public void close() throws IOException { |
7189 | 253 |
beginWrite(); |
254 |
try { |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
255 |
if (!isOpen) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
256 |
return; |
7189 | 257 |
isOpen = false; // set closed |
258 |
} finally { |
|
259 |
endWrite(); |
|
260 |
} |
|
261 |
if (!streams.isEmpty()) { // unlock and close all remaining streams |
|
262 |
Set<InputStream> copy = new HashSet<>(streams); |
|
263 |
for (InputStream is: copy) |
|
264 |
is.close(); |
|
265 |
} |
|
266 |
beginWrite(); // lock and sync |
|
267 |
try { |
|
24364
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
268 |
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> { |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
269 |
sync(); return null; |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
270 |
}); |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
271 |
ch.close(); // close the ch just in case no update |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
272 |
} catch (PrivilegedActionException e) { // and sync dose not close the ch |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
273 |
throw (IOException)e.getException(); |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
274 |
} finally { |
7189 | 275 |
endWrite(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
276 |
} |
7189 | 277 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
278 |
synchronized (inflaters) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
279 |
for (Inflater inf : inflaters) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
280 |
inf.end(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
281 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
282 |
synchronized (deflaters) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
283 |
for (Deflater def : deflaters) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
284 |
def.end(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
285 |
} |
7189 | 286 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
287 |
IOException ioe = null; |
7189 | 288 |
synchronized (tmppaths) { |
289 |
for (Path p: tmppaths) { |
|
290 |
try { |
|
24364
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
291 |
AccessController.doPrivileged( |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
292 |
(PrivilegedExceptionAction<Boolean>)() -> Files.deleteIfExists(p)); |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
293 |
} catch (PrivilegedActionException e) { |
da8afb112f5d
8040059: Change default policy for extensions to no permission
mchung
parents:
23925
diff
changeset
|
294 |
IOException x = (IOException)e.getException(); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
295 |
if (ioe == null) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
296 |
ioe = x; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
297 |
else |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
298 |
ioe.addSuppressed(x); |
7189 | 299 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
300 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
301 |
} |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
302 |
provider.removeFileSystem(zfpath, this); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
303 |
if (ioe != null) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
304 |
throw ioe; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
305 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
306 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
307 |
ZipFileAttributes getFileAttributes(byte[] path) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
308 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
309 |
{ |
7189 | 310 |
Entry e; |
311 |
beginRead(); |
|
312 |
try { |
|
313 |
ensureOpen(); |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
314 |
e = getEntry(path); |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
315 |
if (e == null) { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
316 |
IndexNode inode = getInode(path); |
7189 | 317 |
if (inode == null) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
318 |
return null; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
319 |
e = new Entry(inode.name, inode.isdir); // pseudo directory |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
320 |
e.method = METHOD_STORED; // STORED for dir |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
321 |
e.mtime = e.atime = e.ctime = zfsDefaultTimeStamp; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
322 |
} |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
323 |
} finally { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
324 |
endRead(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
325 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
326 |
return e; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
327 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
328 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
329 |
void checkAccess(byte[] path) throws IOException { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
330 |
beginRead(); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
331 |
try { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
332 |
ensureOpen(); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
333 |
// is it necessary to readCEN as a sanity check? |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
334 |
if (getInode(path) == null) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
335 |
throw new NoSuchFileException(toString()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
336 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
337 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
338 |
} finally { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
339 |
endRead(); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
340 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
341 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
342 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
343 |
void setTimes(byte[] path, FileTime mtime, FileTime atime, FileTime ctime) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
344 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
345 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
346 |
checkWritable(); |
7189 | 347 |
beginWrite(); |
348 |
try { |
|
349 |
ensureOpen(); |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
350 |
Entry e = getEntry(path); // ensureOpen checked |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
351 |
if (e == null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
352 |
throw new NoSuchFileException(getString(path)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
353 |
if (e.type == Entry.CEN) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
354 |
e.type = Entry.COPY; // copy e |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
355 |
if (mtime != null) |
7189 | 356 |
e.mtime = mtime.toMillis(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
357 |
if (atime != null) |
7189 | 358 |
e.atime = atime.toMillis(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
359 |
if (ctime != null) |
7189 | 360 |
e.ctime = ctime.toMillis(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
361 |
update(e); |
7189 | 362 |
} finally { |
363 |
endWrite(); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
364 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
365 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
366 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
367 |
boolean exists(byte[] path) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
368 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
369 |
{ |
7189 | 370 |
beginRead(); |
371 |
try { |
|
372 |
ensureOpen(); |
|
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
373 |
return getInode(path) != null; |
7189 | 374 |
} finally { |
375 |
endRead(); |
|
376 |
} |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
377 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
378 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
379 |
boolean isDirectory(byte[] path) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
380 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
381 |
{ |
7189 | 382 |
beginRead(); |
383 |
try { |
|
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
384 |
IndexNode n = getInode(path); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
385 |
return n != null && n.isDir(); |
7189 | 386 |
} finally { |
387 |
endRead(); |
|
6699
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 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
390 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
391 |
// returns the list of child paths of "path" |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
392 |
Iterator<Path> iteratorOf(byte[] path, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
393 |
DirectoryStream.Filter<? super Path> filter) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
394 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
395 |
{ |
7189 | 396 |
beginWrite(); // iteration of inodes needs exclusive lock |
397 |
try { |
|
398 |
ensureOpen(); |
|
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
399 |
IndexNode inode = getInode(path); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
400 |
if (inode == null) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
401 |
throw new NotDirectoryException(getString(path)); |
7189 | 402 |
List<Path> list = new ArrayList<>(); |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
403 |
IndexNode child = inode.child; |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
404 |
while (child != null) { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
405 |
// assume all path from zip file itself is "normalized" |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
406 |
ZipPath zp = new ZipPath(this, child.name, true); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
407 |
if (filter == null || filter.accept(zp)) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
408 |
list.add(zp); |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
409 |
child = child.sibling; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
410 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
411 |
return list.iterator(); |
7189 | 412 |
} finally { |
413 |
endWrite(); |
|
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 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
417 |
void createDirectory(byte[] dir, FileAttribute<?>... attrs) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
418 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
419 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
420 |
checkWritable(); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
421 |
// dir = toDirectoryPath(dir); |
7189 | 422 |
beginWrite(); |
423 |
try { |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
424 |
ensureOpen(); |
7189 | 425 |
if (dir.length == 0 || exists(dir)) // root dir, or exiting dir |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
426 |
throw new FileAlreadyExistsException(getString(dir)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
427 |
checkParents(dir); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
428 |
Entry e = new Entry(dir, Entry.NEW, true); |
7189 | 429 |
e.method = METHOD_STORED; // STORED for dir |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
430 |
update(e); |
7189 | 431 |
} finally { |
432 |
endWrite(); |
|
6699
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 |
void copyFile(boolean deletesrc, byte[]src, byte[] dst, CopyOption... options) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
437 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
438 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
439 |
checkWritable(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
440 |
if (Arrays.equals(src, dst)) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
441 |
return; // do nothing, src and dst are the same |
7189 | 442 |
|
443 |
beginWrite(); |
|
444 |
try { |
|
445 |
ensureOpen(); |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
446 |
Entry eSrc = getEntry(src); // ensureOpen checked |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
447 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
448 |
if (eSrc == null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
449 |
throw new NoSuchFileException(getString(src)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
450 |
if (eSrc.isDir()) { // spec says to create dst dir |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
451 |
createDirectory(dst); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
452 |
return; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
453 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
454 |
boolean hasReplace = false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
455 |
boolean hasCopyAttrs = false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
456 |
for (CopyOption opt : options) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
457 |
if (opt == REPLACE_EXISTING) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
458 |
hasReplace = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
459 |
else if (opt == COPY_ATTRIBUTES) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
460 |
hasCopyAttrs = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
461 |
} |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
462 |
Entry eDst = getEntry(dst); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
463 |
if (eDst != null) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
464 |
if (!hasReplace) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
465 |
throw new FileAlreadyExistsException(getString(dst)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
466 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
467 |
checkParents(dst); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
468 |
} |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
469 |
Entry u = new Entry(eSrc, Entry.COPY); // copy eSrc entry |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
470 |
u.name(dst); // change name |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
471 |
if (eSrc.type == Entry.NEW || eSrc.type == Entry.FILECH) |
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 |
u.type = eSrc.type; // make it the same type |
16857
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
14342
diff
changeset
|
474 |
if (deletesrc) { // if it's a "rename", take the data |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
14342
diff
changeset
|
475 |
u.bytes = eSrc.bytes; |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
14342
diff
changeset
|
476 |
u.file = eSrc.file; |
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
14342
diff
changeset
|
477 |
} else { // if it's not "rename", copy the data |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
478 |
if (eSrc.bytes != null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
479 |
u.bytes = Arrays.copyOf(eSrc.bytes, eSrc.bytes.length); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
480 |
else if (eSrc.file != null) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
481 |
u.file = getTempPathForEntry(null); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
482 |
Files.copy(eSrc.file, u.file, REPLACE_EXISTING); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
483 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
484 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
485 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
486 |
if (!hasCopyAttrs) |
7189 | 487 |
u.mtime = u.atime= u.ctime = System.currentTimeMillis(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
488 |
update(u); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
489 |
if (deletesrc) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
490 |
updateDelete(eSrc); |
7189 | 491 |
} finally { |
492 |
endWrite(); |
|
6699
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 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
495 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
496 |
// Returns an output stream for writing the contents into the specified |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
497 |
// entry. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
498 |
OutputStream newOutputStream(byte[] path, OpenOption... options) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
499 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
500 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
501 |
checkWritable(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
502 |
boolean hasCreateNew = false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
503 |
boolean hasCreate = false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
504 |
boolean hasAppend = false; |
30811
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
505 |
boolean hasTruncate = false; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
506 |
for (OpenOption opt: options) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
507 |
if (opt == READ) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
508 |
throw new IllegalArgumentException("READ not allowed"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
509 |
if (opt == CREATE_NEW) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
510 |
hasCreateNew = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
511 |
if (opt == CREATE) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
512 |
hasCreate = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
513 |
if (opt == APPEND) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
514 |
hasAppend = true; |
30811
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
515 |
if (opt == TRUNCATE_EXISTING) |
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
516 |
hasTruncate = true; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
517 |
} |
30811
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
518 |
if (hasAppend && hasTruncate) |
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
519 |
throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed"); |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
520 |
beginRead(); // only need a readlock, the "update()" will |
7189 | 521 |
try { // try to obtain a writelock when the os is |
522 |
ensureOpen(); // being closed. |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
523 |
Entry e = getEntry(path); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
524 |
if (e != null) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
525 |
if (e.isDir() || hasCreateNew) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
526 |
throw new FileAlreadyExistsException(getString(path)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
527 |
if (hasAppend) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
528 |
InputStream is = getInputStream(e); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
529 |
OutputStream os = getOutputStream(new Entry(e, Entry.NEW)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
530 |
copyStream(is, os); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
531 |
is.close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
532 |
return os; |
7189 | 533 |
} |
534 |
return getOutputStream(new Entry(e, Entry.NEW)); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
535 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
536 |
if (!hasCreate && !hasCreateNew) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
537 |
throw new NoSuchFileException(getString(path)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
538 |
checkParents(path); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
539 |
return getOutputStream(new Entry(path, Entry.NEW, false)); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
540 |
} |
7189 | 541 |
} finally { |
542 |
endRead(); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
543 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
544 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
545 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
546 |
// Returns an input stream for reading the contents of the specified |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
547 |
// file entry. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
548 |
InputStream newInputStream(byte[] path) throws IOException { |
7189 | 549 |
beginRead(); |
550 |
try { |
|
551 |
ensureOpen(); |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
552 |
Entry e = getEntry(path); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
553 |
if (e == null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
554 |
throw new NoSuchFileException(getString(path)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
555 |
if (e.isDir()) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
556 |
throw new FileSystemException(getString(path), "is a directory", null); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
557 |
return getInputStream(e); |
7189 | 558 |
} finally { |
559 |
endRead(); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
560 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
561 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
562 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
563 |
private void checkOptions(Set<? extends OpenOption> options) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
564 |
// check for options of null type and option is an intance of StandardOpenOption |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
565 |
for (OpenOption option : options) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
566 |
if (option == null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
567 |
throw new NullPointerException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
568 |
if (!(option instanceof StandardOpenOption)) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
569 |
throw new IllegalArgumentException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
570 |
} |
30811
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
571 |
if (options.contains(APPEND) && options.contains(TRUNCATE_EXISTING)) |
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
572 |
throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed"); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
573 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
574 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
575 |
// Returns a Writable/ReadByteChannel for now. Might consdier to use |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
576 |
// newFileChannel() instead, which dump the entry data into a regular |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
577 |
// file on the default file system and create a FileChannel on top of |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
578 |
// it. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
579 |
SeekableByteChannel newByteChannel(byte[] path, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
580 |
Set<? extends OpenOption> options, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
581 |
FileAttribute<?>... attrs) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
582 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
583 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
584 |
checkOptions(options); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
585 |
if (options.contains(StandardOpenOption.WRITE) || |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
586 |
options.contains(StandardOpenOption.APPEND)) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
587 |
checkWritable(); |
7189 | 588 |
beginRead(); |
589 |
try { |
|
590 |
final WritableByteChannel wbc = Channels.newChannel( |
|
591 |
newOutputStream(path, options.toArray(new OpenOption[0]))); |
|
592 |
long leftover = 0; |
|
593 |
if (options.contains(StandardOpenOption.APPEND)) { |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
594 |
Entry e = getEntry(path); |
7189 | 595 |
if (e != null && e.size >= 0) |
596 |
leftover = e.size; |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
597 |
} |
7189 | 598 |
final long offset = leftover; |
599 |
return new SeekableByteChannel() { |
|
600 |
long written = offset; |
|
601 |
public boolean isOpen() { |
|
602 |
return wbc.isOpen(); |
|
603 |
} |
|
604 |
||
605 |
public long position() throws IOException { |
|
606 |
return written; |
|
607 |
} |
|
608 |
||
609 |
public SeekableByteChannel position(long pos) |
|
610 |
throws IOException |
|
611 |
{ |
|
612 |
throw new UnsupportedOperationException(); |
|
613 |
} |
|
614 |
||
615 |
public int read(ByteBuffer dst) throws IOException { |
|
616 |
throw new UnsupportedOperationException(); |
|
617 |
} |
|
618 |
||
619 |
public SeekableByteChannel truncate(long size) |
|
620 |
throws IOException |
|
621 |
{ |
|
622 |
throw new UnsupportedOperationException(); |
|
623 |
} |
|
624 |
||
625 |
public int write(ByteBuffer src) throws IOException { |
|
626 |
int n = wbc.write(src); |
|
627 |
written += n; |
|
628 |
return n; |
|
629 |
} |
|
630 |
||
631 |
public long size() throws IOException { |
|
632 |
return written; |
|
633 |
} |
|
634 |
||
635 |
public void close() throws IOException { |
|
636 |
wbc.close(); |
|
637 |
} |
|
638 |
}; |
|
639 |
} finally { |
|
640 |
endRead(); |
|
641 |
} |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
642 |
} else { |
7189 | 643 |
beginRead(); |
644 |
try { |
|
645 |
ensureOpen(); |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
646 |
Entry e = getEntry(path); |
7189 | 647 |
if (e == null || e.isDir()) |
648 |
throw new NoSuchFileException(getString(path)); |
|
649 |
final ReadableByteChannel rbc = |
|
650 |
Channels.newChannel(getInputStream(e)); |
|
651 |
final long size = e.size; |
|
652 |
return new SeekableByteChannel() { |
|
653 |
long read = 0; |
|
654 |
public boolean isOpen() { |
|
655 |
return rbc.isOpen(); |
|
656 |
} |
|
657 |
||
658 |
public long position() throws IOException { |
|
659 |
return read; |
|
660 |
} |
|
661 |
||
662 |
public SeekableByteChannel position(long pos) |
|
663 |
throws IOException |
|
664 |
{ |
|
665 |
throw new UnsupportedOperationException(); |
|
666 |
} |
|
667 |
||
668 |
public int read(ByteBuffer dst) throws IOException { |
|
12676
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
11841
diff
changeset
|
669 |
int n = rbc.read(dst); |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
11841
diff
changeset
|
670 |
if (n > 0) { |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
11841
diff
changeset
|
671 |
read += n; |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
11841
diff
changeset
|
672 |
} |
3b7fae360d04
7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
sherman
parents:
11841
diff
changeset
|
673 |
return n; |
7189 | 674 |
} |
675 |
||
676 |
public SeekableByteChannel truncate(long size) |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
677 |
throws IOException |
7189 | 678 |
{ |
679 |
throw new NonWritableChannelException(); |
|
680 |
} |
|
681 |
||
682 |
public int write (ByteBuffer src) throws IOException { |
|
683 |
throw new NonWritableChannelException(); |
|
684 |
} |
|
685 |
||
686 |
public long size() throws IOException { |
|
687 |
return size; |
|
688 |
} |
|
689 |
||
690 |
public void close() throws IOException { |
|
691 |
rbc.close(); |
|
692 |
} |
|
693 |
}; |
|
694 |
} finally { |
|
695 |
endRead(); |
|
696 |
} |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
697 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
698 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
699 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
700 |
// Returns a FileChannel of the specified entry. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
701 |
// |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
702 |
// This implementation creates a temporary file on the default file system, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
703 |
// copy the entry data into it if the entry exists, and then create a |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
704 |
// FileChannel on top of it. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
705 |
FileChannel newFileChannel(byte[] path, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
706 |
Set<? extends OpenOption> options, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
707 |
FileAttribute<?>... attrs) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
708 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
709 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
710 |
checkOptions(options); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
711 |
final boolean forWrite = (options.contains(StandardOpenOption.WRITE) || |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
712 |
options.contains(StandardOpenOption.APPEND)); |
7189 | 713 |
beginRead(); |
714 |
try { |
|
715 |
ensureOpen(); |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
716 |
Entry e = getEntry(path); |
7189 | 717 |
if (forWrite) { |
718 |
checkWritable(); |
|
719 |
if (e == null) { |
|
30811
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
720 |
if (!options.contains(StandardOpenOption.CREATE) && |
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
721 |
!options.contains(StandardOpenOption.CREATE_NEW)) { |
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
722 |
throw new NoSuchFileException(getString(path)); |
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
723 |
} |
7189 | 724 |
} else { |
30811
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
725 |
if (options.contains(StandardOpenOption.CREATE_NEW)) { |
7189 | 726 |
throw new FileAlreadyExistsException(getString(path)); |
30811
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
727 |
} |
7189 | 728 |
if (e.isDir()) |
729 |
throw new FileAlreadyExistsException("directory <" |
|
730 |
+ getString(path) + "> exists"); |
|
731 |
} |
|
30811
58432ddf9528
8028480: (zipfs) NoSuchFileException on creating a file in ZipFileSystem with CREATE and WRITE
sherman
parents:
29815
diff
changeset
|
732 |
options = new HashSet<>(options); |
7189 | 733 |
options.remove(StandardOpenOption.CREATE_NEW); // for tmpfile |
734 |
} else if (e == null || e.isDir()) { |
|
735 |
throw new NoSuchFileException(getString(path)); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
736 |
} |
7189 | 737 |
|
738 |
final boolean isFCH = (e != null && e.type == Entry.FILECH); |
|
739 |
final Path tmpfile = isFCH ? e.file : getTempPathForEntry(path); |
|
740 |
final FileChannel fch = tmpfile.getFileSystem() |
|
741 |
.provider() |
|
742 |
.newFileChannel(tmpfile, options, attrs); |
|
743 |
final Entry u = isFCH ? e : new Entry(path, tmpfile, Entry.FILECH); |
|
744 |
if (forWrite) { |
|
745 |
u.flag = FLAG_DATADESCR; |
|
746 |
u.method = METHOD_DEFLATED; |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
747 |
} |
7189 | 748 |
// is there a better way to hook into the FileChannel's close method? |
749 |
return new FileChannel() { |
|
750 |
public int write(ByteBuffer src) throws IOException { |
|
751 |
return fch.write(src); |
|
752 |
} |
|
753 |
public long write(ByteBuffer[] srcs, int offset, int length) |
|
754 |
throws IOException |
|
755 |
{ |
|
756 |
return fch.write(srcs, offset, length); |
|
757 |
} |
|
758 |
public long position() throws IOException { |
|
759 |
return fch.position(); |
|
760 |
} |
|
761 |
public FileChannel position(long newPosition) |
|
762 |
throws IOException |
|
763 |
{ |
|
764 |
fch.position(newPosition); |
|
765 |
return this; |
|
766 |
} |
|
767 |
public long size() throws IOException { |
|
768 |
return fch.size(); |
|
769 |
} |
|
770 |
public FileChannel truncate(long size) |
|
771 |
throws IOException |
|
772 |
{ |
|
773 |
fch.truncate(size); |
|
774 |
return this; |
|
775 |
} |
|
776 |
public void force(boolean metaData) |
|
777 |
throws IOException |
|
778 |
{ |
|
779 |
fch.force(metaData); |
|
780 |
} |
|
781 |
public long transferTo(long position, long count, |
|
782 |
WritableByteChannel target) |
|
783 |
throws IOException |
|
784 |
{ |
|
785 |
return fch.transferTo(position, count, target); |
|
786 |
} |
|
787 |
public long transferFrom(ReadableByteChannel src, |
|
788 |
long position, long count) |
|
789 |
throws IOException |
|
790 |
{ |
|
791 |
return fch.transferFrom(src, position, count); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
792 |
} |
7189 | 793 |
public int read(ByteBuffer dst) throws IOException { |
794 |
return fch.read(dst); |
|
795 |
} |
|
796 |
public int read(ByteBuffer dst, long position) |
|
797 |
throws IOException |
|
798 |
{ |
|
799 |
return fch.read(dst, position); |
|
800 |
} |
|
801 |
public long read(ByteBuffer[] dsts, int offset, int length) |
|
802 |
throws IOException |
|
803 |
{ |
|
804 |
return fch.read(dsts, offset, length); |
|
805 |
} |
|
806 |
public int write(ByteBuffer src, long position) |
|
807 |
throws IOException |
|
808 |
{ |
|
809 |
return fch.write(src, position); |
|
810 |
} |
|
811 |
public MappedByteBuffer map(MapMode mode, |
|
812 |
long position, long size) |
|
813 |
throws IOException |
|
814 |
{ |
|
815 |
throw new UnsupportedOperationException(); |
|
816 |
} |
|
817 |
public FileLock lock(long position, long size, boolean shared) |
|
818 |
throws IOException |
|
819 |
{ |
|
820 |
return fch.lock(position, size, shared); |
|
821 |
} |
|
822 |
public FileLock tryLock(long position, long size, boolean shared) |
|
823 |
throws IOException |
|
824 |
{ |
|
825 |
return fch.tryLock(position, size, shared); |
|
826 |
} |
|
827 |
protected void implCloseChannel() throws IOException { |
|
828 |
fch.close(); |
|
829 |
if (forWrite) { |
|
830 |
u.mtime = System.currentTimeMillis(); |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
831 |
u.size = Files.size(u.file); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
832 |
|
7189 | 833 |
update(u); |
834 |
} else { |
|
835 |
if (!isFCH) // if this is a new fch for reading |
|
836 |
removeTempPathForEntry(tmpfile); |
|
837 |
} |
|
838 |
} |
|
839 |
}; |
|
840 |
} finally { |
|
841 |
endRead(); |
|
842 |
} |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
843 |
} |
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 |
// the outstanding input streams that need to be closed |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
846 |
private Set<InputStream> streams = |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
847 |
Collections.synchronizedSet(new HashSet<InputStream>()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
848 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
849 |
// the ex-channel and ex-path that need to close when their outstanding |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
850 |
// input streams are all closed by the obtainers. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
851 |
private Set<ExChannelCloser> exChClosers = new HashSet<>(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
852 |
|
7189 | 853 |
private Set<Path> tmppaths = Collections.synchronizedSet(new HashSet<Path>()); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
854 |
private Path getTempPathForEntry(byte[] path) throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
855 |
Path tmpPath = createTempFileInSameDirectoryAs(zfpath); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
856 |
if (path != null) { |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
857 |
Entry e = getEntry(path); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
858 |
if (e != null) { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
859 |
try (InputStream is = newInputStream(path)) { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
860 |
Files.copy(is, tmpPath, REPLACE_EXISTING); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
861 |
} |
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 |
return tmpPath; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
865 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
866 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
867 |
private void removeTempPathForEntry(Path path) throws IOException { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
868 |
Files.delete(path); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
869 |
tmppaths.remove(path); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
870 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
871 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
872 |
// check if all parents really exit. ZIP spec does not require |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
873 |
// the existence of any "parent directory". |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
874 |
private void checkParents(byte[] path) throws IOException { |
7189 | 875 |
beginRead(); |
876 |
try { |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
877 |
while ((path = getParent(path)) != null && |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
878 |
path != ROOTPATH) { |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
879 |
if (!inodes.containsKey(IndexNode.keyOf(path))) { |
7189 | 880 |
throw new NoSuchFileException(getString(path)); |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
881 |
} |
7189 | 882 |
} |
883 |
} finally { |
|
884 |
endRead(); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
885 |
} |
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 |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
888 |
private static byte[] ROOTPATH = new byte[] { '/' }; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
889 |
private static byte[] getParent(byte[] path) { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
890 |
int off = getParentOff(path); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
891 |
if (off <= 1) |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
892 |
return ROOTPATH; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
893 |
return Arrays.copyOf(path, off); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
894 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
895 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
896 |
private static int getParentOff(byte[] path) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
897 |
int off = path.length - 1; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
898 |
if (off > 0 && path[off] == '/') // isDirectory |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
899 |
off--; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
900 |
while (off > 0 && path[off] != '/') { off--; } |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
901 |
return off; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
902 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
903 |
|
7189 | 904 |
private final void beginWrite() { |
905 |
rwlock.writeLock().lock(); |
|
906 |
} |
|
907 |
||
908 |
private final void endWrite() { |
|
909 |
rwlock.writeLock().unlock(); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
910 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
911 |
|
7189 | 912 |
private final void beginRead() { |
913 |
rwlock.readLock().lock(); |
|
914 |
} |
|
915 |
||
916 |
private final void endRead() { |
|
917 |
rwlock.readLock().unlock(); |
|
918 |
} |
|
919 |
||
920 |
/////////////////////////////////////////////////////////////////// |
|
921 |
||
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
922 |
private volatile boolean isOpen = true; |
7189 | 923 |
private final SeekableByteChannel ch; // channel to the zipfile |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
924 |
final byte[] cen; // CEN & ENDHDR |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
925 |
private END end; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
926 |
private long locpos; // position of first LOC header (usually 0) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
927 |
|
7189 | 928 |
private final ReadWriteLock rwlock = new ReentrantReadWriteLock(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
929 |
|
7189 | 930 |
// name -> pos (in cen), IndexNode itself can be used as a "key" |
931 |
private LinkedHashMap<IndexNode, IndexNode> inodes; |
|
932 |
||
933 |
final byte[] getBytes(String name) { |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
934 |
return zc.getBytes(name); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
935 |
} |
7189 | 936 |
|
937 |
final String getString(byte[] name) { |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
938 |
return zc.toString(name); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
939 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
940 |
|
44534 | 941 |
@SuppressWarnings("deprecation") |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
942 |
protected void finalize() throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
943 |
close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
944 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
945 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
946 |
// Reads len bytes of data from the specified offset into buf. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
947 |
// Returns the total number of bytes read. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
948 |
// Each/every byte read from here (except the cen, which is mapped). |
7189 | 949 |
final long readFullyAt(byte[] buf, int off, long len, long pos) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
950 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
951 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
952 |
ByteBuffer bb = ByteBuffer.wrap(buf); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
953 |
bb.position(off); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
954 |
bb.limit((int)(off + len)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
955 |
return readFullyAt(bb, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
956 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
957 |
|
7189 | 958 |
private final long readFullyAt(ByteBuffer bb, long pos) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
959 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
960 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
961 |
synchronized(ch) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
962 |
return ch.position(pos).read(bb); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
963 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
964 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
965 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
966 |
// Searches for end of central directory (END) header. The contents of |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
967 |
// the END header will be read and placed in endbuf. Returns the file |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
968 |
// position of the END header, otherwise returns -1 if the END header |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
969 |
// was not found or an error occurred. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
970 |
private END findEND() throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
971 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
972 |
byte[] buf = new byte[READBLOCKSZ]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
973 |
long ziplen = ch.size(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
974 |
long minHDR = (ziplen - END_MAXLEN) > 0 ? ziplen - END_MAXLEN : 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
975 |
long minPos = minHDR - (buf.length - ENDHDR); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
976 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
977 |
for (long pos = ziplen - buf.length; pos >= minPos; pos -= (buf.length - ENDHDR)) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
978 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
979 |
int off = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
980 |
if (pos < 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
981 |
// Pretend there are some NUL bytes before start of file |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
982 |
off = (int)-pos; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
983 |
Arrays.fill(buf, 0, off, (byte)0); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
984 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
985 |
int len = buf.length - off; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
986 |
if (readFullyAt(buf, off, len, pos + off) != len) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
987 |
zerror("zip END header not found"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
988 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
989 |
// Now scan the block backwards for END header signature |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
990 |
for (int i = buf.length - ENDHDR; i >= 0; i--) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
991 |
if (buf[i+0] == (byte)'P' && |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
992 |
buf[i+1] == (byte)'K' && |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
993 |
buf[i+2] == (byte)'\005' && |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
994 |
buf[i+3] == (byte)'\006' && |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
995 |
(pos + i + ENDHDR + ENDCOM(buf, i) == ziplen)) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
996 |
// Found END header |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
997 |
buf = Arrays.copyOfRange(buf, i, i + ENDHDR); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
998 |
END end = new END(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
999 |
end.endsub = ENDSUB(buf); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1000 |
end.centot = ENDTOT(buf); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1001 |
end.cenlen = ENDSIZ(buf); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1002 |
end.cenoff = ENDOFF(buf); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1003 |
end.comlen = ENDCOM(buf); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1004 |
end.endpos = pos + i; |
47223
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1005 |
// try if there is zip64 end; |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1006 |
byte[] loc64 = new byte[ZIP64_LOCHDR]; |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1007 |
if (end.endpos < ZIP64_LOCHDR || |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1008 |
readFullyAt(loc64, 0, loc64.length, end.endpos - ZIP64_LOCHDR) |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1009 |
!= loc64.length || |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1010 |
!locator64SigAt(loc64, 0)) { |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1011 |
return end; |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1012 |
} |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1013 |
long end64pos = ZIP64_LOCOFF(loc64); |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1014 |
byte[] end64buf = new byte[ZIP64_ENDHDR]; |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1015 |
if (readFullyAt(end64buf, 0, end64buf.length, end64pos) |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1016 |
!= end64buf.length || |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1017 |
!end64SigAt(end64buf, 0)) { |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1018 |
return end; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1019 |
} |
47223
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1020 |
// end64 found, |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1021 |
long cenlen64 = ZIP64_ENDSIZ(end64buf); |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1022 |
long cenoff64 = ZIP64_ENDOFF(end64buf); |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1023 |
long centot64 = ZIP64_ENDTOT(end64buf); |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1024 |
// double-check |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1025 |
if (cenlen64 != end.cenlen && end.cenlen != ZIP64_MINVAL || |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1026 |
cenoff64 != end.cenoff && end.cenoff != ZIP64_MINVAL || |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1027 |
centot64 != end.centot && end.centot != ZIP64_MINVAL32) { |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1028 |
return end; |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1029 |
} |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1030 |
// to use the end64 values |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1031 |
end.cenlen = cenlen64; |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1032 |
end.cenoff = cenoff64; |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1033 |
end.centot = (int)centot64; // assume total < 2g |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1034 |
end.endpos = end64pos; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1035 |
return end; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1036 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1037 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1038 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1039 |
zerror("zip END header not found"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1040 |
return null; //make compiler happy |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1041 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1042 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1043 |
// Reads zip file central directory. Returns the file position of first |
21278 | 1044 |
// CEN header, otherwise returns -1 if an error occurred. If zip->msg != NULL |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1045 |
// then the error was a zip format error and zip->msg has the error text. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1046 |
// Always pass in -1 for knownTotal; it's used for a recursive call. |
7189 | 1047 |
private byte[] initCEN() throws IOException { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1048 |
end = findEND(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1049 |
if (end.endpos == 0) { |
7189 | 1050 |
inodes = new LinkedHashMap<>(10); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1051 |
locpos = 0; |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1052 |
buildNodeTree(); |
7189 | 1053 |
return null; // only END header present |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1054 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1055 |
if (end.cenlen > end.endpos) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1056 |
zerror("invalid END header (bad central directory size)"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1057 |
long cenpos = end.endpos - end.cenlen; // position of CEN table |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1058 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1059 |
// Get position of first local file (LOC) header, taking into |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1060 |
// account that there may be a stub prefixed to the zip file. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1061 |
locpos = cenpos - end.cenoff; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1062 |
if (locpos < 0) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1063 |
zerror("invalid END header (bad central directory offset)"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1064 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1065 |
// read in the CEN and END |
7189 | 1066 |
byte[] cen = new byte[(int)(end.cenlen + ENDHDR)]; |
1067 |
if (readFullyAt(cen, 0, cen.length, cenpos) != end.cenlen + ENDHDR) { |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1068 |
zerror("read CEN tables failed"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1069 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1070 |
// Iterate through the entries in the central directory |
7189 | 1071 |
inodes = new LinkedHashMap<>(end.centot + 1); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1072 |
int pos = 0; |
7189 | 1073 |
int limit = cen.length - ENDHDR; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1074 |
while (pos < limit) { |
29714
afac043e9bf0
8075774: Small readability and performance improvements for zipfs
martin
parents:
29270
diff
changeset
|
1075 |
if (!cenSigAt(cen, pos)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1076 |
zerror("invalid CEN header (bad signature)"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1077 |
int method = CENHOW(cen, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1078 |
int nlen = CENNAM(cen, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1079 |
int elen = CENEXT(cen, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1080 |
int clen = CENCOM(cen, pos); |
28562
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
1081 |
if ((CENFLG(cen, pos) & 1) != 0) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1082 |
zerror("invalid CEN header (encrypted entry)"); |
28562
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
1083 |
} |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
1084 |
if (method != METHOD_STORED && method != METHOD_DEFLATED) { |
7189 | 1085 |
zerror("invalid CEN header (unsupported compression method: " + method + ")"); |
28562
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
1086 |
} |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
1087 |
if (pos + CENHDR + nlen > limit) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1088 |
zerror("invalid CEN header (bad header size)"); |
28562
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
1089 |
} |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1090 |
IndexNode inode = new IndexNode(cen, pos + CENHDR, nlen, pos); |
7189 | 1091 |
inodes.put(inode, inode); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1092 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1093 |
// skip ext and comment |
7189 | 1094 |
pos += (CENHDR + nlen + elen + clen); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1095 |
} |
7189 | 1096 |
if (pos + ENDHDR != cen.length) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1097 |
zerror("invalid CEN header (bad header size)"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1098 |
} |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1099 |
buildNodeTree(); |
7189 | 1100 |
return cen; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1101 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1102 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1103 |
private void ensureOpen() throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1104 |
if (!isOpen) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1105 |
throw new ClosedFileSystemException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1106 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1107 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1108 |
// Creates a new empty temporary file in the same directory as the |
17699
dfa52f56753b
8004789: (zipfs) zip provider doesn't work correctly with file systems providers rather than the default
sherman
parents:
16857
diff
changeset
|
1109 |
// specified file. A variant of Files.createTempFile. |
7189 | 1110 |
private Path createTempFileInSameDirectoryAs(Path path) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1111 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1112 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1113 |
Path parent = path.toAbsolutePath().getParent(); |
17699
dfa52f56753b
8004789: (zipfs) zip provider doesn't work correctly with file systems providers rather than the default
sherman
parents:
16857
diff
changeset
|
1114 |
Path dir = (parent == null) ? path.getFileSystem().getPath(".") : parent; |
dfa52f56753b
8004789: (zipfs) zip provider doesn't work correctly with file systems providers rather than the default
sherman
parents:
16857
diff
changeset
|
1115 |
Path tmpPath = Files.createTempFile(dir, "zipfstmp", null); |
7189 | 1116 |
tmppaths.add(tmpPath); |
1117 |
return tmpPath; |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1118 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1119 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1120 |
////////////////////update & sync ////////////////////////////////////// |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1121 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1122 |
private boolean hasUpdate = false; |
7189 | 1123 |
|
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1124 |
// shared key. consumer guarantees the "writeLock" before use it. |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1125 |
private final IndexNode LOOKUPKEY = new IndexNode(null, -1); |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1126 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1127 |
private void updateDelete(IndexNode inode) { |
7189 | 1128 |
beginWrite(); |
1129 |
try { |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1130 |
removeFromTree(inode); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1131 |
inodes.remove(inode); |
7189 | 1132 |
hasUpdate = true; |
1133 |
} finally { |
|
1134 |
endWrite(); |
|
1135 |
} |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1136 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1137 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1138 |
private void update(Entry e) { |
7189 | 1139 |
beginWrite(); |
1140 |
try { |
|
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1141 |
IndexNode old = inodes.put(e, e); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1142 |
if (old != null) { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1143 |
removeFromTree(old); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1144 |
} |
16857
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
14342
diff
changeset
|
1145 |
if (e.type == Entry.NEW || e.type == Entry.FILECH || e.type == Entry.COPY) { |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1146 |
IndexNode parent = inodes.get(LOOKUPKEY.as(getParent(e.name))); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1147 |
e.sibling = parent.child; |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1148 |
parent.child = e; |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1149 |
} |
7189 | 1150 |
hasUpdate = true; |
1151 |
} finally { |
|
1152 |
endWrite(); |
|
1153 |
} |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1154 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1155 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1156 |
// copy over the whole LOC entry (header if necessary, data and ext) from |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1157 |
// old zip to the new one. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1158 |
private long copyLOCEntry(Entry e, boolean updateHeader, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1159 |
OutputStream os, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1160 |
long written, byte[] buf) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1161 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1162 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1163 |
long locoff = e.locoff; // where to read |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1164 |
e.locoff = written; // update the e.locoff with new value |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1165 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1166 |
// calculate the size need to write out |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1167 |
long size = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1168 |
// if there is A ext |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1169 |
if ((e.flag & FLAG_DATADESCR) != 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1170 |
if (e.size >= ZIP64_MINVAL || e.csize >= ZIP64_MINVAL) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1171 |
size = 24; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1172 |
else |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1173 |
size = 16; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1174 |
} |
7189 | 1175 |
// read loc, use the original loc.elen/nlen |
1176 |
if (readFullyAt(buf, 0, LOCHDR , locoff) != LOCHDR) |
|
1177 |
throw new ZipException("loc: reading failed"); |
|
1178 |
if (updateHeader) { |
|
1179 |
locoff += LOCHDR + LOCNAM(buf) + LOCEXT(buf); // skip header |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1180 |
size += e.csize; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1181 |
written = e.writeLOC(os) + size; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1182 |
} else { |
7189 | 1183 |
os.write(buf, 0, LOCHDR); // write out the loc header |
1184 |
locoff += LOCHDR; |
|
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
1185 |
// use e.csize, LOCSIZ(buf) is zero if FLAG_DATADESCR is on |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
1186 |
// size += LOCNAM(buf) + LOCEXT(buf) + LOCSIZ(buf); |
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
1187 |
size += LOCNAM(buf) + LOCEXT(buf) + e.csize; |
7189 | 1188 |
written = LOCHDR + size; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1189 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1190 |
int n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1191 |
while (size > 0 && |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1192 |
(n = (int)readFullyAt(buf, 0, buf.length, locoff)) != -1) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1193 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1194 |
if (size < n) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1195 |
n = (int)size; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1196 |
os.write(buf, 0, n); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1197 |
size -= n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1198 |
locoff += n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1199 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1200 |
return written; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1201 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1202 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1203 |
// sync the zip file system, if there is any udpate |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1204 |
private void sync() throws IOException { |
47223
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1205 |
// System.out.printf("->sync(%s) starting....!%n", toString()); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1206 |
// check ex-closer |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1207 |
if (!exChClosers.isEmpty()) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1208 |
for (ExChannelCloser ecc : exChClosers) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1209 |
if (ecc.streams.isEmpty()) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1210 |
ecc.ch.close(); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1211 |
Files.delete(ecc.path); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1212 |
exChClosers.remove(ecc); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1213 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1214 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1215 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1216 |
if (!hasUpdate) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1217 |
return; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1218 |
Path tmpFile = createTempFileInSameDirectoryAs(zfpath); |
10365
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1219 |
try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(tmpFile, WRITE))) |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1220 |
{ |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1221 |
ArrayList<Entry> elist = new ArrayList<>(inodes.size()); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1222 |
long written = 0; |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1223 |
byte[] buf = new byte[8192]; |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1224 |
Entry e = null; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1225 |
|
10365
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1226 |
// write loc |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1227 |
for (IndexNode inode : inodes.values()) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1228 |
if (inode instanceof Entry) { // an updated inode |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1229 |
e = (Entry)inode; |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1230 |
try { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1231 |
if (e.type == Entry.COPY) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1232 |
// entry copy: the only thing changed is the "name" |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1233 |
// and "nlen" in LOC header, so we udpate/rewrite the |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1234 |
// LOC in new file and simply copy the rest (data and |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1235 |
// ext) without enflating/deflating from the old zip |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1236 |
// file LOC entry. |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1237 |
written += copyLOCEntry(e, true, os, written, buf); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1238 |
} else { // NEW, FILECH or CEN |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1239 |
e.locoff = written; |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1240 |
written += e.writeLOC(os); // write loc header |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1241 |
if (e.bytes != null) { // in-memory, deflated |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1242 |
os.write(e.bytes); // already |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1243 |
written += e.bytes.length; |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1244 |
} else if (e.file != null) { // tmp file |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1245 |
try (InputStream is = Files.newInputStream(e.file)) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1246 |
int n; |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1247 |
if (e.type == Entry.NEW) { // deflated already |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1248 |
while ((n = is.read(buf)) != -1) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1249 |
os.write(buf, 0, n); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1250 |
written += n; |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1251 |
} |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1252 |
} else if (e.type == Entry.FILECH) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1253 |
// the data are not deflated, use ZEOS |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1254 |
try (OutputStream os2 = new EntryOutputStream(e, os)) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1255 |
while ((n = is.read(buf)) != -1) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1256 |
os2.write(buf, 0, n); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1257 |
} |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1258 |
} |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1259 |
written += e.csize; |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1260 |
if ((e.flag & FLAG_DATADESCR) != 0) |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1261 |
written += e.writeEXT(os); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1262 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1263 |
} |
10365
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1264 |
Files.delete(e.file); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1265 |
tmppaths.remove(e.file); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1266 |
} else { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1267 |
// dir, 0-length data |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1268 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1269 |
} |
10365
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1270 |
elist.add(e); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1271 |
} catch (IOException x) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1272 |
x.printStackTrace(); // skip any in-accurate entry |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1273 |
} |
10365
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1274 |
} else { // unchanged inode |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1275 |
if (inode.pos == -1) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1276 |
continue; // pseudo directory node |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1277 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1278 |
e = Entry.readCEN(this, inode); |
10365
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1279 |
try { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1280 |
written += copyLOCEntry(e, false, os, written, buf); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1281 |
elist.add(e); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1282 |
} catch (IOException x) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1283 |
x.printStackTrace(); // skip any wrong entry |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1284 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1285 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1286 |
} |
10365
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1287 |
|
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1288 |
// now write back the cen and end table |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1289 |
end.cenoff = written; |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1290 |
for (Entry entry : elist) { |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1291 |
written += entry.writeCEN(os); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1292 |
} |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1293 |
end.centot = elist.size(); |
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
1294 |
end.cenlen = written - end.cenoff; |
47223
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1295 |
end.write(os, written, forceEnd64); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1296 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1297 |
if (!streams.isEmpty()) { |
7189 | 1298 |
// |
1299 |
// TBD: ExChannelCloser should not be necessary if we only |
|
1300 |
// sync when being closed, all streams should have been |
|
1301 |
// closed already. Keep the logic here for now. |
|
1302 |
// |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1303 |
// There are outstanding input streams open on existing "ch", |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1304 |
// so, don't close the "cha" and delete the "file for now, let |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1305 |
// the "ex-channel-closer" to handle them |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1306 |
ExChannelCloser ecc = new ExChannelCloser( |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1307 |
createTempFileInSameDirectoryAs(zfpath), |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1308 |
ch, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1309 |
streams); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1310 |
Files.move(zfpath, ecc.path, REPLACE_EXISTING); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1311 |
exChClosers.add(ecc); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1312 |
streams = Collections.synchronizedSet(new HashSet<InputStream>()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1313 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1314 |
ch.close(); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1315 |
Files.delete(zfpath); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1316 |
} |
7189 | 1317 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1318 |
Files.move(tmpFile, zfpath, REPLACE_EXISTING); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1319 |
hasUpdate = false; // clear |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1320 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1321 |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
1322 |
IndexNode getInode(byte[] path) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1323 |
if (path == null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1324 |
throw new NullPointerException("path"); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1325 |
return inodes.get(IndexNode.keyOf(path)); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1326 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1327 |
|
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
30811
diff
changeset
|
1328 |
Entry getEntry(byte[] path) throws IOException { |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1329 |
IndexNode inode = getInode(path); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1330 |
if (inode instanceof Entry) |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1331 |
return (Entry)inode; |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1332 |
if (inode == null || inode.pos == -1) |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1333 |
return null; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1334 |
return Entry.readCEN(this, inode); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1335 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1336 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1337 |
public void deleteFile(byte[] path, boolean failIfNotExists) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1338 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1339 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1340 |
checkWritable(); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1341 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1342 |
IndexNode inode = getInode(path); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1343 |
if (inode == null) { |
7189 | 1344 |
if (path != null && path.length == 0) |
1345 |
throw new ZipException("root directory </> can't not be delete"); |
|
1346 |
if (failIfNotExists) |
|
1347 |
throw new NoSuchFileException(getString(path)); |
|
1348 |
} else { |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1349 |
if (inode.isDir() && inode.child != null) |
7189 | 1350 |
throw new DirectoryNotEmptyException(getString(path)); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1351 |
updateDelete(inode); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1352 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1353 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1354 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1355 |
private static void copyStream(InputStream is, OutputStream os) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1356 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1357 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1358 |
byte[] copyBuf = new byte[8192]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1359 |
int n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1360 |
while ((n = is.read(copyBuf)) != -1) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1361 |
os.write(copyBuf, 0, n); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1362 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1363 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1364 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1365 |
// Returns an out stream for either |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1366 |
// (1) writing the contents of a new entry, if the entry exits, or |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1367 |
// (2) updating/replacing the contents of the specified existing entry. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1368 |
private OutputStream getOutputStream(Entry e) throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1369 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1370 |
if (e.mtime == -1) |
7189 | 1371 |
e.mtime = System.currentTimeMillis(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1372 |
if (e.method == -1) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1373 |
e.method = METHOD_DEFLATED; // TBD: use default method |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1374 |
// store size, compressed size, and crc-32 in LOC header |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1375 |
e.flag = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1376 |
if (zc.isUTF8()) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1377 |
e.flag |= FLAG_EFS; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1378 |
OutputStream os; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1379 |
if (useTempFile) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1380 |
e.file = getTempPathForEntry(null); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1381 |
os = Files.newOutputStream(e.file, WRITE); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1382 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1383 |
os = new ByteArrayOutputStream((e.size > 0)? (int)e.size : 8192); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1384 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1385 |
return new EntryOutputStream(e, os); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1386 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1387 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1388 |
private InputStream getInputStream(Entry e) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1389 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1390 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1391 |
InputStream eis = null; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1392 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1393 |
if (e.type == Entry.NEW) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1394 |
if (e.bytes != null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1395 |
eis = new ByteArrayInputStream(e.bytes); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1396 |
else if (e.file != null) |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1397 |
eis = Files.newInputStream(e.file); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1398 |
else |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1399 |
throw new ZipException("update entry data is missing"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1400 |
} else if (e.type == Entry.FILECH) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1401 |
// FILECH result is un-compressed. |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
8005
diff
changeset
|
1402 |
eis = Files.newInputStream(e.file); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1403 |
// TBD: wrap to hook close() |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1404 |
// streams.add(eis); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1405 |
return eis; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1406 |
} else { // untouced CEN or COPY |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1407 |
eis = new EntryInputStream(e, ch); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1408 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1409 |
if (e.method == METHOD_DEFLATED) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1410 |
// MORE: Compute good size for inflater stream: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1411 |
long bufSize = e.size + 2; // Inflater likes a bit of slack |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1412 |
if (bufSize > 65536) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1413 |
bufSize = 8192; |
7189 | 1414 |
final long size = e.size; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1415 |
eis = new InflaterInputStream(eis, getInflater(), (int)bufSize) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1416 |
private boolean isClosed = false; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1417 |
public void close() throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1418 |
if (!isClosed) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1419 |
releaseInflater(inf); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1420 |
this.in.close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1421 |
isClosed = true; |
7189 | 1422 |
streams.remove(this); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1423 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1424 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1425 |
// Override fill() method to provide an extra "dummy" byte |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1426 |
// at the end of the input stream. This is required when |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1427 |
// using the "nowrap" Inflater option. (it appears the new |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1428 |
// zlib in 7 does not need it, but keep it for now) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1429 |
protected void fill() throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1430 |
if (eof) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1431 |
throw new EOFException( |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1432 |
"Unexpected end of ZLIB input stream"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1433 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1434 |
len = this.in.read(buf, 0, buf.length); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1435 |
if (len == -1) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1436 |
buf[0] = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1437 |
len = 1; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1438 |
eof = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1439 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1440 |
inf.setInput(buf, 0, len); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1441 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1442 |
private boolean eof; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1443 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1444 |
public int available() throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1445 |
if (isClosed) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1446 |
return 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1447 |
long avail = size - inf.getBytesWritten(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1448 |
return avail > (long) Integer.MAX_VALUE ? |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1449 |
Integer.MAX_VALUE : (int) avail; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1450 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1451 |
}; |
7189 | 1452 |
} else if (e.method == METHOD_STORED) { |
1453 |
// TBD: wrap/ it does not seem necessary |
|
1454 |
} else { |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1455 |
throw new ZipException("invalid compression method"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1456 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1457 |
streams.add(eis); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1458 |
return eis; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1459 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1460 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1461 |
// Inner class implementing the input stream used to read |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1462 |
// a (possibly compressed) zip file entry. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1463 |
private class EntryInputStream extends InputStream { |
7189 | 1464 |
private final SeekableByteChannel zfch; // local ref to zipfs's "ch". zipfs.ch might |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1465 |
// point to a new channel after sync() |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1466 |
private long pos; // current position within entry data |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1467 |
protected long rem; // number of remaining bytes within entry |
7189 | 1468 |
protected final long size; // uncompressed size of this entry |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1469 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1470 |
EntryInputStream(Entry e, SeekableByteChannel zfch) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1471 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1472 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1473 |
this.zfch = zfch; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1474 |
rem = e.csize; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1475 |
size = e.size; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1476 |
pos = e.locoff; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1477 |
if (pos == -1) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1478 |
Entry e2 = getEntry(e.name); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1479 |
if (e2 == null) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1480 |
throw new ZipException("invalid loc for entry <" + e.name + ">"); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1481 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1482 |
pos = e2.locoff; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1483 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1484 |
pos = -pos; // lazy initialize the real data offset |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1485 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1486 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1487 |
public int read(byte b[], int off, int len) throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1488 |
ensureOpen(); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1489 |
initDataPos(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1490 |
if (rem == 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1491 |
return -1; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1492 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1493 |
if (len <= 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1494 |
return 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1495 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1496 |
if (len > rem) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1497 |
len = (int) rem; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1498 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1499 |
// readFullyAt() |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1500 |
long n = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1501 |
ByteBuffer bb = ByteBuffer.wrap(b); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1502 |
bb.position(off); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1503 |
bb.limit(off + len); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1504 |
synchronized(zfch) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1505 |
n = zfch.position(pos).read(bb); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1506 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1507 |
if (n > 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1508 |
pos += n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1509 |
rem -= n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1510 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1511 |
if (rem == 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1512 |
close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1513 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1514 |
return (int)n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1515 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1516 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1517 |
public int read() throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1518 |
byte[] b = new byte[1]; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1519 |
if (read(b, 0, 1) == 1) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1520 |
return b[0] & 0xff; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1521 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1522 |
return -1; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1523 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1524 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1525 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1526 |
public long skip(long n) throws IOException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1527 |
ensureOpen(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1528 |
if (n > rem) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1529 |
n = rem; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1530 |
pos += n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1531 |
rem -= n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1532 |
if (rem == 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1533 |
close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1534 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1535 |
return n; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1536 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1537 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1538 |
public int available() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1539 |
return rem > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) rem; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1540 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1541 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1542 |
public long size() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1543 |
return size; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1544 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1545 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1546 |
public void close() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1547 |
rem = 0; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1548 |
streams.remove(this); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1549 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1550 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1551 |
private void initDataPos() throws IOException { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1552 |
if (pos <= 0) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1553 |
pos = -pos + locpos; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1554 |
byte[] buf = new byte[LOCHDR]; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1555 |
if (readFullyAt(buf, 0, buf.length, pos) != LOCHDR) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1556 |
throw new ZipException("invalid loc " + pos + " for entry reading"); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1557 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1558 |
pos += LOCHDR + LOCNAM(buf) + LOCEXT(buf); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1559 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1560 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1561 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1562 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1563 |
class EntryOutputStream extends DeflaterOutputStream |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1564 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1565 |
private CRC32 crc; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1566 |
private Entry e; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1567 |
private long written; |
28561
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1568 |
private boolean isClosed = false; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1569 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1570 |
EntryOutputStream(Entry e, OutputStream os) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1571 |
throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1572 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1573 |
super(os, getDeflater()); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1574 |
if (e == null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1575 |
throw new NullPointerException("Zip entry is null"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1576 |
this.e = e; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1577 |
crc = new CRC32(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1578 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1579 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1580 |
@Override |
28561
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1581 |
public synchronized void write(byte b[], int off, int len) |
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1582 |
throws IOException |
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1583 |
{ |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1584 |
if (e.type != Entry.FILECH) // only from sync |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1585 |
ensureOpen(); |
28561
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1586 |
if (isClosed) { |
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1587 |
throw new IOException("Stream closed"); |
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1588 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1589 |
if (off < 0 || len < 0 || off > b.length - len) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1590 |
throw new IndexOutOfBoundsException(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1591 |
} else if (len == 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1592 |
return; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1593 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1594 |
switch (e.method) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1595 |
case METHOD_DEFLATED: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1596 |
super.write(b, off, len); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1597 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1598 |
case METHOD_STORED: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1599 |
written += len; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1600 |
out.write(b, off, len); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1601 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1602 |
default: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1603 |
throw new ZipException("invalid compression method"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1604 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1605 |
crc.update(b, off, len); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1606 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1607 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1608 |
@Override |
28561
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1609 |
public synchronized void close() throws IOException { |
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1610 |
if (isClosed) { |
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1611 |
return; |
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1612 |
} |
bdb3c1d3a975
8069211: (zipfs) ZipFileSystem creates corrupted zip if entry output stream gets closed more than once
sherman
parents:
25859
diff
changeset
|
1613 |
isClosed = true; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1614 |
// TBD ensureOpen(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1615 |
switch (e.method) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1616 |
case METHOD_DEFLATED: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1617 |
finish(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1618 |
e.size = def.getBytesRead(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1619 |
e.csize = def.getBytesWritten(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1620 |
e.crc = crc.getValue(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1621 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1622 |
case METHOD_STORED: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1623 |
// we already know that both e.size and e.csize are the same |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1624 |
e.size = e.csize = written; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1625 |
e.crc = crc.getValue(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1626 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1627 |
default: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1628 |
throw new ZipException("invalid compression method"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1629 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1630 |
//crc.reset(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1631 |
if (out instanceof ByteArrayOutputStream) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1632 |
e.bytes = ((ByteArrayOutputStream)out).toByteArray(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1633 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1634 |
if (e.type == Entry.FILECH) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1635 |
releaseDeflater(def); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1636 |
return; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1637 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1638 |
super.close(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1639 |
releaseDeflater(def); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1640 |
update(e); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1641 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1642 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1643 |
|
28562
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
1644 |
static void zerror(String msg) throws ZipException { |
a3e34b364d38
8037394: ZipFileSystem leaks file descriptor when file is not a valid zip file
sherman
parents:
28561
diff
changeset
|
1645 |
throw new ZipException(msg); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1646 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1647 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1648 |
// Maxmum number of de/inflater we cache |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1649 |
private final int MAX_FLATER = 20; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1650 |
// List of available Inflater objects for decompression |
7189 | 1651 |
private final List<Inflater> inflaters = new ArrayList<>(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1652 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1653 |
// Gets an inflater from the list of available inflaters or allocates |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1654 |
// a new one. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1655 |
private Inflater getInflater() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1656 |
synchronized (inflaters) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1657 |
int size = inflaters.size(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1658 |
if (size > 0) { |
11841
38a39c748880
7143230: fix warnings in java.util.jar, sun.tools.jar, zipfs demo, etc.
smarks
parents:
10373
diff
changeset
|
1659 |
Inflater inf = inflaters.remove(size - 1); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1660 |
return inf; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1661 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1662 |
return new Inflater(true); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1663 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1664 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1665 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1666 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1667 |
// Releases the specified inflater to the list of available inflaters. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1668 |
private void releaseInflater(Inflater inf) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1669 |
synchronized (inflaters) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1670 |
if (inflaters.size() < MAX_FLATER) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1671 |
inf.reset(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1672 |
inflaters.add(inf); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1673 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1674 |
inf.end(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1675 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1676 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1677 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1678 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1679 |
// List of available Deflater objects for compression |
7189 | 1680 |
private final List<Deflater> deflaters = new ArrayList<>(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1681 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1682 |
// Gets an deflater from the list of available deflaters or allocates |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1683 |
// a new one. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1684 |
private Deflater getDeflater() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1685 |
synchronized (deflaters) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1686 |
int size = deflaters.size(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1687 |
if (size > 0) { |
11841
38a39c748880
7143230: fix warnings in java.util.jar, sun.tools.jar, zipfs demo, etc.
smarks
parents:
10373
diff
changeset
|
1688 |
Deflater def = deflaters.remove(size - 1); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1689 |
return def; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1690 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1691 |
return new Deflater(Deflater.DEFAULT_COMPRESSION, true); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1692 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1693 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1694 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1695 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1696 |
// Releases the specified inflater to the list of available inflaters. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1697 |
private void releaseDeflater(Deflater def) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1698 |
synchronized (deflaters) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1699 |
if (inflaters.size() < MAX_FLATER) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1700 |
def.reset(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1701 |
deflaters.add(def); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1702 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1703 |
def.end(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1704 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1705 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1706 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1707 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1708 |
// End of central directory record |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1709 |
static class END { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1710 |
// these 2 fields are not used by anyone and write() uses "0" |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1711 |
// int disknum; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1712 |
// int sdisknum; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1713 |
int endsub; // endsub |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1714 |
int centot; // 4 bytes |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1715 |
long cenlen; // 4 bytes |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1716 |
long cenoff; // 4 bytes |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1717 |
int comlen; // comment length |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1718 |
byte[] comment; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1719 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1720 |
/* members of Zip64 end of central directory locator */ |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1721 |
// int diskNum; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1722 |
long endpos; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1723 |
// int disktot; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1724 |
|
47223
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1725 |
void write(OutputStream os, long offset, boolean forceEnd64) throws IOException { |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1726 |
boolean hasZip64 = forceEnd64; // false; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1727 |
long xlen = cenlen; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1728 |
long xoff = cenoff; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1729 |
if (xlen >= ZIP64_MINVAL) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1730 |
xlen = ZIP64_MINVAL; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1731 |
hasZip64 = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1732 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1733 |
if (xoff >= ZIP64_MINVAL) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1734 |
xoff = ZIP64_MINVAL; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1735 |
hasZip64 = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1736 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1737 |
int count = centot; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1738 |
if (count >= ZIP64_MINVAL32) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1739 |
count = ZIP64_MINVAL32; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1740 |
hasZip64 = true; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1741 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1742 |
if (hasZip64) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1743 |
long off64 = offset; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1744 |
//zip64 end of central directory record |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1745 |
writeInt(os, ZIP64_ENDSIG); // zip64 END record signature |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1746 |
writeLong(os, ZIP64_ENDHDR - 12); // size of zip64 end |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1747 |
writeShort(os, 45); // version made by |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1748 |
writeShort(os, 45); // version needed to extract |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1749 |
writeInt(os, 0); // number of this disk |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1750 |
writeInt(os, 0); // central directory start disk |
47223
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1751 |
writeLong(os, centot); // number of directory entries on disk |
723486922bfe
8186464: ZipFile cannot read some InfoZip ZIP64 zip files
sherman
parents:
47216
diff
changeset
|
1752 |
writeLong(os, centot); // number of directory entries |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1753 |
writeLong(os, cenlen); // length of central directory |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1754 |
writeLong(os, cenoff); // offset of central directory |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1755 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1756 |
//zip64 end of central directory locator |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1757 |
writeInt(os, ZIP64_LOCSIG); // zip64 END locator signature |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1758 |
writeInt(os, 0); // zip64 END start disk |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1759 |
writeLong(os, off64); // offset of zip64 END |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1760 |
writeInt(os, 1); // total number of disks (?) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1761 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1762 |
writeInt(os, ENDSIG); // END record signature |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1763 |
writeShort(os, 0); // number of this disk |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1764 |
writeShort(os, 0); // central directory start disk |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1765 |
writeShort(os, count); // number of directory entries on disk |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1766 |
writeShort(os, count); // total number of directory entries |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1767 |
writeInt(os, xlen); // length of central directory |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1768 |
writeInt(os, xoff); // offset of central directory |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1769 |
if (comment != null) { // zip file comment |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1770 |
writeShort(os, comment.length); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1771 |
writeBytes(os, comment); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1772 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1773 |
writeShort(os, 0); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1774 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1775 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1776 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1777 |
|
7189 | 1778 |
// Internal node that links a "name" to its pos in cen table. |
1779 |
// The node itself can be used as a "key" to lookup itself in |
|
1780 |
// the HashMap inodes. |
|
1781 |
static class IndexNode { |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1782 |
byte[] name; |
7189 | 1783 |
int hashcode; // node is hashable/hashed by its name |
21278 | 1784 |
int pos = -1; // position in cen table, -1 menas the |
7189 | 1785 |
// entry does not exists in zip file |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1786 |
boolean isdir; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1787 |
|
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1788 |
IndexNode(byte[] name, boolean isdir) { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1789 |
name(name); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1790 |
this.isdir = isdir; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1791 |
this.pos = -1; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1792 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1793 |
|
7189 | 1794 |
IndexNode(byte[] name, int pos) { |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1795 |
name(name); |
7189 | 1796 |
this.pos = pos; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1797 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1798 |
|
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1799 |
// constructor for cenInit() |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1800 |
IndexNode(byte[] cen, int noff, int nlen, int pos) { |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1801 |
if (cen[noff + nlen - 1] == '/') { |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1802 |
isdir = true; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1803 |
nlen--; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1804 |
} |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1805 |
name = new byte[nlen + 1]; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1806 |
System.arraycopy(cen, pos + CENHDR, name, 1, nlen); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1807 |
name[0] = '/'; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1808 |
name(name); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1809 |
this.pos = pos; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1810 |
} |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1811 |
|
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1812 |
private static final ThreadLocal<IndexNode> cachedKey = new ThreadLocal<>(); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1813 |
|
7189 | 1814 |
final static IndexNode keyOf(byte[] name) { // get a lookup key; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1815 |
IndexNode key = cachedKey.get(); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1816 |
if (key == null) { |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1817 |
key = new IndexNode(name, -1); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1818 |
cachedKey.set(key); |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1819 |
} |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1820 |
return key.as(name); |
7189 | 1821 |
} |
1822 |
||
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1823 |
final void name(byte[] name) { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1824 |
this.name = name; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1825 |
this.hashcode = Arrays.hashCode(name); |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1826 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1827 |
|
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1828 |
final IndexNode as(byte[] name) { // reuse the node, mostly |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1829 |
name(name); // as a lookup "key" |
7189 | 1830 |
return this; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1831 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1832 |
|
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1833 |
boolean isDir() { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1834 |
return isdir; |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1835 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1836 |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1837 |
public boolean equals(Object other) { |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1838 |
if (!(other instanceof IndexNode)) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1839 |
return false; |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1840 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1841 |
if (other instanceof ParentLookup) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1842 |
return ((ParentLookup)other).equals(this); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1843 |
} |
7189 | 1844 |
return Arrays.equals(name, ((IndexNode)other).name); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1845 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1846 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1847 |
public int hashCode() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1848 |
return hashcode; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1849 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1850 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1851 |
IndexNode() {} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1852 |
IndexNode sibling; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1853 |
IndexNode child; // 1st child |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1854 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1855 |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1856 |
static class Entry extends IndexNode implements ZipFileAttributes { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1857 |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1858 |
static final int CEN = 1; // entry read from cen |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1859 |
static final int NEW = 2; // updated contents in bytes or file |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1860 |
static final int FILECH = 3; // fch update in "file" |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1861 |
static final int COPY = 4; // copy of a CEN entry |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1862 |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1863 |
byte[] bytes; // updated content bytes |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1864 |
Path file; // use tmp file to store bytes; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1865 |
int type = CEN; // default is the entry read from cen |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1866 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1867 |
// entry attributes |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1868 |
int version; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1869 |
int flag; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1870 |
int method = -1; // compression method |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1871 |
long mtime = -1; // last modification time (in DOS time) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1872 |
long atime = -1; // last access time |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1873 |
long ctime = -1; // create time |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1874 |
long crc = -1; // crc-32 of entry data |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1875 |
long csize = -1; // compressed size of entry data |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1876 |
long size = -1; // uncompressed size of entry data |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1877 |
byte[] extra; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1878 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1879 |
// cen |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1880 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1881 |
// these fields are not used by anyone and writeCEN uses "0" |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1882 |
// int versionMade; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1883 |
// int disk; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1884 |
// int attrs; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1885 |
// long attrsEx; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1886 |
long locoff; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1887 |
byte[] comment; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1888 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1889 |
Entry() {} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1890 |
|
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1891 |
Entry(byte[] name, boolean isdir) { |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1892 |
name(name); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1893 |
this.isdir = isdir; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
1894 |
this.mtime = this.ctime = this.atime = System.currentTimeMillis(); |
7189 | 1895 |
this.crc = 0; |
1896 |
this.size = 0; |
|
1897 |
this.csize = 0; |
|
1898 |
this.method = METHOD_DEFLATED; |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1899 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1900 |
|
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1901 |
Entry(byte[] name, int type, boolean isdir) { |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1902 |
this(name, isdir); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1903 |
this.type = type; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1904 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1905 |
|
7189 | 1906 |
Entry (Entry e, int type) { |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
1907 |
name(e.name); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1908 |
this.isdir = e.isdir; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1909 |
this.version = e.version; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1910 |
this.ctime = e.ctime; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1911 |
this.atime = e.atime; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1912 |
this.mtime = e.mtime; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1913 |
this.crc = e.crc; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1914 |
this.size = e.size; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1915 |
this.csize = e.csize; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1916 |
this.method = e.method; |
7189 | 1917 |
this.extra = e.extra; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1918 |
/* |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1919 |
this.versionMade = e.versionMade; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1920 |
this.disk = e.disk; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1921 |
this.attrs = e.attrs; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1922 |
this.attrsEx = e.attrsEx; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1923 |
*/ |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1924 |
this.locoff = e.locoff; |
7189 | 1925 |
this.comment = e.comment; |
1926 |
this.type = type; |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1927 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1928 |
|
7189 | 1929 |
Entry (byte[] name, Path file, int type) { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1930 |
this(name, type, false); |
7189 | 1931 |
this.file = file; |
1932 |
this.method = METHOD_STORED; |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1933 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1934 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1935 |
int version() throws ZipException { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1936 |
if (method == METHOD_DEFLATED) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1937 |
return 20; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1938 |
else if (method == METHOD_STORED) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1939 |
return 10; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1940 |
throw new ZipException("unsupported compression method"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1941 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1942 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1943 |
///////////////////// CEN ////////////////////// |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1944 |
static Entry readCEN(ZipFileSystem zipfs, IndexNode inode) |
7189 | 1945 |
throws IOException |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1946 |
{ |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1947 |
return new Entry().cen(zipfs, inode); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1948 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1949 |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1950 |
private Entry cen(ZipFileSystem zipfs, IndexNode inode) |
7189 | 1951 |
throws IOException |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1952 |
{ |
7189 | 1953 |
byte[] cen = zipfs.cen; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1954 |
int pos = inode.pos; |
29714
afac043e9bf0
8075774: Small readability and performance improvements for zipfs
martin
parents:
29270
diff
changeset
|
1955 |
if (!cenSigAt(cen, pos)) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1956 |
zerror("invalid CEN header (bad signature)"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1957 |
version = CENVER(cen, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1958 |
flag = CENFLG(cen, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1959 |
method = CENHOW(cen, pos); |
7189 | 1960 |
mtime = dosToJavaTime(CENTIM(cen, pos)); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1961 |
crc = CENCRC(cen, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1962 |
csize = CENSIZ(cen, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1963 |
size = CENLEN(cen, pos); |
7189 | 1964 |
int nlen = CENNAM(cen, pos); |
1965 |
int elen = CENEXT(cen, pos); |
|
1966 |
int clen = CENCOM(cen, pos); |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1967 |
/* |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1968 |
versionMade = CENVEM(cen, pos); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1969 |
disk = CENDSK(cen, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1970 |
attrs = CENATT(cen, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1971 |
attrsEx = CENATX(cen, pos); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1972 |
*/ |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1973 |
locoff = CENOFF(cen, pos); |
7189 | 1974 |
pos += CENHDR; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1975 |
this.name = inode.name; |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
1976 |
this.isdir = inode.isdir; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
1977 |
this.hashcode = inode.hashcode; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1978 |
|
7189 | 1979 |
pos += nlen; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1980 |
if (elen > 0) { |
7189 | 1981 |
extra = Arrays.copyOfRange(cen, pos, pos + elen); |
1982 |
pos += elen; |
|
1983 |
readExtra(zipfs); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1984 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1985 |
if (clen > 0) { |
7189 | 1986 |
comment = Arrays.copyOfRange(cen, pos, pos + clen); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1987 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1988 |
return this; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1989 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1990 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1991 |
int writeCEN(OutputStream os) throws IOException |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1992 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1993 |
int written = CENHDR; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1994 |
int version0 = version(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1995 |
long csize0 = csize; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1996 |
long size0 = size; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1997 |
long locoff0 = locoff; |
7189 | 1998 |
int elen64 = 0; // extra for ZIP64 |
1999 |
int elenNTFS = 0; // extra for NTFS (a/c/mtime) |
|
2000 |
int elenEXTT = 0; // extra for Extended Timestamp |
|
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2001 |
boolean foundExtraTime = false; // if time stamp NTFS, EXTT present |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2002 |
|
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2003 |
byte[] zname = isdir ? toDirectoryPath(name) : name; |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2004 |
|
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2005 |
// confirm size/length |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2006 |
int nlen = (zname != null) ? zname.length - 1 : 0; // name has [0] as "slash" |
7189 | 2007 |
int elen = (extra != null) ? extra.length : 0; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2008 |
int eoff = 0; |
7189 | 2009 |
int clen = (comment != null) ? comment.length : 0; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2010 |
if (csize >= ZIP64_MINVAL) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2011 |
csize0 = ZIP64_MINVAL; |
7189 | 2012 |
elen64 += 8; // csize(8) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2013 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2014 |
if (size >= ZIP64_MINVAL) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2015 |
size0 = ZIP64_MINVAL; // size(8) |
7189 | 2016 |
elen64 += 8; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2017 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2018 |
if (locoff >= ZIP64_MINVAL) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2019 |
locoff0 = ZIP64_MINVAL; |
7189 | 2020 |
elen64 += 8; // offset(8) |
2021 |
} |
|
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2022 |
if (elen64 != 0) { |
7189 | 2023 |
elen64 += 4; // header and data sz 4 bytes |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2024 |
} |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2025 |
while (eoff + 4 < elen) { |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2026 |
int tag = SH(extra, eoff); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2027 |
int sz = SH(extra, eoff + 2); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2028 |
if (tag == EXTID_EXTT || tag == EXTID_NTFS) { |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2029 |
foundExtraTime = true; |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2030 |
} |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2031 |
eoff += (4 + sz); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2032 |
} |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2033 |
if (!foundExtraTime) { |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2034 |
if (isWindows) { // use NTFS |
7189 | 2035 |
elenNTFS = 36; // total 36 bytes |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2036 |
} else { // Extended Timestamp otherwise |
7189 | 2037 |
elenEXTT = 9; // only mtime in cen |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2038 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2039 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2040 |
writeInt(os, CENSIG); // CEN header signature |
7189 | 2041 |
if (elen64 != 0) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2042 |
writeShort(os, 45); // ver 4.5 for zip64 |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2043 |
writeShort(os, 45); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2044 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2045 |
writeShort(os, version0); // version made by |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2046 |
writeShort(os, version0); // version needed to extract |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2047 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2048 |
writeShort(os, flag); // general purpose bit flag |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2049 |
writeShort(os, method); // compression method |
7189 | 2050 |
// last modification time |
2051 |
writeInt(os, (int)javaToDosTime(mtime)); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2052 |
writeInt(os, crc); // crc-32 |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2053 |
writeInt(os, csize0); // compressed size |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2054 |
writeInt(os, size0); // uncompressed size |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2055 |
writeShort(os, nlen); |
7189 | 2056 |
writeShort(os, elen + elen64 + elenNTFS + elenEXTT); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2057 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2058 |
if (comment != null) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2059 |
writeShort(os, Math.min(clen, 0xffff)); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2060 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2061 |
writeShort(os, 0); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2062 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2063 |
writeShort(os, 0); // starting disk number |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2064 |
writeShort(os, 0); // internal file attributes (unused) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2065 |
writeInt(os, 0); // external file attributes (unused) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2066 |
writeInt(os, locoff0); // relative offset of local header |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2067 |
writeBytes(os, zname, 1, nlen); |
7189 | 2068 |
if (elen64 != 0) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2069 |
writeShort(os, EXTID_ZIP64);// Zip64 extra |
10365
8a89ee820687
7077769: (zipfs) ZipFileSystem.writeCEN() writes wrong "data size" for ZIP64 extended information extra field
sherman
parents:
9035
diff
changeset
|
2070 |
writeShort(os, elen64 - 4); // size of "this" extra block |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2071 |
if (size0 == ZIP64_MINVAL) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2072 |
writeLong(os, size); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2073 |
if (csize0 == ZIP64_MINVAL) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2074 |
writeLong(os, csize); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2075 |
if (locoff0 == ZIP64_MINVAL) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2076 |
writeLong(os, locoff); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2077 |
} |
7189 | 2078 |
if (elenNTFS != 0) { |
2079 |
writeShort(os, EXTID_NTFS); |
|
2080 |
writeShort(os, elenNTFS - 4); |
|
2081 |
writeInt(os, 0); // reserved |
|
2082 |
writeShort(os, 0x0001); // NTFS attr tag |
|
2083 |
writeShort(os, 24); |
|
2084 |
writeLong(os, javaToWinTime(mtime)); |
|
2085 |
writeLong(os, javaToWinTime(atime)); |
|
2086 |
writeLong(os, javaToWinTime(ctime)); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2087 |
} |
7189 | 2088 |
if (elenEXTT != 0) { |
2089 |
writeShort(os, EXTID_EXTT); |
|
2090 |
writeShort(os, elenEXTT - 4); |
|
2091 |
if (ctime == -1) |
|
2092 |
os.write(0x3); // mtime and atime |
|
2093 |
else |
|
2094 |
os.write(0x7); // mtime, atime and ctime |
|
2095 |
writeInt(os, javaToUnixTime(mtime)); |
|
2096 |
} |
|
2097 |
if (extra != null) // whatever not recognized |
|
2098 |
writeBytes(os, extra); |
|
2099 |
if (comment != null) //TBD: 0, Math.min(commentBytes.length, 0xffff)); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2100 |
writeBytes(os, comment); |
7189 | 2101 |
return CENHDR + nlen + elen + clen + elen64 + elenNTFS + elenEXTT; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2102 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2103 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2104 |
///////////////////// LOC ////////////////////// |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2105 |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2106 |
int writeLOC(OutputStream os) throws IOException { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2107 |
writeInt(os, LOCSIG); // LOC header signature |
7189 | 2108 |
int version = version(); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2109 |
|
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2110 |
byte[] zname = isdir ? toDirectoryPath(name) : name; |
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2111 |
int nlen = (zname != null) ? zname.length - 1 : 0; // [0] is slash |
7189 | 2112 |
int elen = (extra != null) ? extra.length : 0; |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2113 |
boolean foundExtraTime = false; // if extra timestamp present |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2114 |
int eoff = 0; |
7189 | 2115 |
int elen64 = 0; |
2116 |
int elenEXTT = 0; |
|
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2117 |
int elenNTFS = 0; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2118 |
if ((flag & FLAG_DATADESCR) != 0) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2119 |
writeShort(os, version()); // version needed to extract |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2120 |
writeShort(os, flag); // general purpose bit flag |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2121 |
writeShort(os, method); // compression method |
7189 | 2122 |
// last modification time |
2123 |
writeInt(os, (int)javaToDosTime(mtime)); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2124 |
// store size, uncompressed size, and crc-32 in data descriptor |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2125 |
// immediately following compressed entry data |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2126 |
writeInt(os, 0); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2127 |
writeInt(os, 0); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2128 |
writeInt(os, 0); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2129 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2130 |
if (csize >= ZIP64_MINVAL || size >= ZIP64_MINVAL) { |
7189 | 2131 |
elen64 = 20; //headid(2) + size(2) + size(8) + csize(8) |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2132 |
writeShort(os, 45); // ver 4.5 for zip64 |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2133 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2134 |
writeShort(os, version()); // version needed to extract |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2135 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2136 |
writeShort(os, flag); // general purpose bit flag |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2137 |
writeShort(os, method); // compression method |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2138 |
// last modification time |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2139 |
writeInt(os, (int)javaToDosTime(mtime)); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2140 |
writeInt(os, crc); // crc-32 |
7189 | 2141 |
if (elen64 != 0) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2142 |
writeInt(os, ZIP64_MINVAL); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2143 |
writeInt(os, ZIP64_MINVAL); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2144 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2145 |
writeInt(os, csize); // compressed size |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2146 |
writeInt(os, size); // uncompressed size |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2147 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2148 |
} |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2149 |
while (eoff + 4 < elen) { |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2150 |
int tag = SH(extra, eoff); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2151 |
int sz = SH(extra, eoff + 2); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2152 |
if (tag == EXTID_EXTT || tag == EXTID_NTFS) { |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2153 |
foundExtraTime = true; |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2154 |
} |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2155 |
eoff += (4 + sz); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2156 |
} |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2157 |
if (!foundExtraTime) { |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2158 |
if (isWindows) { |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2159 |
elenNTFS = 36; // NTFS, total 36 bytes |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2160 |
} else { // on unix use "ext time" |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2161 |
elenEXTT = 9; |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2162 |
if (atime != -1) |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2163 |
elenEXTT += 4; |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2164 |
if (ctime != -1) |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2165 |
elenEXTT += 4; |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2166 |
} |
7189 | 2167 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2168 |
writeShort(os, nlen); |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2169 |
writeShort(os, elen + elen64 + elenNTFS + elenEXTT); |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2170 |
writeBytes(os, zname, 1, nlen); |
7189 | 2171 |
if (elen64 != 0) { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2172 |
writeShort(os, EXTID_ZIP64); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2173 |
writeShort(os, 16); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2174 |
writeLong(os, size); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2175 |
writeLong(os, csize); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2176 |
} |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2177 |
if (elenNTFS != 0) { |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2178 |
writeShort(os, EXTID_NTFS); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2179 |
writeShort(os, elenNTFS - 4); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2180 |
writeInt(os, 0); // reserved |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2181 |
writeShort(os, 0x0001); // NTFS attr tag |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2182 |
writeShort(os, 24); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2183 |
writeLong(os, javaToWinTime(mtime)); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2184 |
writeLong(os, javaToWinTime(atime)); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2185 |
writeLong(os, javaToWinTime(ctime)); |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2186 |
} |
7189 | 2187 |
if (elenEXTT != 0) { |
2188 |
writeShort(os, EXTID_EXTT); |
|
2189 |
writeShort(os, elenEXTT - 4);// size for the folowing data block |
|
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2190 |
int fbyte = 0x1; |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2191 |
if (atime != -1) // mtime and atime |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2192 |
fbyte |= 0x2; |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2193 |
if (ctime != -1) // mtime, atime and ctime |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2194 |
fbyte |= 0x4; |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2195 |
os.write(fbyte); // flags byte |
7189 | 2196 |
writeInt(os, javaToUnixTime(mtime)); |
17910
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2197 |
if (atime != -1) |
82d10099a8a6
4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents:
17699
diff
changeset
|
2198 |
writeInt(os, javaToUnixTime(atime)); |
7189 | 2199 |
if (ctime != -1) |
2200 |
writeInt(os, javaToUnixTime(ctime)); |
|
2201 |
} |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2202 |
if (extra != null) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2203 |
writeBytes(os, extra); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2204 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2205 |
return LOCHDR + nlen + elen + elen64 + elenNTFS + elenEXTT; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2206 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2207 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2208 |
// Data Descriptior |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2209 |
int writeEXT(OutputStream os) throws IOException { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2210 |
writeInt(os, EXTSIG); // EXT header signature |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2211 |
writeInt(os, crc); // crc-32 |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2212 |
if (csize >= ZIP64_MINVAL || size >= ZIP64_MINVAL) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2213 |
writeLong(os, csize); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2214 |
writeLong(os, size); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2215 |
return 24; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2216 |
} else { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2217 |
writeInt(os, csize); // compressed size |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2218 |
writeInt(os, size); // uncompressed size |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2219 |
return 16; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2220 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2221 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2222 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2223 |
// read NTFS, UNIX and ZIP64 data from cen.extra |
7189 | 2224 |
void readExtra(ZipFileSystem zipfs) throws IOException { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2225 |
if (extra == null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2226 |
return; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2227 |
int elen = extra.length; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2228 |
int off = 0; |
7189 | 2229 |
int newOff = 0; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2230 |
while (off + 4 < elen) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2231 |
// extra spec: HeaderID+DataSize+Data |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2232 |
int pos = off; |
7189 | 2233 |
int tag = SH(extra, pos); |
2234 |
int sz = SH(extra, pos + 2); |
|
2235 |
pos += 4; |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2236 |
if (pos + sz > elen) // invalid data |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2237 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2238 |
switch (tag) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2239 |
case EXTID_ZIP64 : |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2240 |
if (size == ZIP64_MINVAL) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2241 |
if (pos + 8 > elen) // invalid zip64 extra |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2242 |
break; // fields, just skip |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2243 |
size = LL(extra, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2244 |
pos += 8; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2245 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2246 |
if (csize == ZIP64_MINVAL) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2247 |
if (pos + 8 > elen) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2248 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2249 |
csize = LL(extra, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2250 |
pos += 8; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2251 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2252 |
if (locoff == ZIP64_MINVAL) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2253 |
if (pos + 8 > elen) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2254 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2255 |
locoff = LL(extra, pos); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2256 |
pos += 8; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2257 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2258 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2259 |
case EXTID_NTFS: |
29815
a50c9d80a80f
8076641: getNextEntry throws ArrayIndexOutOfBoundsException when unzipping file
sherman
parents:
29714
diff
changeset
|
2260 |
if (sz < 32) |
a50c9d80a80f
8076641: getNextEntry throws ArrayIndexOutOfBoundsException when unzipping file
sherman
parents:
29714
diff
changeset
|
2261 |
break; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2262 |
pos += 4; // reserved 4 bytes |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2263 |
if (SH(extra, pos) != 0x0001) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2264 |
break; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2265 |
if (SH(extra, pos + 2) != 24) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2266 |
break; |
7189 | 2267 |
// override the loc field, datatime here is |
2268 |
// more "accurate" |
|
2269 |
mtime = winToJavaTime(LL(extra, pos + 4)); |
|
2270 |
atime = winToJavaTime(LL(extra, pos + 12)); |
|
2271 |
ctime = winToJavaTime(LL(extra, pos + 20)); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2272 |
break; |
7189 | 2273 |
case EXTID_EXTT: |
2274 |
// spec says the Extened timestamp in cen only has mtime |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2275 |
// need to read the loc to get the extra a/ctime, if flag |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2276 |
// "zipinfo-time" is not specified to false; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2277 |
// there is performance cost (move up to loc and read) to |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2278 |
// access the loc table foreach entry; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2279 |
if (zipfs.noExtt) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2280 |
if (sz == 5) |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2281 |
mtime = unixToJavaTime(LG(extra, pos + 1)); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2282 |
break; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2283 |
} |
7189 | 2284 |
byte[] buf = new byte[LOCHDR]; |
2285 |
if (zipfs.readFullyAt(buf, 0, buf.length , locoff) |
|
2286 |
!= buf.length) |
|
2287 |
throw new ZipException("loc: reading failed"); |
|
29714
afac043e9bf0
8075774: Small readability and performance improvements for zipfs
martin
parents:
29270
diff
changeset
|
2288 |
if (!locSigAt(buf, 0)) |
7189 | 2289 |
throw new ZipException("loc: wrong sig ->" |
29714
afac043e9bf0
8075774: Small readability and performance improvements for zipfs
martin
parents:
29270
diff
changeset
|
2290 |
+ Long.toString(getSig(buf, 0), 16)); |
7189 | 2291 |
int locElen = LOCEXT(buf); |
2292 |
if (locElen < 9) // EXTT is at lease 9 bytes |
|
2293 |
break; |
|
2294 |
int locNlen = LOCNAM(buf); |
|
2295 |
buf = new byte[locElen]; |
|
2296 |
if (zipfs.readFullyAt(buf, 0, buf.length , locoff + LOCHDR + locNlen) |
|
2297 |
!= buf.length) |
|
2298 |
throw new ZipException("loc extra: reading failed"); |
|
2299 |
int locPos = 0; |
|
2300 |
while (locPos + 4 < buf.length) { |
|
2301 |
int locTag = SH(buf, locPos); |
|
2302 |
int locSZ = SH(buf, locPos + 2); |
|
2303 |
locPos += 4; |
|
2304 |
if (locTag != EXTID_EXTT) { |
|
2305 |
locPos += locSZ; |
|
2306 |
continue; |
|
2307 |
} |
|
43224
355457152ea8
8173072: zipfs fails to handle incorrect info-zip "extended timestamp extra field"
sherman
parents:
43193
diff
changeset
|
2308 |
int end = locPos + locSZ - 4; |
7189 | 2309 |
int flag = CH(buf, locPos++); |
43224
355457152ea8
8173072: zipfs fails to handle incorrect info-zip "extended timestamp extra field"
sherman
parents:
43193
diff
changeset
|
2310 |
if ((flag & 0x1) != 0 && locPos <= end) { |
7189 | 2311 |
mtime = unixToJavaTime(LG(buf, locPos)); |
2312 |
locPos += 4; |
|
2313 |
} |
|
43224
355457152ea8
8173072: zipfs fails to handle incorrect info-zip "extended timestamp extra field"
sherman
parents:
43193
diff
changeset
|
2314 |
if ((flag & 0x2) != 0 && locPos <= end) { |
7189 | 2315 |
atime = unixToJavaTime(LG(buf, locPos)); |
2316 |
locPos += 4; |
|
2317 |
} |
|
43224
355457152ea8
8173072: zipfs fails to handle incorrect info-zip "extended timestamp extra field"
sherman
parents:
43193
diff
changeset
|
2318 |
if ((flag & 0x4) != 0 && locPos <= end) { |
7189 | 2319 |
ctime = unixToJavaTime(LG(buf, locPos)); |
2320 |
locPos += 4; |
|
2321 |
} |
|
2322 |
break; |
|
2323 |
} |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2324 |
break; |
7189 | 2325 |
default: // unknown tag |
2326 |
System.arraycopy(extra, off, extra, newOff, sz + 4); |
|
2327 |
newOff += (sz + 4); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2328 |
} |
7189 | 2329 |
off += (sz + 4); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2330 |
} |
7189 | 2331 |
if (newOff != 0 && newOff != extra.length) |
2332 |
extra = Arrays.copyOf(extra, newOff); |
|
2333 |
else |
|
2334 |
extra = null; |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2335 |
} |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2336 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2337 |
///////// basic file attributes /////////// |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2338 |
@Override |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2339 |
public FileTime creationTime() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2340 |
return FileTime.fromMillis(ctime == -1 ? mtime : ctime); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2341 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2342 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2343 |
@Override |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2344 |
public boolean isDirectory() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2345 |
return isDir(); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2346 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2347 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2348 |
@Override |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2349 |
public boolean isOther() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2350 |
return false; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2351 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2352 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2353 |
@Override |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2354 |
public boolean isRegularFile() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2355 |
return !isDir(); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2356 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2357 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2358 |
@Override |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2359 |
public FileTime lastAccessTime() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2360 |
return FileTime.fromMillis(atime == -1 ? mtime : atime); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2361 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2362 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2363 |
@Override |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2364 |
public FileTime lastModifiedTime() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2365 |
return FileTime.fromMillis(mtime); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2366 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2367 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2368 |
@Override |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2369 |
public long size() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2370 |
return size; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2371 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2372 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2373 |
@Override |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2374 |
public boolean isSymbolicLink() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2375 |
return false; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2376 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2377 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2378 |
@Override |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2379 |
public Object fileKey() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2380 |
return null; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2381 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2382 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2383 |
///////// zip entry attributes /////////// |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2384 |
public long compressedSize() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2385 |
return csize; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2386 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2387 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2388 |
public long crc() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2389 |
return crc; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2390 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2391 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2392 |
public int method() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2393 |
return method; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2394 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2395 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2396 |
public byte[] extra() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2397 |
if (extra != null) |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2398 |
return Arrays.copyOf(extra, extra.length); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2399 |
return null; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2400 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2401 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2402 |
public byte[] comment() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2403 |
if (comment != null) |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2404 |
return Arrays.copyOf(comment, comment.length); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2405 |
return null; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2406 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2407 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2408 |
public String toString() { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2409 |
StringBuilder sb = new StringBuilder(1024); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2410 |
Formatter fm = new Formatter(sb); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2411 |
fm.format(" creationTime : %tc%n", creationTime().toMillis()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2412 |
fm.format(" lastAccessTime : %tc%n", lastAccessTime().toMillis()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2413 |
fm.format(" lastModifiedTime: %tc%n", lastModifiedTime().toMillis()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2414 |
fm.format(" isRegularFile : %b%n", isRegularFile()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2415 |
fm.format(" isDirectory : %b%n", isDirectory()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2416 |
fm.format(" isSymbolicLink : %b%n", isSymbolicLink()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2417 |
fm.format(" isOther : %b%n", isOther()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2418 |
fm.format(" fileKey : %s%n", fileKey()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2419 |
fm.format(" size : %d%n", size()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2420 |
fm.format(" compressedSize : %d%n", compressedSize()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2421 |
fm.format(" crc : %x%n", crc()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2422 |
fm.format(" method : %d%n", method()); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2423 |
fm.close(); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2424 |
return sb.toString(); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2425 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2426 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2427 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2428 |
private static class ExChannelCloser { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2429 |
Path path; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2430 |
SeekableByteChannel ch; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2431 |
Set<InputStream> streams; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2432 |
ExChannelCloser(Path path, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2433 |
SeekableByteChannel ch, |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2434 |
Set<InputStream> streams) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2435 |
{ |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2436 |
this.path = path; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2437 |
this.ch = ch; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2438 |
this.streams = streams; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2439 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2440 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2441 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2442 |
// ZIP directory has two issues: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2443 |
// (1) ZIP spec does not require the ZIP file to include |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2444 |
// directory entry |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2445 |
// (2) all entries are not stored/organized in a "tree" |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2446 |
// structure. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2447 |
// A possible solution is to build the node tree ourself as |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2448 |
// implemented below. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2449 |
private IndexNode root; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2450 |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2451 |
// default time stamp for pseudo entries |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2452 |
private long zfsDefaultTimeStamp = System.currentTimeMillis(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2453 |
|
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2454 |
private void removeFromTree(IndexNode inode) { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2455 |
IndexNode parent = inodes.get(LOOKUPKEY.as(getParent(inode.name))); |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2456 |
IndexNode child = parent.child; |
16857
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
14342
diff
changeset
|
2457 |
if (child.equals(inode)) { |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2458 |
parent.child = child.sibling; |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2459 |
} else { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2460 |
IndexNode last = child; |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2461 |
while ((child = child.sibling) != null) { |
16857
1e094a236e0e
8002390: (zipfs) Problems moving files between zip file systems
sherman
parents:
14342
diff
changeset
|
2462 |
if (child.equals(inode)) { |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2463 |
last.sibling = child.sibling; |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2464 |
break; |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2465 |
} else { |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2466 |
last = child; |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2467 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2468 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2469 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2470 |
} |
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2471 |
|
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2472 |
// purely for parent lookup, so we don't have to copy the parent |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2473 |
// name every time |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2474 |
static class ParentLookup extends IndexNode { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2475 |
int len; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2476 |
ParentLookup() {} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2477 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2478 |
final ParentLookup as(byte[] name, int len) { // as a lookup "key" |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2479 |
name(name, len); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2480 |
return this; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2481 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2482 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2483 |
void name(byte[] name, int len) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2484 |
this.name = name; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2485 |
this.len = len; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2486 |
// calculate the hashcode the same way as Arrays.hashCode() does |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2487 |
int result = 1; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2488 |
for (int i = 0; i < len; i++) |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2489 |
result = 31 * result + name[i]; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2490 |
this.hashcode = result; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2491 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2492 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2493 |
@Override |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2494 |
public boolean equals(Object other) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2495 |
if (!(other instanceof IndexNode)) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2496 |
return false; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2497 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2498 |
byte[] oname = ((IndexNode)other).name; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2499 |
return Arrays.equals(name, 0, len, |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2500 |
oname, 0, oname.length); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2501 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2502 |
|
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2503 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2504 |
|
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2505 |
private void buildNodeTree() throws IOException { |
7189 | 2506 |
beginWrite(); |
2507 |
try { |
|
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2508 |
IndexNode root = new IndexNode(ROOTPATH, true); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2509 |
IndexNode[] nodes = inodes.keySet().toArray(new IndexNode[0]); |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2510 |
inodes.put(root, root); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2511 |
ParentLookup lookup = new ParentLookup(); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2512 |
for (IndexNode node : nodes) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2513 |
IndexNode parent; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2514 |
while (true) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2515 |
int off = getParentOff(node.name); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2516 |
if (off <= 1) { // parent is root |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2517 |
node.sibling = root.child; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2518 |
root.child = node; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2519 |
break; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2520 |
} |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2521 |
lookup = lookup.as(node.name, off); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2522 |
if (inodes.containsKey(lookup)) { |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2523 |
parent = inodes.get(lookup); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2524 |
node.sibling = parent.child; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2525 |
parent.child = node; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2526 |
break; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2527 |
} |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2528 |
// add new pseudo directory entry |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
38769
diff
changeset
|
2529 |
parent = new IndexNode(Arrays.copyOf(node.name, off), true); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2530 |
inodes.put(parent, parent); |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2531 |
node.sibling = parent.child; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2532 |
parent.child = node; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2533 |
node = parent; |
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
34835
diff
changeset
|
2534 |
} |
8005
5bc99c45810a
7006576: (zipfs) Path.exists() always returns false on dirs when zip/JAR file built without dirs
sherman
parents:
7531
diff
changeset
|
2535 |
} |
7189 | 2536 |
} finally { |
2537 |
endWrite(); |
|
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2538 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2539 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2540 |
} |