本文整理匯總了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();
}
}