Java Code Examples for net.lingala.zip4j.util.Zip4jConstants#COMP_DEFLATE

The following examples show how to use net.lingala.zip4j.util.Zip4jConstants#COMP_DEFLATE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CipherOutputStream.java    From AndroidZip with Apache License 2.0 6 votes vote down vote up
private int[] generateGeneralPurposeBitArray(boolean isEncrpyted, int compressionMethod) {
	
	int[] generalPurposeBits = new int[8];
	if (isEncrpyted) {
		generalPurposeBits[0] = 1;
	} else {
		generalPurposeBits[0] = 0;
	}
	
	if (compressionMethod == Zip4jConstants.COMP_DEFLATE) {
		// Have to set flags for deflate
	} else {
		generalPurposeBits[1] = 0;
		generalPurposeBits[2] = 0;
	}

	generalPurposeBits[3] = 1;
	
	return generalPurposeBits;
}
 
Example 2
Source File: ZipEngine.java    From AndroidZip with Apache License 2.0 5 votes vote down vote up
private void checkParameters(ZipParameters parameters) throws ZipException {
	
	if (parameters == null) {
		throw new ZipException("cannot validate zip parameters");
	}
	
	if ((parameters.getCompressionMethod() != Zip4jConstants.COMP_STORE) && 
			parameters.getCompressionMethod() != Zip4jConstants.COMP_DEFLATE) {
		throw new ZipException("unsupported compression type");
	}
	
	if (parameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) {
		if (parameters.getCompressionLevel() < 0 && parameters.getCompressionLevel() > 9) {
			throw new ZipException("invalid compression level. compression level dor deflate should be in the range of 0-9");
		}
	}
	
	if (parameters.isEncryptFiles()) {
		if (parameters.getEncryptionMethod() != Zip4jConstants.ENC_METHOD_STANDARD && 
				parameters.getEncryptionMethod() != Zip4jConstants.ENC_METHOD_AES) {
			throw new ZipException("unsupported encryption method");
		}
		
		if (parameters.getPassword() == null || parameters.getPassword().length <= 0) {
			throw new ZipException("input password is empty or null");
		}
	} else {
		parameters.setAesKeyStrength(-1);
		parameters.setEncryptionMethod(-1);
	}
	
}
 
Example 3
Source File: ZipParameters.java    From AndroidZip with Apache License 2.0 5 votes vote down vote up
public ZipParameters() {
	compressionMethod = Zip4jConstants.COMP_DEFLATE;
	encryptFiles = false;
	readHiddenFiles = true;
	encryptionMethod = Zip4jConstants.ENC_NO_ENCRYPTION;
	aesKeyStrength = -1;
	includeRootFolder = true;
	timeZone = TimeZone.getDefault();
}
 
Example 4
Source File: DeflaterOutputStream.java    From AndroidZip with Apache License 2.0 5 votes vote down vote up
public void putNextEntry(File file, ZipParameters zipParameters)
		throws ZipException {
	super.putNextEntry(file, zipParameters);
	if (zipParameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) {
		deflater.reset();
		if ((zipParameters.getCompressionLevel() < 0 || zipParameters
				.getCompressionLevel() > 9)
				&& zipParameters.getCompressionLevel() != -1) {
			throw new ZipException(
					"invalid compression level for deflater. compression level should be in the range of 0-9");
		}
		deflater.setLevel(zipParameters.getCompressionLevel());
	}
}
 
Example 5
Source File: DeflaterOutputStream.java    From AndroidZip with Apache License 2.0 5 votes vote down vote up
public void write(byte[] buf, int off, int len) throws IOException {
	if (zipParameters.getCompressionMethod() != Zip4jConstants.COMP_DEFLATE) {
		super.write(buf, off, len);
	} else {
		deflater.setInput(buf, off, len);
		 while (!deflater.needsInput()) {
			 deflate();
            }
	}		
}
 
Example 6
Source File: DeflaterOutputStream.java    From AndroidZip with Apache License 2.0 5 votes vote down vote up
public void closeEntry() throws IOException, ZipException {
	if (zipParameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) {
		if (!deflater.finished()) {
			deflater.finish();
			while (!deflater.finished()) {
				deflate();
			}
		}
		firstBytesRead = false;
	}
	super.closeEntry();
}