I am using the Zip utility package of Java and wanted to know how to create a zip file with no compression at all. Setting the level to 0 doesn\'t help. Is this right?
FYI:
In JDK Source of the method [java.util.zip.ZipOutputStream.setLevel(int)]:
public void setLevel(int level) {
def.setLevel(level);
}
It simply redirect the compression level setting to the field variable [def], which is an instance of [java.util.zip.Deflater].
And in the source code of the class [java.util.zip.Deflater]:
/**
* Compression level for no compression.
*/
public static final int NO_COMPRESSION = 0;
/**
* Compression level for fastest compression.
*/
public static final int BEST_SPEED = 1;
/**
* Compression level for best compression.
*/
public static final int BEST_COMPRESSION = 9;
/**
* Default compression level.
*/
public static final int DEFAULT_COMPRESSION = -1;
So, I think it will be more readable if you use the constant value [Deflater.NO_COMPRESSION]:
zipOut.setMethod(ZipOutputStream.DEFLATED);
zipOut.setLevel(Deflater.NO_COMPRESSION);