本文整理汇总了Java中net.lingala.zip4j.core.ZipFile.getFileHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.getFileHeaders方法的具体用法?Java ZipFile.getFileHeaders怎么用?Java ZipFile.getFileHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.lingala.zip4j.core.ZipFile
的用法示例。
在下文中一共展示了ZipFile.getFileHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
示例2: 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();
}
}
示例3: expandArtifact
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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);
}
}
示例4: zipContents
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
* returns an array of files in zipfileName(fileName.zip)
* @param zipfileName
* @return
*/
public static String[] zipContents(String zipfileName)
{
try
{
// Initiate ZipFile object with the path/name of the zip file.
ZipFile zipFile = new ZipFile(zipfileName);
// Get the list of file headers from the zip file
List<FileHeader> headers = zipFile.getFileHeaders();
String[] fileNames = new String[headers.size()];
// Loop through the file headers
for(int i = 0; i < headers.size(); i++)
{
FileHeader header = headers.get(i);
fileNames[i] = header.getFileName();
}
return fileNames;
}
catch (ZipException e)
{
Log.error("Zip Error",e);
}
return null;
}
示例5: getUnzippedFileSize
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
*
* @param filename of the zip (including ext.)
* @return integer, total unpacked size of all the files that are in the zipfile
*/
public static int getUnzippedFileSize(String fileName)
{
int size = 0;
try
{
ZipFile zipfile = new ZipFile(fileName);
List<FileHeader> headers = zipfile.getFileHeaders();
for(FileHeader header : headers)
{
size += header.getUncompressedSize();
}
}
catch(Exception e)
{
Log.error("Error inspecting zip file "+fileName);
}
return size;
}
示例6: withData
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
private void withData() throws Exception {
FileUtil fileUtil = new FileUtil();
File dataFile = new File(fileUtil.getBaseFolderName() + "data.zip");
dataZip = new ZipFile(dataFile);
if (dataZip.getFileHeaders() != null) {
List fileHeaderList = dataZip.getFileHeaders();
ProgressModel progressModel = new ProgressModel();
progressModel.setMax(fileHeaderList.size());
publishProgress(progressModel);
List<FileHeader> headers = dataZip.getFileHeaders();
for (FileHeader header : headers) {
dataZip.extractFile(header, fileUtil.getBaseFolderName());
copyFileToData(fileUtil.getBaseFolderName(), header.getFileName());
}
}
FileUtils.forceDelete(dataFile);
}
示例7: read
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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("/", ""));
}
}
}
示例8: printZipInfo
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
* 打印zip文件信息
*
* @param path
*/
public static void printZipInfo(String path) {
try {
ZipFile zipFile = new ZipFile(path);
List fileHeaderList = zipFile.getFileHeaders();
for (int i = 0; i < fileHeaderList.size(); i++) {
FileHeader fileHeader = (FileHeader) fileHeaderList.get(i);
// FileHeader包含zip文件中对应文件的很多属性
System.out.println("****File Details for: " + fileHeader.getFileName() + "*****");
System.out.println("文件名: " + fileHeader.getFileName());
System.out.println("是否为目录: " + fileHeader.isDirectory());
System.out.println("压缩后大小: " + fileHeader.getCompressedSize());
System.out.println("未压缩大小: " + fileHeader.getUncompressedSize());
System.out.println("************************************************************");
}
} catch (ZipException e) {
e.printStackTrace();
}
}
示例9: getZipArchiveInfo
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static ZipArchiveInfo getZipArchiveInfo(File zipFile) throws IOException {
try {
ZipFile internalZipFile = new ZipFile(zipFile);
long totalSize = 0;
long entryCount = 0;
for (Object fileHeader : internalZipFile.getFileHeaders()) {
FileHeader entry = (FileHeader) fileHeader;
long size = entry.getUncompressedSize();
if (size > 0L) {
totalSize += size;
}
++entryCount;
}
return new ZipArchiveInfo(totalSize, entryCount);
} catch (ZipException e) {
throw new IOException("Can't get ZIP-archive info.", e);
}
}
示例10: unzip
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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;
}
示例11: unzip
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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;
}
示例12: loadMap
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
* Tries to load the map data for a name
*
* @param name the name of the map to load
* @return the loaded map
* @throws MapException when
*/
@Nonnull
public Map loadMap(@Nonnull String name) {
Optional<Map> map = getMap(name);
if (!map.isPresent()) {
Optional<MapInfo> mapInfo = getMapInfo(name);
if (!mapInfo.isPresent()) {
throw new MapException(
"Unknown map " + name + ". Did you register it into the world config?");
}
try {
ZipFile zipFile = new ZipFile(new File(worldsFolder, mapInfo.get().getName() + ".zip"));
for (FileHeader header : (List<FileHeader>) zipFile.getFileHeaders()) {
if (header.getFileName().endsWith("config.json")) {
InputStream stream = zipFile.getInputStream(header);
Map m = gson.fromJson(new JsonReader(new InputStreamReader(stream)), Map.class);
m.initMarkers(mapHandler);
maps.add(m);
return m;
}
}
throw new MapException("Could not load map config for map " + name
+ ". Fileheader was null. Does it has a map.json?");
} catch (Exception e) {
throw new MapException("Error while trying to load map config " + name, e);
}
} else {
return map.get();
}
}
示例13: loadMap
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
* Tries to load the map data for a name
*
* @param name the name of the map to load
* @return the loaded map
* @throws MapException when
*/
@Nonnull
public Map loadMap(@Nonnull String name) {
Optional<Map> map = getMap(name);
if (!map.isPresent()) {
if (!getMapInfo(name).isPresent()) {
throw new MapException("Unknown map " + name + ". Did you register it into the world config?");
}
try {
ZipFile zipFile = new ZipFile(new File(worldsFolder, name + ".zip"));
for (FileHeader header : (List<FileHeader>) zipFile.getFileHeaders()) {
if (header.getFileName().endsWith("config.json")) {
InputStream stream = zipFile.getInputStream(header);
Map m = gson.fromJson(new JsonReader(new InputStreamReader(stream)), Map.class);
maps.add(m);
return m;
}
}
throw new MapException("Could not load map config for map " + name + ". Fileheader was null. Does it has a map.json?");
} catch (Exception e) {
throw new MapException("Error while trying to load map config " + name, e);
}
} else {
return map.get();
}
}
示例14: listForPattern
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static List<FileHeader> listForPattern(File zipFile, String regex){
List<FileHeader> list = new ArrayList<>();
Pattern p = Pattern.compile(regex);
// Pattern p = Pattern.compile("[^/]*\\.dex");
try {
if(!FileHelper.exists(zipFile)){
return new ArrayList<>(0);
}
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
FileHeader fileHeader = (FileHeader) fileHeaderList.get(i);
Matcher matcher = p.matcher(fileHeader.getFileName());
if(matcher.matches()){
list.add(fileHeader);
}
}
return list;
} catch (ZipException e) {
e.printStackTrace();
}
return new ArrayList<>(0);
}
示例15: ListAllFilesInZipFile
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public ListAllFilesInZipFile() {
try {
// Initiate ZipFile object with the path/name of the zip file.
ZipFile zipFile = new ZipFile("c:\\ZipTest\\ListAllFilesInZipFile.zip");
// Get the list of file headers from the zip file
List fileHeaderList = zipFile.getFileHeaders();
// Loop through the file headers
for (int i = 0; i < fileHeaderList.size(); i++) {
FileHeader fileHeader = (FileHeader)fileHeaderList.get(i);
// FileHeader contains all the properties of the file
System.out.println("****File Details for: " + fileHeader.getFileName() + "*****");
System.out.println("Name: " + fileHeader.getFileName());
System.out.println("Compressed Size: " + fileHeader.getCompressedSize());
System.out.println("Uncompressed Size: " + fileHeader.getUncompressedSize());
System.out.println("CRC: " + fileHeader.getCrc32());
System.out.println("************************************************************");
// Various other properties are available in FileHeader. Please have a look at FileHeader
// class to see all the properties
}
} catch (ZipException e) {
e.printStackTrace();
}
}