本文整理汇总了Java中net.lingala.zip4j.model.FileHeader.isDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java FileHeader.isDirectory方法的具体用法?Java FileHeader.isDirectory怎么用?Java FileHeader.isDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.lingala.zip4j.model.FileHeader
的用法示例。
在下文中一共展示了FileHeader.isDirectory方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadJar
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的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
示例2: expandArtifact
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void expandArtifact(File artifactFile) throws IOException {
try {
ZipFile zipFile = new ZipFile(artifactFile);
for (FileHeader each : (List<FileHeader>) zipFile.getFileHeaders()) {
if (each.getFileName().startsWith("META-INF")) {
continue;
}
if (each.isDirectory()) {
continue;
}
this.archive.add(new ZipFileHeaderAsset(zipFile, each), each.getFileName());
}
} catch (ZipException e) {
throw new IOException(e);
}
}
示例3: read
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的package包/类
/**
* Read a ZIP file.
*
* @param file The ZIP file to read
* @throws ZipException
*/
public void read(File file) throws ZipException
{
ZipFile zip = new ZipFile(file);
@SuppressWarnings("unchecked")
List<FileHeader> fileHeaders = zip.getFileHeaders();
for (FileHeader fileHeader : fileHeaders)
{
LOGGER.info("ZIP contains: {}", fileHeader.getFileName());
if (fileHeader.isDirectory() && fileHeader.getFileName().toUpperCase().matches("^M-\\d+\\/*$"))
{
readManufacturerFiles(zip, fileHeader.getFileName().replace("/", ""));
}
}
}
示例4: unzip
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的package包/类
/**
* 使用给定密码解压指定的ZIP压缩文件到指定目录
* <p>
* 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
* @param dest 解压目录
* @param passwd ZIP文件的密码
* @return 解压后文件数组
* @throws ZipException 压缩文件有损坏或者解压缩失败抛出
*/
public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException {
ZipFile zFile = new ZipFile(zipFile);
zFile.setFileNameCharset("GBK");
if (!zFile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能被损坏.");
}
File destDir = new File(dest);
if (destDir.isDirectory() && !destDir.exists()) {
destDir.mkdir();
}
if (zFile.isEncrypted()) {
zFile.setPassword(passwd.toCharArray());
}
zFile.extractAll(dest);
List<FileHeader> headerList = zFile.getFileHeaders();
List<File> extractedFileList = new ArrayList<File>();
for(FileHeader fileHeader : headerList) {
if (!fileHeader.isDirectory()) {
extractedFileList.add(new File(destDir,fileHeader.getFileName()));
}
}
File [] extractedFiles = new File[extractedFileList.size()];
extractedFileList.toArray(extractedFiles);
return extractedFiles;
}
示例5: unzip
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的package包/类
/**
* 使用给定密码解压指定的ZIP压缩文件到指定目录
* <p>
* 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
* @param zipFile 指定的ZIP压缩文件
* @param dest 解压目录
* @param passwd ZIP文件的密码
* @return 解压后文件数组
* @throws ZipException 压缩文件有损坏或者解压缩失败抛出
*/
public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException {
ZipFile zFile = new ZipFile(zipFile);
zFile.setFileNameCharset("GBK");
if (!zFile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能被损坏.");
}
File destDir = new File(dest);
if (destDir.isDirectory() && !destDir.exists()) {
destDir.mkdir();
}
if (zFile.isEncrypted()) {
zFile.setPassword(passwd.toCharArray());
}
zFile.extractAll(dest);
List<FileHeader> headerList = zFile.getFileHeaders();
List<File> extractedFileList = new ArrayList<File>();
for(FileHeader fileHeader : headerList) {
if (!fileHeader.isDirectory()) {
extractedFileList.add(new File(destDir,fileHeader.getFileName()));
}
}
File [] extractedFiles = new File[extractedFileList.size()];
extractedFileList.toArray(extractedFiles);
return extractedFiles;
}
示例6: unzip
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的package包/类
/**
* 使用给定密码解压指定的ZIP压缩文件到指定目录
* <p>
* 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
* @param zip 指定的ZIP压缩文件
* @param dest 解压目录
* @param passwd ZIP文件的密码
* @return 解压后文件数组
* @throws ZipException 压缩文件有损坏或者解压缩失败抛出
* @throws IOException
*/
public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException, IOException {
if(StringUtils.isEmpty(dest))
throw new ZipException("@@@@Error: Unzip destination can not be empty!!!!");
if(zipFile == null || !zipFile.exists())
throw new ZipException("@@@@Error: Unzip file not exist!!!!");
if(AppFileUtils.getContentType(zipFile.getName()).equals("rar")){
return unrar(zipFile,dest);
} else {
File destDir = new File(dest);
FileUtils.forceMkdir(destDir);
ZipFile zFile = new ZipFile(zipFile);
zFile.setFileNameCharset(Constants.GBK); //不可随意更换位置
if (!zFile.isValidZipFile()) {
throw new ZipException(String.format("@@@@Error: Unzip file: %s is broken!!!!",zipFile.getAbsolutePath()));
}
if (zFile.isEncrypted()) {
zFile.setPassword(passwd.toCharArray());
}
zFile.extractAll(dest);
@SuppressWarnings("unchecked")
List<FileHeader> headerList = zFile.getFileHeaders();
List<File> extractedFileList = new ArrayList<File>();
for (FileHeader fileHeader : headerList) {
if (!fileHeader.isDirectory()) {
File out = new File(destDir, fileHeader.getFileName());
extractedFileList.add(out);
log.debug("File to be extracted....." + out.getAbsolutePath());
}
}
File[] extractedFiles = new File[extractedFileList.size()];
extractedFileList.toArray(extractedFiles);
return extractedFiles;
}
}
示例7: unzip
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的package包/类
/**
* 使用给定密码解压指定的ZIP压缩文件到指定目录
* <p>
* 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
*
* @param zip
* 指定的ZIP压缩文件
* @param dest
* 解压目录
* @param passwd
* ZIP文件的密码
* @param charset
* ZIP文件的编码
* @return 解压后文件数组
* @throws ZipException
* 压缩文件有损坏或者解压缩失败抛出
*/
public static File[] unzip(File zipFile, String dest, String passwd,
String charset) throws ZipException {
ZipFile zFile = new ZipFile(zipFile);
if (null != charset || !"".equals(charset)) {
zFile.setFileNameCharset(charset);
}
if (!zFile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能被损坏.");
}
File destDir = new File(dest);
if (destDir.isDirectory() && !destDir.exists()) {
destDir.mkdir();
}
if (zFile.isEncrypted()) {
zFile.setPassword(passwd.toCharArray());
}
zFile.extractAll(dest);
List<FileHeader> headerList = zFile.getFileHeaders();
List<File> extractedFileList = new ArrayList<File>();
for (FileHeader fileHeader : headerList) {
if (!fileHeader.isDirectory()) {
extractedFileList.add(new File(destDir, fileHeader
.getFileName()));
}
}
File[] extractedFiles = new File[extractedFileList.size()];
extractedFileList.toArray(extractedFiles);
return extractedFiles;
}
示例8: removePreviousModVersion
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的package包/类
private void removePreviousModVersion(String modName, String installedVersion) {
File previousModZip = new File(cacheDir, modName + "-" + installedVersion + ".zip");
if (!previousModZip.exists()) {
Util.log("[File not Found] Could not delete '%s'.", previousModZip.getPath());
return;
}
try {
// Mod has been previously installed uninstall previous version
ZipFile zf = new ZipFile(previousModZip);
List<FileHeader> entries = zf.getFileHeaders();
// Go through zipfile of previous version and delete all file from
// Modpack that exist in the zip
for (FileHeader fileHeader : entries) {
if (fileHeader.isDirectory()) {
continue;
}
File file = new File(GameUpdater.modpackDir, fileHeader.getFileName());
Util.log("Deleting '%s'", file.getPath());
if (file.exists()) {
// File from mod exists.. delete it
file.delete();
}
}
InstalledModsYML.removeMod(modName);
} catch (ZipException e) {
e.printStackTrace();
}
}
示例9: ExtractSelectFilesWithInputStream
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的package包/类
public ExtractSelectFilesWithInputStream() {
ZipInputStream is = null;
OutputStream os = null;
try {
// Initiate the ZipFile
ZipFile zipFile = new ZipFile("C:\\ZipTest\\ExtractAllFilesWithInputStreams.zip");
String destinationPath = "c:\\ZipTest";
// If zip file is password protected then set the password
if (zipFile.isEncrypted()) {
zipFile.setPassword("password");
}
//Get the FileHeader of the File you want to extract from the
//zip file. Input for the below method is the name of the file
//For example: 123.txt or abc/123.txt if the file 123.txt
//is inside the directory abc
FileHeader fileHeader = zipFile.getFileHeader("yourfilename");
if (fileHeader != null) {
//Build the output file
String outFilePath = destinationPath + System.getProperty("file.separator") + fileHeader.getFileName();
File outFile = new File(outFilePath);
//Checks if the file is a directory
if (fileHeader.isDirectory()) {
//This functionality is up to your requirements
//For now I create the directory
outFile.mkdirs();
return;
}
//Check if the directories(including parent directories)
//in the output file path exists
File parentDir = outFile.getParentFile();
if (!parentDir.exists()) {
parentDir.mkdirs(); //If not create those directories
}
//Get the InputStream from the ZipFile
is = zipFile.getInputStream(fileHeader);
//Initialize the output stream
os = new FileOutputStream(outFile);
int readLen = -1;
byte[] buff = new byte[BUFF_SIZE];
//Loop until End of File and write the contents to the output stream
while ((readLen = is.read(buff)) != -1) {
os.write(buff, 0, readLen);
}
//Closing inputstream also checks for CRC of the the just extracted file.
//If CRC check has to be skipped (for ex: to cancel the unzip operation, etc)
//use method is.close(boolean skipCRCCheck) and set the flag,
//skipCRCCheck to false
//NOTE: It is recommended to close outputStream first because Zip4j throws
//an exception if CRC check fails
is.close();
//Close output stream
os.close();
//To restore File attributes (ex: last modified file time,
//read only flag, etc) of the extracted file, a utility class
//can be used as shown below
UnzipUtil.applyFileAttributes(fileHeader, outFile);
System.out.println("Done extracting: " + fileHeader.getFileName());
} else {
System.err.println("FileHeader does not exist");
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: unzip
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的package包/类
/**
* 使用给定密码解压指定的ZIP压缩文件到指定目录
* 如果指定目录不存在,可以自动创建,不合法的路径将导致异常被抛出
* @param zipFile 指定的ZIP压缩文件
* @param dest 解压目录(当此参数为空时,与源文件同级目录,若压缩内容为单文件或已存在文件夹,则直接解压;若文件为多文件,则创建一个与源文件同名的文件夹,将压缩内容解压至此文件)
* @param charset 编码方式
* @param passwd ZIP文件的密码
* @return
* @throws ZipException
*/
private static File[] unzip(File zipFile, File destDir,String charset, String passwd)
throws ZipException {
ZipFile zFile = new ZipFile(zipFile);
zFile.setFileNameCharset(charset);
if (!zFile.isValidZipFile()) {
throw new ZipException("压缩文件不合法,可能被损坏.");
}
@SuppressWarnings("unchecked")
List<FileHeader> headerList = zFile.getFileHeaders();
if(destDir==null){
//单文件
if(headerList.size()==1){
destDir = new File(zipFile.getParent() + File.separatorChar + headerList.get(0).getFileName());
}else{
String firstHeaderName = headerList.get(0).getFileName();
String lastHeaderName = headerList.get(headerList.size()-1).getFileName();
//当前压缩包根目录仅存在一个目录
if(firstHeaderName.indexOf(lastHeaderName)==0){
destDir = new File(zipFile.getParent() + File.separatorChar);
}else{//当前压缩包根目录存在至少两个文件
destDir = new File(FastFile.getFileNameNoSuffix(zipFile.getAbsoluteFile())+File.separatorChar);
}
}
}
if(!destDir.exists()){
destDir.mkdir();
}
if (zFile.isEncrypted()) {
if(StringUtils.isNotBlank(passwd)){
zFile.setPassword(passwd.toCharArray());
}else{
throw new ZipException("该压缩文件为加密压缩,请输入密码.");
}
}
zFile.extractAll(destDir.getAbsolutePath()+File.separatorChar);
List<File> extractedFileList = new ArrayList<File>();
for (FileHeader fileHeader : headerList) {
if (!fileHeader.isDirectory()) {
extractedFileList.add(new File(destDir, fileHeader
.getFileName()));
}
}
File[] extractedFiles = new File[extractedFileList.size()];
extractedFileList.toArray(extractedFiles);
return extractedFiles;
}
示例11: unzip
import net.lingala.zip4j.model.FileHeader; //导入方法依赖的package包/类
public static void unzip(File zipArchive, File destinationDirectory, @Nullable FileFilter skipFilter)
throws IOException {
try {
FileUtil.ensureDirectoryExists(destinationDirectory);
ZipFile zipFile = new ZipFile(zipArchive);
int count = 0;
for (Object fileHeader : zipFile.getFileHeaders()) {
if (count >= MAX_ZIP_ENTRY_COUNT) {
break;
}
FileHeader entry = (FileHeader) fileHeader;
File file = new File(destinationDirectory, entry.getFileName());
if (skipFilter != null && skipFilter.accept(file)) {
continue;
}
if (entry.isDirectory()) {
FileUtil.ensureDirectoryExists(file);
} else {
long maxSize = max(entry.getUncompressedSize(), entry.getCompressedSize());
if (maxSize <= MAX_ZIP_ENTRY_SIZE) {
FileUtil.ensureDirectoryExists(file.getParentFile());
zipFile.extractFile(entry, destinationDirectory.getAbsolutePath());
} else {
throw new IOException(String.format(
"Entry '%s' (%s) is larger than %s.",
entry.getFileName(), FileUtil.formatSize(maxSize),
FileUtil.formatSize(MAX_ZIP_ENTRY_SIZE)
));
}
}
++count;
}
} catch (ZipException e) {
throw new IOException("Can't extract ZIP-file to directory.", e);
}
}