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


Java ZipFile.getFileHeader方法代码示例

本文整理汇总了Java中net.lingala.zip4j.core.ZipFile.getFileHeader方法的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.getFileHeader方法的具体用法?Java ZipFile.getFileHeader怎么用?Java ZipFile.getFileHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.lingala.zip4j.core.ZipFile的用法示例。


在下文中一共展示了ZipFile.getFileHeader方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extract

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
private byte[] extract(ZipFile zipFile, String file, boolean isFileMandatory) throws ZipException, IOException {
    // Files in the zip are flattened, so remove the folder prefix if there is one
    String fileName = getFileNameFromPath(file);

    // Extract from zip
    FileHeader header = zipFile.getFileHeader(fileName);
    if (header == null) {
        if (isFileMandatory) {
            // Mandatory file not found - throw exception
            throw new IllegalArgumentException(String.format("File %s missing from model run outputs", fileName));
        } else {
            // Optional file not found - return null
            return null;
        }
    } else {
        try (ZipInputStream inputStream = zipFile.getInputStream(header)) {
            return IOUtils.toByteArray(inputStream);
        }
    }
}
 
开发者ID:SEEG-Oxford,项目名称:ABRAID-MP,代码行数:21,代码来源:MainHandler.java

示例2: verifyBackupFile

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static boolean verifyBackupFile(File file) {
    try {
        ZipFile zipFile = new ZipFile(file);
        FileHeader preferences = zipFile.getFileHeader(BACKUP_PREFERENCES_PATH);
        FileHeader notificationRules = zipFile.getFileHeader(BACKUP_NOTIFICATION_RULES_PATH);
        FileHeader commandAliases = zipFile.getFileHeader(BACKUP_COMMAND_ALIASES_PATH);
        return preferences != null && notificationRules != null && commandAliases != null;
    } catch (ZipException e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:13,代码来源:BackupManager.java

示例3: isBackupPasswordProtected

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static boolean isBackupPasswordProtected(File file) {
    try {
        ZipFile zipFile = new ZipFile(file);
        FileHeader preferences = zipFile.getFileHeader(BACKUP_PREFERENCES_PATH);
        return preferences.isEncrypted();
    } catch (ZipException e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:11,代码来源:BackupManager.java

示例4: hasFile

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * 是否包含指定文件
 *
 * @param zip
 * @param fileName
 * @return
 */
public static boolean hasFile(ZipFile zip, String fileName){
    try {
        return zip.getFileHeader(fileName) != null;
    } catch (ZipException e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:16,代码来源:ZipUtils.java

示例5: readManufacturerFiles

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * Read the files of a manufacturer.
 *
 * @param zip The ZIP file to read from
 * @param manufacturerKey The zip file key of the manufacturer, e.g. "M-0004"
 * @throws ZipException
 */
void readManufacturerFiles(ZipFile zip, String manufacturerKey) throws ZipException
{
   LOGGER.info("Reading files of manufacturer {}", manufacturerKey);

   String catalogFileName = manufacturerKey + "/Catalog.xml";
   FileHeader catalogFileHeader = zip.getFileHeader(catalogFileName);
   if (catalogFileHeader == null)
   {
      LOGGER.info("Skipping {}: no catalog file {} found", manufacturerKey, catalogFileName);
      return;
   }

   String hardwareFileName = manufacturerKey + "/Hardware.xml";
   FileHeader hardwareFileHeader = zip.getFileHeader(hardwareFileName);
   if (hardwareFileHeader == null)
   {
      LOGGER.info("Skipping {}: no hardware file {} found", manufacturerKey, hardwareFileName);
      return;
   }

   LOGGER.info("Reading {}", catalogFileName);
   KnxDocument catalogDocument = readXml(zip.getInputStream(catalogFileHeader), catalogFileName);

   LOGGER.info("Reading {}", hardwareFileName);
   KnxDocument hardwareDocument = readXml(zip.getInputStream(hardwareFileHeader), hardwareFileName);

   // Process the product files of the manufacturer
   String filePrefix = manufacturerKey + '/' + manufacturerKey + '_';
   @SuppressWarnings("unchecked")
   List<FileHeader> fileHeaders = zip.getFileHeaders();
   for (FileHeader fileHeader : fileHeaders)
   {
      if (fileHeader.getFileName().startsWith(filePrefix))
      {
         LOGGER.info("Reading {}", fileHeader.getFileName());
         KnxDocument productsDocument = readXml(zip.getInputStream(fileHeader), fileHeader.getFileName());
      }
   }
}
 
开发者ID:selfbus,项目名称:tools-libraries,代码行数:47,代码来源:KnxprodReader.java

示例6: removeDirFromZipArchive

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * 删除压缩文件中的目录
 * 
 * @param file
 *            目标zip文件
 * @param removeDir
 *            要移除的目录
 * @param charset
 *            编码
 * @throws ZipException
 */
@SuppressWarnings("rawtypes")
private static void removeDirFromZipArchive(String file, String removeDir,
		String charset) throws ZipException {
	// 创建ZipFile并设置编码
	ZipFile zipFile = new ZipFile(file);

	if (null != charset || !"".equals(charset)) {
		zipFile.setFileNameCharset(charset);
	}

	// 给要删除的目录加上路径分隔符
	if (!removeDir.endsWith(File.separator))
		removeDir += File.separator;

	// 如果目录不存在, 直接返回
	FileHeader dirHeader = zipFile.getFileHeader(removeDir);
	if (null == dirHeader)
		return;

	// 遍历压缩文件中所有的FileHeader, 将指定删除目录下的子文件名保存起来
	List headersList = zipFile.getFileHeaders();
	List<String> removeHeaderNames = new ArrayList<String>();
	for (int i = 0, len = headersList.size(); i < len; i++) {
		FileHeader subHeader = (FileHeader) headersList.get(i);
		if (subHeader.getFileName().startsWith(dirHeader.getFileName())
				&& !subHeader.getFileName().equals(dirHeader.getFileName())) {
			removeHeaderNames.add(subHeader.getFileName());
		}
	}
	// 遍历删除指定目录下的所有子文件, 最后删除指定目录(此时已为空目录)
	for (String headerNameString : removeHeaderNames) {
		zipFile.removeFile(headerNameString);
	}
	zipFile.removeFile(dirHeader);
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:47,代码来源:CompressUtil.java

示例7: extract

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
@Override
public InputStream extract(File zip, String fileName, String password) throws ZipException {
    try {
        ZipFile zipFile = new ZipFile(zip);
        if ((password != null) && zipFile.isEncrypted()) {
            zipFile.setPassword(password);
        }
        FileHeader fh = zipFile.getFileHeader(fileName);
        return zipFile.getInputStream(fh);
    } catch (net.lingala.zip4j.exception.ZipException e) {
        throw new ZipException(e);
    }
}
 
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:14,代码来源:ZipDelegaterZip4j.java

示例8: ExtractSelectFilesWithInputStream

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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();
	}
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:80,代码来源:ExtractSelectFilesWithInputStream.java

示例9: activateApp

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
private void activateApp(App app)
{
	FileMeta appSourceArchive = app.getSourceFiles();
	if (appSourceArchive != null)
	{
		File fileStoreFile = fileStore.getFile(appSourceArchive.getId());
		if (fileStoreFile == null)
		{
			LOG.error("Source archive '{}' for app '{}' missing in file store", appSourceArchive.getId(),
					app.getName());
			throw new RuntimeException("An error occurred trying to activate app");
		}

		try
		{
			ZipFile zipFile = new ZipFile(fileStoreFile);
			if (!app.getUseFreemarkerTemplate())
			{
				FileHeader fileHeader = zipFile.getFileHeader("index.html");
				if (fileHeader == null)
				{
					LOG.error(
							"Missing index.html in {} while option Use freemarker template as index.html was set 'No'",
							app.getName());
					throw new RuntimeException(
							format("Missing index.html in %s while option 'Use freemarker template as index.html' was set 'No'",
									app.getName()));
				}
			}
			//noinspection StringConcatenationMissingWhitespace
			zipFile.extractAll(
					fileStore.getStorageDir() + separatorChar + FILE_STORE_PLUGIN_APPS_PATH + separatorChar
							+ app.getId() + separatorChar);
		}
		catch (ZipException e)
		{
			LOG.error("", e);
			throw new RuntimeException(format("An error occurred activating app '%s'", app.getName()));
		}
	}
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:42,代码来源:AppRepositoryDecorator.java


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