--- old/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java 2019-09-23 18:40:41.000000000 -0400 +++ new/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java 2019-09-23 18:40:40.000000000 -0400 @@ -88,6 +88,12 @@ private static final Set DEFAULT_PERMISSIONS = PosixFilePermissions.fromString("rwxrwxrwx"); + // Property used to specify the compression mode to use + private static final String COMPRESSION_METHOD = "compressionMethod"; + // Value specified for compressionMethod property to compress Zip entries + public static final String DEFLATED_COMPRESSION_METHOD = "DEFLATED"; + // Value specified for compressionMethod property to not compress Zip entries + public static final String STORED_COMPRESSION_METHOD = "STORED"; private final ZipFileSystemProvider provider; private final Path zfpath; @@ -124,7 +130,7 @@ this.noExtt = "false".equals(env.get("zipinfo-time")); this.useTempFile = isTrue(env, "useTempFile"); this.forceEnd64 = isTrue(env, "forceZIP64End"); - this.defaultCompressionMethod = isTrue(env, "noCompression") ? METHOD_STORED : METHOD_DEFLATED; + this.defaultCompressionMethod = getDefaultCompressionMethod(env); this.supportPosix = isTrue(env, OPT_POSIX); this.defaultOwner = initOwner(zfpath, env); this.defaultGroup = initGroup(zfpath, env); @@ -163,6 +169,49 @@ this.zfpath = zfpath; } + /** + * Return the compression method to use(STORED or DEFLATED). If the + * property {@code commpressionMethod} is set use its value to determine + * the compression method to use. If the property is not set, then the + * default compression is DEFLATED unless the property {@code noCompression} + * is set which is supported for backwards compatability. + * @param env Zip FS map of properties + * @return The Compression method to use + */ + private int getDefaultCompressionMethod(Map env) { + int result = + isTrue(env, "noCompression") ? METHOD_STORED : METHOD_DEFLATED; + if(env.containsKey(COMPRESSION_METHOD)) { + Object compressionMethod = env.get(COMPRESSION_METHOD); + if(compressionMethod != null) { + if(compressionMethod instanceof String) { + switch(((String) compressionMethod).toUpperCase()) { + case STORED_COMPRESSION_METHOD: + result = METHOD_STORED; + break; + case DEFLATED_COMPRESSION_METHOD: + result = METHOD_DEFLATED; + break; + default: + throw new IllegalArgumentException(String.format( + "The value for the %s property must be %s or %s", + COMPRESSION_METHOD, STORED_COMPRESSION_METHOD, + DEFLATED_COMPRESSION_METHOD)); + } + } else { + throw new IllegalArgumentException(String.format( + "The Object type for the %s property must be a String")); + } + } else { + throw new IllegalArgumentException(String.format( + "The value for the %s property must be %s or %s", + COMPRESSION_METHOD, STORED_COMPRESSION_METHOD, + DEFLATED_COMPRESSION_METHOD)); + } + } + return result; + } + // returns true if there is a name=true/"true" setting in env private static boolean isTrue(Map env, String name) { return "true".equals(env.get(name)) || TRUE.equals(env.get(name));