/nio-zipfs

java.util.nio zipfs file system - from OpenJDK8u demo code

Primary LanguageJavaBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

nio-zipfs

ZipFileSystem is a file system provider that treats the contents of a zip or JAR file as a java.nio.file.FileSystem.

Related projects

zipfilesystem-standalone by Philippe Marschall.

Building

To build, you will need Oracle JDK 7/OpenJDK 7 or newer, together with Apache Maven 3.x.

This implementation is tested with Maven 3.2, openjdk7 and openjdk8.

To build:

mvn clean install

To then use from a Maven project, use:

<dependency>
	<groupId>no.s11.zipfs</groupId>
	<artifactId>nio-zipfs</artifactId>
	<version>8.60.0-SNAPSHOT</version>	
</dependency>

Check pom.xml to find the latest <version> number.

TODO: Set up Maven snapshot repository.

Usage

If nio-zipfs is on the Java classpath, then it should be discovered by the ServiceLoader mechanism in FileSystemProvider.

WARNING: If [java.nio.file.spi.FileSystemProvider.installedProviders()

The factory methods defined by the java.nio.file.FileSystems class can be used to create a ZipFileSystem for an existing ZIP file:

   // use file type detection
   Path zipfile = Paths.get("foo.zip");
   FileSystem fs = FileSystems.newFileSystem(zipfile, null);

-or-:

   // locate file system by the legacy ZIP URL syntax
   Map<String,?> env = Collections.emptyMap();
   URI uri = URI.create("zip:file:/mydir/foo.zip");
   FileSystem fs = FileSystems.newFileSystem(uri, env);

Once a FileSystem is created then classes in the java.nio.file package can be used to access files in the zip/JAR file, eg:

   Path mf = fs.getPath("/META-INF/MANIFEST.MF");
   InputStream in = mf.newInputStream();

See Demo.java for more interesting usages.

License

License: BSD 3-Clause

  • Copyright (c) 2015 University of Manchester, UK.
  • Copyright (c) 2009, 2012, Oracle and/or its affiliates.

All rights reserved.

Based on the zipfs demo of OpenJDK 8 by Oracle, distributed under a BSD 3-Clause license.

For details, see the files NOTICE and LICENSE.

Relation to OpenJDK

This code is based on the demo/nio/zipfs code from OpenJDK 8 which has been distributed with Open JDK since 7u20.

While OpenJDK 8 is licensed under GPL 2 with the classpath exception, the zipfs code was distributed under the BSD 3-Clause license.

Since OpenJDK 9, zipfs is included in the main OpenJDK codebase, but now covered by the GPL license.

This code in nio-zipfs is only based on the OpenJDK 8 demo code, and remains licensed under BSD 3-Clause, which makes it compatible with other open source licenses like Apache Software License 2.0, provided you retain the notices in the files NOTICE and LICENSE.

Contributing

If you have a question, feature request or think you found a bug, please raise a GitHub issue.

To suggest changes or improvements to the code, please raise a GitHub pull request. The whole purpose of moving this code out of OpenJDK is to be able to improve it independently of the OpenJDK release schedule.

Please make sure that your patch is a clean contribution intellectual-property-wise, e.g. that you or your employer owns the copyright or that you are allowed to contribute it under the BSD 3-Clause license. This means that you cannot contribute any code from the [upstream OpenJDK 9 code base]((http://hg.openjdk.java.net/jdk9/dev/jdk/file/default/src/jdk.zipfs/share/classes/jdk/nio/zipfs) as it is now licensed under GPL. Patches from upstream OpenJDK 8 ) are however allowed, as long as they still have the BSD license headers.

There's no mailing list, but you can watch this repository to be included when issues and pull requests are raised.