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


Java ZipArchiveEntry类代码示例

本文整理汇总了Java中org.apache.commons.compress.archivers.zip.ZipArchiveEntry的典型用法代码示例。如果您正苦于以下问题:Java ZipArchiveEntry类的具体用法?Java ZipArchiveEntry怎么用?Java ZipArchiveEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ZipArchiveEntry类属于org.apache.commons.compress.archivers.zip包,在下文中一共展示了ZipArchiveEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractZip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
private void extractZip(ZipFile zipFile) {
  Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
  while (entries.hasMoreElements()) {

    ZipArchiveEntry entry = entries.nextElement();
    String fileName = entry.getName();
    File outputFile = new File(config.getExtractionFolder(), fileName);

    if (entry.isDirectory()) {
      makeDirectory(outputFile);
    } else {
      createNewFile(outputFile);
      try {
        InputStream inputStream = zipFile.getInputStream(entry);
        extractFile(inputStream, outputFile, fileName);
      } catch (IOException e) {
        throw new ExtractionException("Error extracting file '" + fileName + "' "
            + "from downloaded file: " + config.getDownloadTarget(), e);
      }
    }
  }
}
 
开发者ID:AlejandroRivera,项目名称:embedded-rabbitmq,代码行数:23,代码来源:BasicExtractor.java

示例2: makeOnlyUnZip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
public static void makeOnlyUnZip() throws ArchiveException, IOException{
		final InputStream is = new FileInputStream("D:/中文名字.zip");
		ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
		ZipArchiveEntry entry = entry = (ZipArchiveEntry) in.getNextEntry();
		
		String dir = "D:/cnname";
		File filedir = new File(dir);
		if(!filedir.exists()){
			filedir.mkdir();
		}
//		OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
		OutputStream out = new FileOutputStream(new File(filedir, entry.getName()));
		IOUtils.copy(in, out);
		out.close();
		in.close();
	}
 
开发者ID:h819,项目名称:spring-boot,代码行数:17,代码来源:CompressExample.java

示例3: getDownloadEntries

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
public Set<String> getDownloadEntries(final NodeRef downloadNode)
{
    return transactionHelper.doInTransaction(new RetryingTransactionCallback<Set<String>>()
    {
        @Override
        public Set<String> execute() throws Throwable
        {
            Set<String> entryNames = new TreeSet<String>();
            ContentReader reader = contentService.getReader(downloadNode, ContentModel.PROP_CONTENT);
            try (ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(reader.getContentInputStream()))
            {
                ZipArchiveEntry zipEntry = null;
                while ((zipEntry = zipInputStream.getNextZipEntry()) != null)
                {
                    String name = zipEntry.getName();
                    entryNames.add(name);
                }
            }
            return entryNames;
        }
    });
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:CMMDownloadTestUtil.java

示例4: testApache

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
public void testApache() throws IOException, ArchiveException {
	log.debug("testApache()");
	File zip = File.createTempFile("apache_", ".zip");
	
	// Create zip
	FileOutputStream fos = new FileOutputStream(zip);
	ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fos);
	aos.putArchiveEntry(new ZipArchiveEntry("coñeta"));
	aos.closeArchiveEntry();
	aos.close();
	
	// Read zip
	FileInputStream fis = new FileInputStream(zip);
	ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream("zip", fis);
	ZipArchiveEntry zae = (ZipArchiveEntry) ais.getNextEntry();
	assertEquals(zae.getName(), "coñeta");
	ais.close();
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:19,代码来源:ZipTest.java

示例5: contentImpl

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
@Override
public void contentImpl(NodeRef nodeRef, QName property, InputStream content, ContentData contentData, int index)
{
    // if the content stream to output is empty, then just return content descriptor as is
    if (content == null)
    {
        return;
    }
    
    try
    {
        // ALF-2016
        ZipArchiveEntry zipEntry=new ZipArchiveEntry(getPath());
        zipStream.putArchiveEntry(zipEntry);
        
        // copy export stream to zip
        copyStream(zipStream, content);
        
        zipStream.closeArchiveEntry();
        filesAddedCount = filesAddedCount + 1;
    }
    catch (IOException e)
    {
        throw new ExporterException("Failed to zip export stream", e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:27,代码来源:ZipDownloadExporter.java

示例6: importStream

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
public InputStream importStream(String content)
{
    ZipArchiveEntry zipEntry = zipFile.getEntry(content);
    if (zipEntry == null)
    {
        // Note: for some reason, when modifying a zip archive the path seperator changes
        // TODO: Need to investigate further as to why and whether this workaround is enough 
        content = content.replace('\\', '/');
        zipEntry = zipFile.getEntry(content);
        if (zipEntry == null)
        {
            throw new ImporterException("Failed to find content " + content + " within zip package");
        }
    }
    
    try
    {
        return zipFile.getInputStream(zipEntry);
    }
    catch (IOException e)
    {
        throw new ImporterException("Failed to open content " + content + " within zip package due to " + e.getMessage(), e);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:25,代码来源:ACPImportPackageHandler.java

示例7: postUnzipFileHook

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
/**
 * Hook called right after a file has been unzipped (during an install).
 * <p/>
 * The base class implementation makes sure to properly adjust set executable
 * permission on Linux and MacOS system if the zip entry was marked as +x.
 *
 * @param archive The archive that is being installed.
 * @param monitor The {@link ITaskMonitor} to display errors.
 * @param fileOp The {@link IFileOp} used by the archive installer.
 * @param unzippedFile The file that has just been unzipped in the install temp directory.
 * @param zipEntry The {@link ZipArchiveEntry} that has just been unzipped.
 */
public void postUnzipFileHook(
        Archive archive,
        ITaskMonitor monitor,
        IFileOp fileOp,
        File unzippedFile,
        ZipArchiveEntry zipEntry) {

    // if needed set the permissions.
    if (sUsingUnixPerm && fileOp.isFile(unzippedFile)) {
        // get the mode and test if it contains the executable bit
        int mode = zipEntry.getUnixMode();
        if ((mode & 0111) != 0) {
            try {
                fileOp.setExecutablePermission(unzippedFile);
            } catch (IOException ignore) {}
        }
    }

}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:32,代码来源:Package.java

示例8: downloadZipAndExtract

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
protected static void downloadZipAndExtract(final String url, final File targetDirectory) {
  download(url, inputStream -> {
    try {
      final byte[] bytes = IOUtils.toByteArray(inputStream);
      try (final ZipFile zipFile = new ZipFile(new SeekableInMemoryByteChannel(bytes))) {
        final Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
        while (entries.hasMoreElements()) {
          final ZipArchiveEntry entry = entries.nextElement();
          final File file = new File(targetDirectory, entry.getName());
          if (entry.isDirectory()) {
            file.mkdir();
            continue;
          }
          try (final OutputStream outputStream =
              new BufferedOutputStream(new FileOutputStream(file))) {
            IOUtils.copy(zipFile.getInputStream(entry), outputStream);
          }
        }
      }
    } catch (final IOException exception) {
      throw new RuntimeException(exception);
    }
  });
}
 
开发者ID:klaushauschild1984,项目名称:selenium-toys,代码行数:25,代码来源:AbstractDownloadingWebDriverFactory.java

示例9: TestBarInstaller

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
/**
 * barファイル内エントリのファイルサイズ上限値を超えた場合に例外が発生すること.
 */
@Test
public void barファイル内エントリのファイルサイズ上限値を超えた場合に例外が発生すること() {
    TestBarInstaller testBarInstaller = new TestBarInstaller();
    URL fileUrl = ClassLoader.getSystemResource("requestData/barInstall/V1_1_2_bar_minimum.bar");
    File file = new File(fileUrl.getPath());

    try {
        ZipFile zipFile = new ZipFile(file, "UTF-8");
        Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
        long maxBarEntryFileSize = 0;
        while (entries.hasMoreElements()) {
            ZipArchiveEntry zae = entries.nextElement();
            if (zae.isDirectory()) {
                continue;
            }
            testBarInstaller.checkBarFileEntrySize(zae, zae.getName(), maxBarEntryFileSize);
        }
        fail("Unexpected exception");
    } catch (PersoniumCoreException dce) {
        String code = PersoniumCoreException.BarInstall.BAR_FILE_ENTRY_SIZE_TOO_LARGE.getCode();
        assertEquals(code, dce.getCode());
    } catch (Exception ex) {
        fail("Unexpected exception");
    }
}
 
开发者ID:personium,项目名称:personium-core,代码行数:29,代码来源:BarFileValidateTest.java

示例10: handle

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
@Override
public List<ProcessTask> handle(EntityManager manager) throws Exception {
    if (!file.exists()) {
        return todo;
    }
    try (ZipFile zip = new ZipFile(file)) {
        for (ZipArchiveEntry entry : new IteratorIterable<>(new EnumerationIterator<>(zip.getEntries()))) {
            try {
                handleSingleZipEntry(zip, entry, manager);
            } catch (IOException ex) {
                System.out.println(ex.getLocalizedMessage());
            }
        }
    }
    return todo;
}
 
开发者ID:Idrinths-Stellaris-Mods,项目名称:Mod-Tools,代码行数:17,代码来源:ZipContentParser.java

示例11: getStroomZipNameSet

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
public StroomZipNameSet getStroomZipNameSet() throws IOException {
	if (stroomZipNameSet == null) {
		stroomZipNameSet = new StroomZipNameSet(false);
		Enumeration<ZipArchiveEntry> entryE = getZipFile().getEntries();

		while (entryE.hasMoreElements()) {
			ZipArchiveEntry entry = entryE.nextElement();

			// Skip Dir's
			if (!entry.isDirectory()) {
				String fileName = entry.getName();
				stroomZipNameSet.add(fileName);
			}

			long entrySize = entry.getSize();
			if (entrySize == -1 || totalSize == -1) {
				// Can nolonger sum
			} else {
				totalSize += entrySize;
			}

		}

	}
	return stroomZipNameSet;
}
 
开发者ID:gchq,项目名称:stroom-agent,代码行数:27,代码来源:StroomZipFile.java

示例12: unZip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
public static void unZip(Path file, Path target) throws IOException {
    try (final ZipFile zipFile = new ZipFile(file.toFile())) {
        final Enumeration<ZipArchiveEntry> files = zipFile.getEntriesInPhysicalOrder();
        while (files.hasMoreElements()) {
            final ZipArchiveEntry entry = files.nextElement();
            final Path entryFile = target.resolve(REMOVE_LEADING_GO_PATH_PATTERN.matcher(entry.getName()).replaceFirst("")).toAbsolutePath();
            if (entry.isDirectory()) {
                createDirectoriesIfRequired(entryFile);
            } else {
                ensureParentOf(entryFile);
                try (final InputStream is = zipFile.getInputStream(entry)) {
                    try (final OutputStream os = newOutputStream(entryFile)) {
                        copy(is, os);
                    }
                }
            }
        }
    }
}
 
开发者ID:echocat,项目名称:gradle-golang-plugin,代码行数:20,代码来源:ArchiveUtils.java

示例13: unZipToFolder

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
/**
 * 把一个ZIP文件解压到一个指定的目录中
 * @param zipfilename ZIP文件抽象地址
 * @param outputdir 目录绝对地址
 */
public static void unZipToFolder(String zipfilename, String outputdir) throws IOException {
    File zipfile = new File(zipfilename);
    if (zipfile.exists()) {
        outputdir = outputdir + File.separator;
        FileUtils.forceMkdir(new File(outputdir));

        ZipFile zf = new ZipFile(zipfile, "UTF-8");
        Enumeration zipArchiveEntrys = zf.getEntries();
        while (zipArchiveEntrys.hasMoreElements()) {
            ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) zipArchiveEntrys.nextElement();
            if (zipArchiveEntry.isDirectory()) {
                FileUtils.forceMkdir(new File(outputdir + zipArchiveEntry.getName() + File.separator));
            } else {
                IOUtils.copy(zf.getInputStream(zipArchiveEntry), FileUtils.openOutputStream(new File(outputdir + zipArchiveEntry.getName())));
            }
        }
    } else {
        throw new IOException("指定的解压文件不存在:\t" + zipfilename);
    }
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:26,代码来源:CompressExample.java

示例14: makeOnlyZip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
public static void makeOnlyZip() throws IOException, ArchiveException{
	File f1 = new File("D:/compresstest.txt");
       File f2 = new File("D:/test1.xml");
       
       final OutputStream out = new FileOutputStream("D:/中文名字.zip");
       ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, out);
       
       os.putArchiveEntry(new ZipArchiveEntry(f1.getName()));
       IOUtils.copy(new FileInputStream(f1), os);
       os.closeArchiveEntry();

       os.putArchiveEntry(new ZipArchiveEntry(f2.getName()));
       IOUtils.copy(new FileInputStream(f2), os);
       os.closeArchiveEntry();
       os.close();
}
 
开发者ID:h819,项目名称:spring-boot,代码行数:17,代码来源:CompressExample.java

示例15: addFilesToZip

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; //导入依赖的package包/类
void addFilesToZip(File source, File destination) throws IOException, ArchiveException {
    OutputStream archiveStream = new FileOutputStream(destination);
    ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, archiveStream);
    Collection<File> fileList = FileUtils.listFiles(source, null, true);
    for (File file : fileList) {
        String entryName = getEntryName(source, file);
        ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
        archive.putArchiveEntry(entry);
        BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(input, archive);
        input.close();
        archive.closeArchiveEntry();
    }
    archive.finish();
    archiveStream.close();
}
 
开发者ID:spirylics,项目名称:web2app,代码行数:17,代码来源:Npm.java


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