本文整理汇总了Java中net.lingala.zip4j.core.ZipFile类的典型用法代码示例。如果您正苦于以下问题:Java ZipFile类的具体用法?Java ZipFile怎么用?Java ZipFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipFile类属于net.lingala.zip4j.core包,在下文中一共展示了ZipFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compress
import net.lingala.zip4j.core.ZipFile; //导入依赖的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: ExtractSingleFile
import net.lingala.zip4j.core.ZipFile; //导入依赖的package包/类
public ExtractSingleFile() {
try {
// Initiate ZipFile object with the path/name of the zip file.
ZipFile zipFile = new ZipFile("c:\\ZipTest\\ExtractSingleFile.zip");
// Check to see if the zip file is password protected
if (zipFile.isEncrypted()) {
// if yes, then set the password for the zip file
zipFile.setPassword("test123!");
}
// Specify the file name which has to be extracted and the path to which
// this file has to be extracted
zipFile.extractFile("Ronan_Keating_-_In_This_Life.mp3", "c:\\ZipTest\\");
// Note that the file name is the relative file name in the zip file.
// For example if the zip file contains a file "mysong.mp3" in a folder
// "FolderToAdd", then extraction of this file can be done as below:
zipFile.extractFile("FolderToAdd\\myvideo.avi", "c:\\ZipTest\\");
} catch (ZipException e) {
e.printStackTrace();
}
}
示例3: loadJar
import net.lingala.zip4j.core.ZipFile; //导入依赖的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
示例4: zip
import net.lingala.zip4j.core.ZipFile; //导入依赖的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();
}
}
示例5: defineClass
import net.lingala.zip4j.core.ZipFile; //导入依赖的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
示例6: recreatePristineSiad
import net.lingala.zip4j.core.ZipFile; //导入依赖的package包/类
private static File recreatePristineSiad() throws IOException {
doTimed(() -> {
File zipFile = new File("../../sia-preloaded.zip");
ZipFile preloaded = new ZipFile(zipFile);
final File extractTo = new File("junit/sia").getCanonicalFile();
FileUtils.deleteDirectory(extractTo);
preloaded.extractAll(extractTo.getCanonicalPath());
return null;
});
final String siadDir = JUNIT_SIA + "Sia-v1.3.0-linux-amd64/";
final File siadDirectoryFile = new File(siadDir).getCanonicalFile();
final boolean result = new File(siadDirectoryFile, "siad").setExecutable(true);
Assert.assertTrue("unable to set siad executable", result);
return siadDirectoryFile;
}
示例7: unzipfile
import net.lingala.zip4j.core.ZipFile; //导入依赖的package包/类
public void unzipfile(File zipfile, String dest, String passwd) throws ZipException {
ZipFile zfile = new ZipFile(zipfile);
// zfile.setFileNameCharset("GBK");//在GBK系统中需要设置
if (!zfile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能已经损坏!");
}
File file = new File(dest);
if (file.isDirectory() && !file.exists()) {
file.mkdirs();
}
if (zfile.isEncrypted()) {
zfile.setPassword(passwd.toCharArray());
}
zfile.extractAll(dest);
}
示例8: loadWorld
import net.lingala.zip4j.core.ZipFile; //导入依赖的package包/类
/**
* Loads a world. Needs to copy the file from the repo, unzip it and let the implementation load it <br><b>Always
* needs to call super! Super needs to be called first (because it copies the world)</b>
*
* @param map the map that should be loaded
* @param gameid the id of the game this map belongs to
* @return the loaded world
* @throws WorldException something goes wrong
*/
@Nonnull
public World loadWorld(@Nonnull Map map, @Nonnull UUID gameid, boolean replaceMarkers) {
map.load(gameid, "TEMP_" + map.getWorldName() + "_" + gameid.toString().split("-")[0]);
log.finer("Loading map " + map.getInfo().getName() + " as " + map.getLoadedName(gameid));
File file = new File(worldContainer, map.getLoadedName(gameid));
try {
ZipFile zip = new ZipFile(new File(worldsFolder, map.getWorldName() + ".zip"));
zip.extractAll(file.getAbsolutePath());
FileUtils.delete(new File(file, "uid.dat"));
} catch (ZipException e) {
throw new WorldException("Could not unzip world " + map.getInfo().getName() + ".", e);
}
World world = loadLocalWorld(map.getLoadedName(gameid));
if (replaceMarkers) {
replaceMarkers(world, map);
}
return world;
}
示例9: createZip
import net.lingala.zip4j.core.ZipFile; //导入依赖的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;
}
示例10: compress
import net.lingala.zip4j.core.ZipFile; //导入依赖的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);
}
}
示例11: unzip
import net.lingala.zip4j.core.ZipFile; //导入依赖的package包/类
/**
* 解压文件到指定目录
*
* @param zipFile 压缩文件
* @param outDir 输出路径
* @param isClean 是否清理目录
* @return
*/
public static boolean unzip(File zipFile, File outDir, boolean isClean){
try {
if(!FileHelper.exists(zipFile)){
return false;
}
ZipFile zip = new ZipFile(zipFile);
if(isClean && outDir.exists()){
FileHelper.delete(outDir);
}
zip.setRunInThread(false);
zip.extractAll(outDir.getPath());
return true;
} catch (ZipException e) {
e.printStackTrace();
}
return false;
}
示例12: list
import net.lingala.zip4j.core.ZipFile; //导入依赖的package包/类
/**
* 解压文件,注意该法方法并不是异步的
*
* @param zipFile 压缩文件
* @param filter
* @return
*/
public static void list(File zipFile, FileFilter filter){
try {
if(!FileHelper.exists(zipFile)){
return;
}
ZipFile zip = new ZipFile(zipFile);
zip.setRunInThread(false);
// Get the list of file headers from the zip file
List fileHeaderList = zip.getFileHeaders();
// Loop through the file headers
for (int i = 0; i < fileHeaderList.size(); i++) {
// Extract the file to the specified destination
filter.handle(zip, (FileHeader) fileHeaderList.get(i));
}
} catch (ZipException e) {
e.printStackTrace();
}
}
示例13: unzipDexList
import net.lingala.zip4j.core.ZipFile; //导入依赖的package包/类
protected List<File> unzipDexList(File apk, File tempDir){
List<FileHeader> dexFileHeaders = MultDexSupport.getDexFileHeaders(apk);
if(dexFileHeaders.isEmpty()){
return new ArrayList<>(0);
}
// 解压dex文件
tempDir.mkdirs();
List<File> dexFileList = new ArrayList<>(dexFileHeaders.size());
try {
for(FileHeader dexFileHeader : dexFileHeaders){
ZipFile zipFile = new ZipFile(apk);
boolean unzip = ZipUtils.unzip(zipFile, dexFileHeader, tempDir);
if(unzip){
dexFileList.add(new File(tempDir,dexFileHeader.getFileName()));
}
}
return dexFileList;
} catch (ZipException e) {
e.printStackTrace();
}
return new ArrayList<>(0);
}
示例14: generateZipFile
import net.lingala.zip4j.core.ZipFile; //导入依赖的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);
}
}
示例15: AddFolder
import net.lingala.zip4j.core.ZipFile; //导入依赖的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();
}
}