当前位置: 首页>>代码示例>>Java>>正文


Java FileHeader类代码示例

本文整理汇总了Java中net.lingala.zip4j.model.FileHeader的典型用法代码示例。如果您正苦于以下问题:Java FileHeader类的具体用法?Java FileHeader怎么用?Java FileHeader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileHeader类属于net.lingala.zip4j.model包,在下文中一共展示了FileHeader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: calculateTotalWork

import net.lingala.zip4j.model.FileHeader; //导入依赖的package包/类
private long calculateTotalWork(ArrayList fileHeaders) throws ZipException {
	
	if (fileHeaders == null) {
		throw new ZipException("fileHeaders is null, cannot calculate total work");
	}
	
	long totalWork = 0;
	
	for (int i = 0; i < fileHeaders.size(); i++) {
		FileHeader fileHeader = (FileHeader)fileHeaders.get(i);
		if (fileHeader.getZip64ExtendedInfo() != null && 
				fileHeader.getZip64ExtendedInfo().getUnCompressedSize() > 0) {
			totalWork += fileHeader.getZip64ExtendedInfo().getCompressedSize();
		} else {
			totalWork += fileHeader.getCompressedSize();
		}
		
	}
	
	return totalWork;
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:22,代码来源:Unzip.java

示例3: list

import net.lingala.zip4j.model.FileHeader; //导入依赖的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();
    }
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:28,代码来源:ZipUtils.java

示例4: unzipDexList

import net.lingala.zip4j.model.FileHeader; //导入依赖的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);
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:23,代码来源:MultDexSupport.java

示例5: removeZipFile

import net.lingala.zip4j.model.FileHeader; //导入依赖的package包/类
public HashMap removeZipFile(final ZipModel zipModel, 
		final FileHeader fileHeader, final ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
	
	if (runInThread) {
		Thread thread = new Thread(InternalZipConstants.THREAD_NAME) {
			public void run() {
				try {
					initRemoveZipFile(zipModel, fileHeader, progressMonitor);
					progressMonitor.endProgressMonitorSuccess();
				} catch (ZipException e) {
				}
			}
		};
		thread.start();
		return null;
	} else {
		HashMap retMap = initRemoveZipFile(zipModel, fileHeader, progressMonitor);
		progressMonitor.endProgressMonitorSuccess();
		return retMap;
	}
	
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:23,代码来源:ArchiveMaintainer.java

示例6: getFileHeader

import net.lingala.zip4j.model.FileHeader; //导入依赖的package包/类
public static FileHeader getFileHeader(ZipModel zipModel, String fileName) throws ZipException {
	if (zipModel == null) {
		throw new ZipException("zip model is null, cannot determine file header for fileName: " + fileName);
	}
	
	if (!isStringNotNullAndNotEmpty(fileName)) {
		throw new ZipException("file name is null, cannot determine file header for fileName: " + fileName);
	}
	
	FileHeader fileHeader = null;
	fileHeader = getFileHeaderWithExactMatch(zipModel, fileName);
	
	if (fileHeader == null) {
		fileName = fileName.replaceAll("\\\\", "/");
		fileHeader = getFileHeaderWithExactMatch(zipModel, fileName);
		
		if (fileHeader == null) {
			fileName = fileName.replaceAll("/", "\\\\");
			fileHeader = getFileHeaderWithExactMatch(zipModel, fileName);
		}
	}
	
	return fileHeader;
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:25,代码来源:Zip4jUtil.java

示例7: extractFile

import net.lingala.zip4j.model.FileHeader; //导入依赖的package包/类
/**
 * Extracts a specific file from the zip file to the destination path.
 * If destination path is invalid, then this method throws an exception.
 * @param fileHeader
 * @param destPath
 * @param unzipParameters
 * @param newFileName
 * @throws ZipException
 */
public void extractFile(FileHeader fileHeader, String destPath, 
		UnzipParameters unzipParameters, String newFileName) throws ZipException {
	
	if (fileHeader == null) {
		throw new ZipException("input file header is null, cannot extract file");
	}
	
	if (!Zip4jUtil.isStringNotNullAndNotEmpty(destPath)) {
		throw new ZipException("destination path is empty or null, cannot extract file");
	}
	
	readZipInfo();
	
	if (progressMonitor.getState() == ProgressMonitor.STATE_BUSY) {
		throw new ZipException("invalid operation - Zip4j is in busy state");
	}
	
	fileHeader.extractFile(zipModel, destPath, unzipParameters, newFileName, progressMonitor, runInThread);
	
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:30,代码来源:ZipFile.java

示例8: setPassword

import net.lingala.zip4j.model.FileHeader; //导入依赖的package包/类
/**
 * Sets the password for the zip file
 * @param password
 * @throws ZipException
 */
public void setPassword(char[] password) throws ZipException {
	if (zipModel == null) {
		readZipInfo();
		if (zipModel == null) {
			throw new ZipException("Zip Model is null");
		}
	}
	
	if (zipModel.getCentralDirectory() == null || zipModel.getCentralDirectory().getFileHeaders() == null) {
		throw new ZipException("invalid zip file");
	}
	
	for (int i = 0; i < zipModel.getCentralDirectory().getFileHeaders().size(); i++) {
		if (zipModel.getCentralDirectory().getFileHeaders().get(i) != null) {
			if (((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).isEncrypted()) {
				((FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i)).setPassword(password);
			}
		}
	}
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:26,代码来源:ZipFile.java

示例9: isEncrypted

import net.lingala.zip4j.model.FileHeader; //导入依赖的package包/类
/**
 * Checks to see if the zip file is encrypted
 * @return true if encrypted, false if not
 * @throws ZipException
 */
public boolean isEncrypted() throws ZipException {
	if (zipModel == null) {
		readZipInfo();
		if (zipModel == null) {
			throw new ZipException("Zip Model is null");
		}
	}
	
	if (zipModel.getCentralDirectory() == null || zipModel.getCentralDirectory().getFileHeaders() == null) {
		throw new ZipException("invalid zip file");
	}
	
	ArrayList fileHeaderList = zipModel.getCentralDirectory().getFileHeaders();
	for (int i = 0; i < fileHeaderList.size(); i++) {
		FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);
		if (fileHeader != null) {
			if (fileHeader.isEncrypted()) {
				isEncrypted = true;
				break;
			}
		}
	}
	
	return isEncrypted;
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:31,代码来源:ZipFile.java

示例10: removeFile

import net.lingala.zip4j.model.FileHeader; //导入依赖的package包/类
/**
 * Removes the file provided in the input paramters from the zip file.
 * This method first finds the file header and then removes the file.
 * If file does not exist, then this method throws an exception.
 * If zip file is a split zip file, then this method throws an exception as
 * zip specification does not allow for updating split zip archives.
 * @param fileName
 * @throws ZipException
 */
public void removeFile(String fileName) throws ZipException {
	
	if (!Zip4jUtil.isStringNotNullAndNotEmpty(fileName)) {
		throw new ZipException("file name is empty or null, cannot remove file");
	}
	
	if (zipModel == null) {
		if (Zip4jUtil.checkFileExists(file)) {
			readZipInfo();
		}
	}
	
	if (zipModel.isSplitArchive()) {
		throw new ZipException("Zip file format does not allow updating split/spanned files");
	}
	
	FileHeader fileHeader = Zip4jUtil.getFileHeader(zipModel, fileName);
	if (fileHeader == null) {
		throw new ZipException("could not find file header for file: " + fileName);
	}
	
	removeFile(fileHeader);
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:33,代码来源:ZipFile.java

示例11: writeCentralDirectory

import net.lingala.zip4j.model.FileHeader; //导入依赖的package包/类
/**
 * Writes central directory header data to an array list
 * @param zipModel
 * @param outputStream
 * @param headerBytesList
 * @return size of central directory
 * @throws ZipException
 */
private int writeCentralDirectory(ZipModel zipModel, 
		OutputStream outputStream, List headerBytesList) throws ZipException {
	if (zipModel == null || outputStream == null) {
		throw new ZipException("input parameters is null, cannot write central directory");
	}
	
	if (zipModel.getCentralDirectory() == null || 
			zipModel.getCentralDirectory().getFileHeaders() == null || 
			zipModel.getCentralDirectory().getFileHeaders().size() <= 0) {
		return 0;
	}
	
	int sizeOfCentralDir = 0;
	for (int i = 0; i < zipModel.getCentralDirectory().getFileHeaders().size(); i++) {
		FileHeader fileHeader = (FileHeader)zipModel.getCentralDirectory().getFileHeaders().get(i);
		int sizeOfFileHeader = writeFileHeader(zipModel, fileHeader, outputStream, headerBytesList);
		sizeOfCentralDir += sizeOfFileHeader;
	}
	return sizeOfCentralDir;
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:29,代码来源:HeaderWriter.java

示例12: readAndSaveExtraDataRecord

import net.lingala.zip4j.model.FileHeader; //导入依赖的package包/类
/**
 * Reads extra data record and saves it in the {@link FileHeader}
 * @param fileHeader
 * @throws ZipException
 */
private void readAndSaveExtraDataRecord(FileHeader fileHeader) throws ZipException {
	
	if (zip4jRaf == null) {
		throw new ZipException("invalid file handler when trying to read extra data record");
	}
	
	if (fileHeader == null) {
		throw new ZipException("file header is null");
	}
	
	int extraFieldLength = fileHeader.getExtraFieldLength(); 
	if (extraFieldLength <= 0) {
		return;
	}
	
	fileHeader.setExtraDataRecords(readExtraDataRecords(extraFieldLength));
	
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:24,代码来源:HeaderReader.java

示例13: readAndSaveAESExtraDataRecord

import net.lingala.zip4j.model.FileHeader; //导入依赖的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);
	}
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:21,代码来源:HeaderReader.java

示例14: zipInfo

import net.lingala.zip4j.model.FileHeader; //导入依赖的package包/类
public static double zipInfo(String zipFile) throws ZipException {
    net.lingala.zip4j.core.ZipFile zip = new net.lingala.zip4j.core.ZipFile(zipFile);
    zip.setFileNameCharset("GBK");
    List<FileHeader> list = zip.getFileHeaders();
    long zipCompressedSize = 0;
    for (FileHeader head : list) {
        zipCompressedSize += head.getCompressedSize();
        //      System.out.println(zipFile+"文件相关信息如下:");
        //      System.out.println("Name: "+head.getFileName());
        //      System.out.println("Compressed Size:"+(head.getCompressedSize()/1.0/1024)+"kb");
        //      System.out.println("Uncompressed Size:"+(head.getUncompressedSize()/1.0/1024)+"kb");
        //      System.out.println("CRC32:"+head.getCrc32());
        //      System.out.println("*************************************");
    }
    double size = zipCompressedSize / 1.0 / 1024;//转换为kb
    return size;
}
 
开发者ID:vondear,项目名称:RxTools,代码行数:18,代码来源:RxZipTool.java

示例15: 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);
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:18,代码来源:BuildTool.java


注:本文中的net.lingala.zip4j.model.FileHeader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。