author | sherman |
Tue, 01 Feb 2011 14:20:01 -0800 | |
changeset 8165 | b67d8b1f4e46 |
parent 7531 | 77870839c857 |
permissions | -rw-r--r-- |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
1 |
ZipFileSystem is a file system provider that treats the contents of a zip or |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
2 |
JAR file as a java.nio.file.FileSystem. |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
3 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
4 |
The factory methods defined by the java.nio.file.FileSystems class can be |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
5 |
used to create a FileSystem, eg: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
6 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
7 |
// use file type detection |
7189 | 8 |
Path jarfile = Paths.get("foo.jar"); |
8165
b67d8b1f4e46
7015391: (zipfs) Update zip provider for 1/2011 changes
sherman
parents:
7531
diff
changeset
|
9 |
FileSystem fs = FileSystems.newFileSystem(jarfile, null); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
10 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
11 |
-or |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
12 |
|
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
13 |
// locate file system by the legacy JAR URL syntax |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
14 |
Map<String,?> env = Collections.emptyMap(); |
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
15 |
URI uri = URI.create("jar:file:/mydir/foo.jar"); |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
16 |
FileSystem fs = FileSystems.newFileSystem(uri, env); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
17 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
18 |
Once a FileSystem is created then classes in the java.nio.file package |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
19 |
can be used to access files in the zip/JAR file, eg: |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
20 |
|
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
21 |
Path mf = fs.getPath("/META-INF/MANIFEST.MF"); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
22 |
InputStream in = mf.newInputStream(); |
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
23 |
|
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
24 |
See Demo.java for more interesting usages. |
6699
d8229570529d
6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff
changeset
|
25 |
|
7531
77870839c857
6989148: (fs) zip provider should be available "out of the box"
sherman
parents:
7189
diff
changeset
|
26 |