當前位置: 首頁>>代碼示例>>Java>>正文


Java Zip4jConstants.ENC_METHOD_STANDARD屬性代碼示例

本文整理匯總了Java中net.lingala.zip4j.util.Zip4jConstants.ENC_METHOD_STANDARD屬性的典型用法代碼示例。如果您正苦於以下問題:Java Zip4jConstants.ENC_METHOD_STANDARD屬性的具體用法?Java Zip4jConstants.ENC_METHOD_STANDARD怎麽用?Java Zip4jConstants.ENC_METHOD_STANDARD使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在net.lingala.zip4j.util.Zip4jConstants的用法示例。


在下文中一共展示了Zip4jConstants.ENC_METHOD_STANDARD屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkParameters

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);
	}
	
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:32,代碼來源:ZipEngine.java

示例2: calculateTotalWork

private long calculateTotalWork(ArrayList fileList, ZipParameters parameters) throws ZipException {
	if (fileList == null) {
		throw new ZipException("file list is null, cannot calculate total work");
	}
	
	long totalWork = 0;
	
	for (int i = 0; i < fileList.size(); i++) {
		if(fileList.get(i) instanceof File) {
			if (((File)fileList.get(i)).exists()) {
				if (parameters.isEncryptFiles() && 
						parameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
					totalWork += (Zip4jUtil.getFileLengh((File)fileList.get(i)) * 2);
				} else {
					totalWork += Zip4jUtil.getFileLengh((File)fileList.get(i));
				}
				
				if (zipModel.getCentralDirectory() != null && 
						zipModel.getCentralDirectory().getFileHeaders() != null && 
						zipModel.getCentralDirectory().getFileHeaders().size() > 0) {
					String relativeFileName = Zip4jUtil.getRelativeFileName(
							((File)fileList.get(i)).getAbsolutePath(), parameters.getRootFolderInZip(), parameters.getDefaultFolderPath());
					FileHeader fileHeader = Zip4jUtil.getFileHeader(zipModel, relativeFileName);
					if (fileHeader != null) {
						totalWork += (Zip4jUtil.getFileLengh(new File(zipModel.getZipFile())) - fileHeader.getCompressedSize());
					}
				}
			}
		}
	}
	
	return totalWork;
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:33,代碼來源:ZipEngine.java

示例3: checkCRC

public void checkCRC() throws ZipException {
	if (fileHeader != null) {
		if (fileHeader.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_AES) {
			if (decrypter != null && decrypter instanceof AESDecrypter) {
				byte[] tmpMacBytes = ((AESDecrypter)decrypter).getCalculatedAuthenticationBytes();
				byte[] storedMac = ((AESDecrypter)decrypter).getStoredMac();
				byte[] calculatedMac = new byte[InternalZipConstants.AES_AUTH_LENGTH]; 
				
				if (calculatedMac == null || storedMac == null) {
					throw new ZipException("CRC (MAC) check failed for " + fileHeader.getFileName());
				}
				
				System.arraycopy(tmpMacBytes, 0, calculatedMac, 0, InternalZipConstants.AES_AUTH_LENGTH);
				
				if (!Arrays.equals(calculatedMac, storedMac)) {
					throw new ZipException("invalid CRC (MAC) for file: " + fileHeader.getFileName());
				}
			}
		} else {
			long calculatedCRC = crc.getValue() & 0xffffffffL;
			if (calculatedCRC != fileHeader.getCrc32()) {
				String errMsg = "invalid CRC for file: " + fileHeader.getFileName();
				if (localFileHeader.isEncrypted() && 
						localFileHeader.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
					errMsg += " - Wrong Password?";
				}
				throw new ZipException(errMsg);
			}
		}
	}
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:31,代碼來源:UnzipEngine.java

示例4: read

public int read(byte[] b, int off, int len) throws IOException {
	
	if (b == null) {
		throw new NullPointerException("input buffer is null");
	} else if (off < 0 || len < 0 || len > b.length - off) {
	    throw new IndexOutOfBoundsException();
	} else if (len == 0) {
	    return 0;
	}
	
	try {
	    int n;
	    if (bytesWritten >= uncompressedSize)
	    	return -1;
	    while ((n = inflater.inflate(b, off, len)) == 0) {
			if (inflater.finished() || inflater.needsDictionary()) {
			    return -1;
			}
			if (inflater.needsInput()) {
				fill();
			}
	    }
	    bytesWritten += n;
	    return n;
	} catch (DataFormatException e) {
	    String s = "Invalid ZLIB data format";
	    if (e.getMessage() != null) {
	    	s = e.getMessage();
	    }
	    if (unzipEngine != null) {
	    	if (unzipEngine.getLocalFileHeader().isEncrypted() && 
	    			unzipEngine.getLocalFileHeader().getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
	    		s += " - Wrong Password?";
	    	}
	    }
	    throw new IOException(s);
	}
}
 
開發者ID:ModernDayPlayer,項目名稱:SurvivalGamesX,代碼行數:38,代碼來源:InflaterInputStream.java

示例5: read

public int read(byte[] b, int off, int len) throws IOException {
	
	if (b == null) {
		throw new NullPointerException("input buffer is null");
	} else if (off < 0 || len < 0 || len > b.length - off) {
	    throw new IndexOutOfBoundsException();
	} else if (len == 0) {
	    return 0;
	}
	
	try {
	    int n;
	    if (bytesWritten >= uncompressedSize) {
	    	finishInflating();
	    	return -1;
	    }
	    while ((n = inflater.inflate(b, off, len)) == 0) {
			if (inflater.finished() || inflater.needsDictionary()) {
				finishInflating();
			    return -1;
			}
			if (inflater.needsInput()) {
				fill();
			}
	    }
	    bytesWritten += n;
	    return n;
	} catch (DataFormatException e) {
	    String s = "Invalid ZLIB data format";
	    if (e.getMessage() != null) {
	    	s = e.getMessage();
	    }
	    if (unzipEngine != null) {
	    	if (unzipEngine.getLocalFileHeader().isEncrypted() && 
	    			unzipEngine.getLocalFileHeader().getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
	    		s += " - Wrong Password?";
	    	}
	    }
	    throw new IOException(s);
	}
}
 
開發者ID:joielechong,項目名稱:Zip4jAndroid,代碼行數:41,代碼來源:InflaterInputStream.java


注:本文中的net.lingala.zip4j.util.Zip4jConstants.ENC_METHOD_STANDARD屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。