本文整理汇总了Java中net.lingala.zip4j.model.ZipParameters类的典型用法代码示例。如果您正苦于以下问题:Java ZipParameters类的具体用法?Java ZipParameters怎么用?Java ZipParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ZipParameters类属于net.lingala.zip4j.model包,在下文中一共展示了ZipParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compress
import net.lingala.zip4j.model.ZipParameters; //导入依赖的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: loadJar
import net.lingala.zip4j.model.ZipParameters; //导入依赖的package包/类
public void loadJar(File jar) throws IOException {
try {
final ZipFile zipFile = new ZipFile(classFile);
final ZipFile jarFile = new ZipFile(jar);
//noinspection unchecked
for (FileHeader header : (List<FileHeader>) jarFile.getFileHeaders()) {
if (!header.isDirectory()) {
final ZipParameters parameters = new ZipParameters();
parameters.setFileNameInZip(header.getFileName());
parameters.setSourceExternalStream(true);
zipFile.addStream(jarFile.getInputStream(header), parameters);
}
}
dexJar();
} catch (ZipException e) {
IOException exception = new IOException();
//noinspection UnnecessaryInitCause
exception.initCause(e);
throw exception;
}
}
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:22,代码来源:AndroidClassLoader.java
示例3: zip
import net.lingala.zip4j.model.ZipParameters; //导入依赖的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();
}
}
示例4: defineClass
import net.lingala.zip4j.model.ZipParameters; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Class<?> defineClass(String name, byte[] data) {
try {
final ZipFile zipFile = new ZipFile(classFile);
final ZipParameters parameters = new ZipParameters();
parameters.setFileNameInZip(name.replace('.', '/') + ".class");
parameters.setSourceExternalStream(true);
zipFile.addStream(new ByteArrayInputStream(data), parameters);
return dexJar().loadClass(name, parent);
} catch (IOException | ZipException e) {
throw new FatalLoadingException(e);
} finally {
dexFile.delete();
odexOatFile.delete();
}
}
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:20,代码来源:AndroidClassLoader.java
示例5: createZip
import net.lingala.zip4j.model.ZipParameters; //导入依赖的package包/类
/**
* Creates a zip from all files and folders in the specified folder. DOES NOT INCLUDE THE FOLDER
* ITSELF!
*
* @param file the folder which content should be zipped
* @return the created zip
* @throws ZipException if something goes wrong
*/
@Nonnull
public static ZipFile createZip(@Nonnull File file) throws ZipException {
ZipFile zip = new ZipFile(new File(file.getParent(), file.getName() + ".zip"));
ArrayList<File> fileList = new ArrayList<>();
File[] files = file.listFiles();
if (files == null) {
return zip;
}
Arrays.stream(files).forEach(fileList::add);
zip.createZipFile(fileList, new ZipParameters());
return zip;
}
示例6: compress
import net.lingala.zip4j.model.ZipParameters; //导入依赖的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);
}
}
示例7: generateZipFile
import net.lingala.zip4j.model.ZipParameters; //导入依赖的package包/类
private void generateZipFile() {
try {
File outputFile = new File(this.workFolder.getName() + ".zip");
if (outputFile.exists()) {
Logger.info(outputFile.getAbsolutePath() + " already exists. Deleting.");
outputFile.delete();
}
ZipFile output = new net.lingala.zip4j.core.ZipFile(outputFile);
Logger.info("Generating " + output.getFile().getAbsolutePath());
ZipParameters params = new ZipParameters();
params.setIncludeRootFolder(false);
params.setRootFolderInZip("");
output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "apktool", params);
params.setRootFolderInZip("classes");
output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "classes", params);
} catch (Throwable t) {
Logger.error("Unable to generate final zip file.", t);
}
}
示例8: AddFolder
import net.lingala.zip4j.model.ZipParameters; //导入依赖的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();
}
}
示例9: createZipFile
import net.lingala.zip4j.model.ZipParameters; //导入依赖的package包/类
/**
* Creates a zip file and adds the list of source file(s) to the zip file. If the zip file
* exists then this method throws an exception. Parameters such as compression type, etc
* can be set in the input parameters. While the method addFile/addFiles also creates the
* zip file if it does not exist, the main functionality of this method is to create a split
* zip file. To create a split zip file, set the splitArchive parameter to true with a valid
* splitLength. Split Length has to be more than 65536 bytes
* @param sourceFileList - File to be added to the zip file
* @param parameters - zip parameters for this file list
* @param splitArchive - if archive has to be split or not
* @param splitLength - if archive has to be split, then length in bytes at which it has to be split
* @throws ZipException
*/
public void createZipFile(ArrayList sourceFileList, ZipParameters parameters,
boolean splitArchive, long splitLength) throws ZipException {
if (!Zip4jUtil.isStringNotNullAndNotEmpty(file)) {
throw new ZipException("zip file path is empty");
}
if (Zip4jUtil.checkFileExists(file)) {
throw new ZipException("zip file: " + file + " already exists. To add files to existing zip file use addFile method");
}
if (sourceFileList == null) {
throw new ZipException("input file ArrayList is null, cannot create zip file");
}
if (!Zip4jUtil.checkArrayListTypes(sourceFileList, InternalZipConstants.LIST_TYPE_FILE)) {
throw new ZipException("One or more elements in the input ArrayList is not of type File");
}
createNewZipModel();
this.zipModel.setSplitArchive(splitArchive);
this.zipModel.setSplitLength(splitLength);
addFiles(sourceFileList, parameters);
}
示例10: createZipFileFromFolder
import net.lingala.zip4j.model.ZipParameters; //导入依赖的package包/类
/**
* Creates a zip file and adds the files/folders from the specified folder to the zip file.
* This method does the same functionality as in addFolder method except that this method
* can also create split zip files when adding a folder. To create a split zip file, set the
* splitArchive parameter to true and specify the splitLength. Split length has to be more than
* or equal to 65536 bytes. Note that this method throws an exception if the zip file already
* exists.
* @param folderToAdd
* @param parameters
* @param splitArchive
* @param splitLength
* @throws ZipException
*/
public void createZipFileFromFolder(File folderToAdd, ZipParameters parameters,
boolean splitArchive, long splitLength) throws ZipException {
if (folderToAdd == null) {
throw new ZipException("folderToAdd is null, cannot create zip file from folder");
}
if (parameters == null) {
throw new ZipException("input parameters are null, cannot create zip file from folder");
}
if (Zip4jUtil.checkFileExists(file)) {
throw new ZipException("zip file: " + file + " already exists. To add files to existing zip file use addFolder method");
}
createNewZipModel();
this.zipModel.setSplitArchive(splitArchive);
if (splitArchive)
this.zipModel.setSplitLength(splitLength);
addFolder(folderToAdd, parameters, false);
}
示例11: addFolder
import net.lingala.zip4j.model.ZipParameters; //导入依赖的package包/类
/**
* Internal method to add a folder to the zip file.
* @param path
* @param parameters
* @param checkSplitArchive
* @throws ZipException
*/
private void addFolder(File path, ZipParameters parameters,
boolean checkSplitArchive) throws ZipException {
checkZipModel();
if (this.zipModel == null) {
throw new ZipException("internal error: zip model is null");
}
if (checkSplitArchive) {
if (this.zipModel.isSplitArchive()) {
throw new ZipException("This is a split archive. Zip file format does not allow updating split/spanned files");
}
}
ZipEngine zipEngine = new ZipEngine(zipModel);
zipEngine.addFolderToZip(path, parameters, progressMonitor, runInThread);
}
示例12: generateAESExtraDataRecord
import net.lingala.zip4j.model.ZipParameters; //导入依赖的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;
}
示例13: compile
import net.lingala.zip4j.model.ZipParameters; //导入依赖的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();
}
}
示例14: zip
import net.lingala.zip4j.model.ZipParameters; //导入依赖的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);
}
}
示例15: zipFixture
import net.lingala.zip4j.model.ZipParameters; //导入依赖的package包/类
public static File zipFixture(String path) throws ZipException {
File source = new File(path);
File target = new File("target/archives/zip-archive-test.zip");
if (target.exists() && !target.delete())
throw new RuntimeException("Unable to delete old zip file target");
if (!target.getParentFile().exists() && !target.getParentFile().mkdirs())
throw new RuntimeException("Unable to create directories for zip file target");
ZipFile zipFile = new ZipFile(target);
ZipParameters parameters = new ZipParameters();
parameters.setIncludeRootFolder(false);
zipFile.createZipFileFromFolder(source, parameters, false, -1);
return target;
}