author | ssadetsky |
Wed, 03 Apr 2019 15:40:23 -0700 | |
branch | JDK-8200758-branch |
changeset 57302 | 3506e9694603 |
parent 53043 | fd2e8f941ded |
child 54920 | 6a6935abebe8 |
permissions | -rw-r--r-- |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1 |
/* |
53043
fd2e8f941ded
8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
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:
14342
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:
14342
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:
14342
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:
14342
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:
14342
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:
14342
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:
14342
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:
14342
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:
14342
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:
14342
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:
14342
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:
14342
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:
14342
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:
14342
diff
changeset
|
20 |
* |
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
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:
14342
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:
14342
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:
14342
diff
changeset
|
26 |
package jdk.nio.zipfs; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
27 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
28 |
import java.io.IOException; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
29 |
import java.nio.file.FileStore; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
30 |
import java.nio.file.FileSystems; |
53043
fd2e8f941ded
8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents:
47216
diff
changeset
|
31 |
import java.nio.file.Files; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
32 |
import java.nio.file.Path; |
53043
fd2e8f941ded
8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents:
47216
diff
changeset
|
33 |
import java.nio.file.attribute.BasicFileAttributeView; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
34 |
import java.nio.file.attribute.FileAttributeView; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
35 |
import java.nio.file.attribute.FileStoreAttributeView; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
36 |
|
53043
fd2e8f941ded
8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents:
47216
diff
changeset
|
37 |
/** |
fd2e8f941ded
8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents:
47216
diff
changeset
|
38 |
* @author Xueming Shen, Rajendra Gutupalli, Jaya Hangal |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
39 |
*/ |
23925
0d5f2d863262
8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents:
14342
diff
changeset
|
40 |
class ZipFileStore extends FileStore { |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
41 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
42 |
private final ZipFileSystem zfs; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
43 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
44 |
ZipFileStore(ZipPath zpath) { |
11841
38a39c748880
7143230: fix warnings in java.util.jar, sun.tools.jar, zipfs demo, etc.
smarks
parents:
10292
diff
changeset
|
45 |
this.zfs = zpath.getFileSystem(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
46 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
47 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
48 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
49 |
public String name() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
50 |
return zfs.toString() + "/"; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
51 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
52 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
53 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
54 |
public String type() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
55 |
return "zipfs"; |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
56 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
57 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
58 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
59 |
public boolean isReadOnly() { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
60 |
return zfs.isReadOnly(); |
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 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
64 |
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
65 |
return (type == BasicFileAttributeView.class || |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
66 |
type == ZipFileAttributeView.class); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
67 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
68 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
69 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
70 |
public boolean supportsFileAttributeView(String name) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
71 |
return name.equals("basic") || name.equals("zip"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
72 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
73 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
74 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
75 |
public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> type) { |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
76 |
if (type == null) |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
77 |
throw new NullPointerException(); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
78 |
return (V)null; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
79 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
80 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
81 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
82 |
public long getTotalSpace() throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
83 |
return new ZipFileStoreAttributes(this).totalSpace(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
84 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
85 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
86 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
87 |
public long getUsableSpace() throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
88 |
return new ZipFileStoreAttributes(this).usableSpace(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
89 |
} |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
90 |
|
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
91 |
@Override |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
92 |
public long getUnallocatedSpace() throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
93 |
return new ZipFileStoreAttributes(this).unallocatedSpace(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
94 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
95 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
96 |
@Override |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
97 |
public Object getAttribute(String attribute) throws IOException { |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
98 |
if (attribute.equals("totalSpace")) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
99 |
return getTotalSpace(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
100 |
if (attribute.equals("usableSpace")) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
101 |
return getUsableSpace(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
102 |
if (attribute.equals("unallocatedSpace")) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
103 |
return getUnallocatedSpace(); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
104 |
throw new UnsupportedOperationException("does not support the given attribute"); |
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:
7531
diff
changeset
|
107 |
private static class ZipFileStoreAttributes { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
108 |
final FileStore fstore; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
109 |
final long size; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
110 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
111 |
public ZipFileStoreAttributes(ZipFileStore fileStore) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
112 |
throws IOException |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
113 |
{ |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
114 |
Path path = FileSystems.getDefault().getPath(fileStore.name()); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
115 |
this.size = Files.size(path); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
116 |
this.fstore = Files.getFileStore(path); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
117 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
118 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
119 |
public long totalSpace() { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
120 |
return size; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
121 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
122 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
123 |
public long usableSpace() throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
124 |
if (!fstore.isReadOnly()) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
125 |
return fstore.getUsableSpace(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
126 |
return 0; |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
127 |
} |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
128 |
|
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
129 |
public long unallocatedSpace() throws IOException { |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
130 |
if (!fstore.isReadOnly()) |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
131 |
return fstore.getUnallocatedSpace(); |
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
132 |
return 0; |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
133 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
134 |
} |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
135 |
} |