本文整理匯總了Java中net.lingala.zip4j.util.Zip4jConstants類的典型用法代碼示例。如果您正苦於以下問題:Java Zip4jConstants類的具體用法?Java Zip4jConstants怎麽用?Java Zip4jConstants使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Zip4jConstants類屬於net.lingala.zip4j.util包,在下文中一共展示了Zip4jConstants類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: compress
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
public void compress(Transformation transformation) {
File inputFile = transformation.getTransformedApplicationLocation().getAbsoluteFile();
File compressedFile = new File(transformation.getTransformedApplicationLocation().getAbsolutePath() + ".zip");
logger.info("Compressing transformed application");
try {
ZipFile zipFile = new ZipFile(compressedFile);
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipFile.addFolder(inputFile, parameters);
FileUtils.deleteDirectory(transformation.getTransformedApplicationLocation());
logger.info("Transformed application has been compressed to {}", compressedFile.getAbsoluteFile());
} catch (Exception e) {
logger.error("Error when compressing transformed application", e);
}
}
示例2: zip
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
public static void zip(String targetPath, String destinationFilePath, String password) {
try {
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
if (password.length() > 0) {
parameters.setEncryptFiles(true);
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
parameters.setPassword(password);
}
ZipFile zipFile = new ZipFile(destinationFilePath);
File targetFile = new File(targetPath);
if (targetFile.isFile()) {
zipFile.addFile(targetFile, parameters);
} else if (targetFile.isDirectory()) {
zipFile.addFolder(targetFile, parameters);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: compress
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
/**
* Compress.
*
* @param fileName
* the file name
* @param compressedFileName
* the compressed file name
* @param password
* the password
*/
public static void compress(String fileName, String compressedFileName, String password) {
try {
ZipParameters zipParameters = new ZipParameters();
zipParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA);
if (password != null) {
zipParameters.setEncryptFiles(true);
zipParameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
zipParameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
zipParameters.setPassword(password);
}
String destinationZipFilePath = compressedFileName;
ZipFile zipFile = new ZipFile(destinationZipFilePath);
zipFile.addFile(new File(fileName), zipParameters);
} catch (ZipException e) {
JKExceptionUtil.handle(e);
}
}
示例4: AddFolder
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
public AddFolder() {
try {
// Initiate ZipFile object with the path/name of the zip file.
ZipFile zipFile = new ZipFile("c:\\ZipTest\\AddFolder.zip");
// Folder to add
String folderToAdd = "c:\\FolderToAdd";
// Initiate Zip Parameters which define various properties such
// as compression method, etc.
ZipParameters parameters = new ZipParameters();
// set compression method to store compression
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
// Set the compression level
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
// Add folder to the zip file
zipFile.addFolder(folderToAdd, parameters);
} catch (ZipException e) {
e.printStackTrace();
}
}
示例5: AESEncrpyter
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
public AESEncrpyter(char[] password, int keyStrength) throws ZipException {
if (password == null || password.length == 0) {
throw new ZipException("input password is empty or null in AES encrypter constructor");
}
if (keyStrength != Zip4jConstants.AES_STRENGTH_128 &&
keyStrength != Zip4jConstants.AES_STRENGTH_256) {
throw new ZipException("Invalid key strength in AES encrypter constructor");
}
this.password = password;
this.keyStrength = keyStrength;
this.finished = false;
counterBlock = new byte[InternalZipConstants.AES_BLOCK_SIZE];
iv = new byte[InternalZipConstants.AES_BLOCK_SIZE];
init();
}
示例6: readAndSaveAESExtraDataRecord
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
/**
* Reads AES Extra Data Record and saves it in the {@link FileHeader}
* @param fileHeader
* @throws ZipException
*/
private void readAndSaveAESExtraDataRecord(FileHeader fileHeader) throws ZipException {
if (fileHeader == null) {
throw new ZipException("file header is null in reading Zip64 Extended Info");
}
if (fileHeader.getExtraDataRecords() == null || fileHeader.getExtraDataRecords().size() <= 0) {
return;
}
AESExtraDataRecord aesExtraDataRecord = readAESExtraDataRecord(fileHeader.getExtraDataRecords());
if (aesExtraDataRecord != null) {
fileHeader.setAesExtraDataRecord(aesExtraDataRecord);
fileHeader.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
}
}
示例7: generateGeneralPurposeBitArray
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
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;
}
示例8: generateAESExtraDataRecord
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
private AESExtraDataRecord generateAESExtraDataRecord(ZipParameters parameters) throws ZipException {
if (parameters == null) {
throw new ZipException("zip parameters are null, cannot generate AES Extra Data record");
}
AESExtraDataRecord aesDataRecord = new AESExtraDataRecord();
aesDataRecord.setSignature(InternalZipConstants.AESSIG);
aesDataRecord.setDataSize(7);
aesDataRecord.setVendorID("AE");
// Always set the version number to 2 as we do not store CRC for any AES encrypted files
// only MAC is stored and as per the specification, if version number is 2, then MAC is read
// and CRC is ignored
aesDataRecord.setVersionNumber(2);
if (parameters.getAesKeyStrength() == Zip4jConstants.AES_STRENGTH_128) {
aesDataRecord.setAesStrength(Zip4jConstants.AES_STRENGTH_128);
} else if (parameters.getAesKeyStrength() == Zip4jConstants.AES_STRENGTH_256) {
aesDataRecord.setAesStrength(Zip4jConstants.AES_STRENGTH_256);
} else {
throw new ZipException("invalid AES key strength, cannot generate AES Extra data record");
}
aesDataRecord.setCompressionMethod(parameters.getCompressionMethod());
return aesDataRecord;
}
示例9: compile
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
public static void compile(String pkgroot){
try {
File parent = new File(pkgroot).getParentFile();
String name = new File(pkgroot).getName() + ".atomx";
ZipFile zipFile = new ZipFile(new File(parent, name));
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
parameters.setIncludeRootFolder(false);
zipFile.addFolder(pkgroot, parameters);
} catch (ZipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例10: zip
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
/**
* Archives the list of files to a zip archive
*
* @param zipFileName
* @param fileList
* @param desaElement
* @throws MetsExportException
*/
private void zip(String zipFileName, ArrayList<File> fileList, IDesaElement desaElement) throws MetsExportException {
try {
File file = new File(zipFileName);
if (file.exists()) {
file.delete();
file = null;
LOG.log(Level.FINE, "File:" + zipFileName + " exists, so it was deleted");
}
ZipFile zipFile = new ZipFile(zipFileName);
ZipParameters zip4jZipParameters = new ZipParameters();
zip4jZipParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
zip4jZipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipFile.addFiles(fileList, zip4jZipParameters);
LOG.log(Level.FINE, "Zip archive created:" + zipFileName + " for " + desaElement.getElementType());
} catch (ZipException e) {
throw new MetsExportException(desaElement.getOriginalPid(), "Unable to create a zip file:" + zipFileName, false, e);
}
}
示例11: initZipParameters
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
/**
*
* @return ZipParameters
*/
private ZipParameters initZipParameters() {
// Initiate Zip Parameters which define various properties such
// as compression method, etc. More parameters are explained in other
// examples
ZipParameters zpParameters = new ZipParameters();
// set compression method to deflate compression
zpParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
/*
Set the compression level. This value has to be in between 0 to 9
Several predefined compression levels are available
DEFLATE_LEVEL_FASTEST - Lowest compression level but higher speed of compression
DEFLATE_LEVEL_FAST - Low compression level but higher speed of compression
DEFLATE_LEVEL_NORMAL - Optimal balance between compression level/speed
DEFLATE_LEVEL_MAXIMUM - High compression level with a compromise of speed
DEFLATE_LEVEL_ULTRA - Highest compression level but low speed
*/
zpParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
return zpParameters;
}
示例12: ArchiverWorker
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
public ArchiverWorker(GameSet romSet, ArchiveMergerPlugin plugin, Consumer<Boolean> callback)
{
super(romSet, plugin, r -> r.getStatus().isComplete(), callback);
try
{
zfile = new ZipFile(Main.setManager.settings(romSet).romsPath.resolve("romset.zip").toFile());
zparams = new ZipParameters();
aparams = new ZipParameters();
zparams.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
zparams.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
aparams.setCompressionLevel(Zip4jConstants.COMP_DEFLATE);
aparams.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
aparams.setSourceExternalStream(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
示例13: withData
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
private void withData(AppsModel model, ApplicationInfo packageInfo, File file, FileUtil fileUtil, int count) throws Exception {
File dataFolder = new File(packageInfo.dataDir);
File dataFile = new File(fileUtil.getBaseFolderName() + model.getPackageName());
boolean z = RootManager.getInstance().copyFile(dataFolder.getPath(), fileUtil.getBaseFolderName());
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FASTEST);
if (z) {
if (dataFile.exists()) {
zipData.addFolder(dataFile, parameters);
FileUtils.deleteDirectory(dataFile);
}
}
ProgressModel progressModel = new ProgressModel();
progressModel.setProgress(count);
progressModel.setFileName(model.getAppName());
publishProgress(progressModel);
}
示例14: createZipFile
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
private File createZipFile(String[] outputFilenames) throws IOException, ZipException {
// We want a temporary filename but the file must not yet exist. So create a temporary file then delete it.
File file = File.createTempFile("outputs", ".zip");
deleteZipFile(file);
ZipFile zipFile = new ZipFile(file);
ZipParameters zipParameters = new ZipParameters();
zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
// Add files to zip file
ArrayList<File> filesToAdd = new ArrayList<>();
for (String outputFilename : outputFilenames) {
File fileToAdd = getFileInWorkingDirectory(outputFilename);
if (fileToAdd.exists()) {
filesToAdd.add(fileToAdd);
} else {
throw new IllegalArgumentException("File does not exist: " + fileToAdd.getAbsolutePath());
}
}
zipFile.createZipFile(filesToAdd, zipParameters);
return file;
}
示例15: example1
import net.lingala.zip4j.util.Zip4jConstants; //導入依賴的package包/類
/**
* 示例1 創建壓縮包添加文件到壓縮包中(未設置加密)
*/
@Test
public void example1(){
try {
ZipFile zipFile = new ZipFile("src/main/resources/AddFilesDeflateComp.zip");
ArrayList<File> filesToAdd = new ArrayList<File>();
filesToAdd.add(new File("src/main/resources/sample.txt"));
filesToAdd.add(new File("src/main/resources/zip4j.txt"));
filesToAdd.add(new File("src/main/resources/zip4j-1.3.2.jar"));
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to deflate compression
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipFile.addFiles(filesToAdd, parameters);
CompressUtil.printZipInfo("src/main/resources/AddFilesDeflateComp.zip");
} catch (ZipException e) {
e.printStackTrace();
}
}