< prev index next >

src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java

Print this page

        

*** 86,95 **** --- 86,101 ---- private static final String OPT_DEFAULT_GROUP = "defaultGroup"; private static final String OPT_DEFAULT_PERMISSIONS = "defaultPermissions"; private static final Set<PosixFilePermission> 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; final ZipCoder zc; private final ZipPath rootdir;
*** 122,132 **** String nameEncoding = env.containsKey("encoding") ? (String)env.get("encoding") : "UTF-8"; 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.supportPosix = isTrue(env, OPT_POSIX); this.defaultOwner = initOwner(zfpath, env); this.defaultGroup = initGroup(zfpath, env); this.defaultPermissions = initPermissions(env); this.supportedFileAttributeViews = supportPosix ? --- 128,138 ---- String nameEncoding = env.containsKey("encoding") ? (String)env.get("encoding") : "UTF-8"; this.noExtt = "false".equals(env.get("zipinfo-time")); this.useTempFile = isTrue(env, "useTempFile"); this.forceEnd64 = isTrue(env, "forceZIP64End"); ! this.defaultCompressionMethod = getDefaultCompressionMethod(env); this.supportPosix = isTrue(env, OPT_POSIX); this.defaultOwner = initOwner(zfpath, env); this.defaultGroup = initGroup(zfpath, env); this.defaultPermissions = initPermissions(env); this.supportedFileAttributeViews = supportPosix ?
*** 161,170 **** --- 167,219 ---- } this.provider = provider; 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<String, ?> 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<String, ?> env, String name) { return "true".equals(env.get(name)) || TRUE.equals(env.get(name)); }
< prev index next >