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


Java ZipArchiveInputStream类代码示例

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


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

示例1: getDownloadEntries

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的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

示例2: unZipFiles

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
public static void unZipFiles(InputStream instream, String ID)
		throws IOException {
	ZipArchiveInputStream zin = new ZipArchiveInputStream(instream);
	java.util.zip.ZipEntry entry = null;
	while ((entry = zin.getNextZipEntry()) != null) {
		String zipEntryName = entry.getName();
		String outPath = zipEntryName.replaceAll("\\*", "/");
		String path = "lib";
		path += zipEntryName.substring(zipEntryName.indexOf('/'), zipEntryName.length());
		System.out.println("[path ]:" + path);
		if (!outPath.endsWith("/")) {
			InputStream in = zin;
			HDFSIO.uploadModel("/" + ID + "/" + path, in);
		}
	}
	zin.close();
}
 
开发者ID:ICT-BDA,项目名称:EasyML,代码行数:18,代码来源:FileUploadServlet.java

示例3: importEntitiesFromZIP

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
@Override
public Collection<Entity> importEntitiesFromZIP(byte[] zipBytes, EntityImportView view) {
    Collection<Entity> result = new ArrayList<>();
    Collection<? extends Entity> entities;
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(zipBytes);
    ZipArchiveInputStream archiveReader = new ZipArchiveInputStream(byteArrayInputStream);
    try {
        try {
            while (archiveReader.getNextZipEntry() != null) {
                String json = new String(readBytesFromEntry(archiveReader), StandardCharsets.UTF_8);
                entities = entitySerialization.entitiesCollectionFromJson(json,
                        null,
                        EntitySerializationOption.COMPACT_REPEATED_ENTITIES);
                result.addAll(importEntities(entities, view));
            }
        } catch (IOException e) {
            throw new RuntimeException("Exception occurred while importing report", e);
        }
    } finally {
        IOUtils.closeQuietly(archiveReader);
    }
    return result;
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:24,代码来源:EntityImportExport.java

示例4: getHashesFromZipFile

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
public List<String> getHashesFromZipFile(File file) throws IOException {
  List<String> hashes = new ArrayList<>();
  ZipFile zipFile = new ZipFile(file);

  byte[] buf = new byte[65536];
  Enumeration<?> entries = zipFile.getEntries();
  while (entries.hasMoreElements()) {
    ZipArchiveEntry zipArchiveEntry = (ZipArchiveEntry) entries.nextElement();
    int n;
    InputStream is = zipFile.getInputStream(zipArchiveEntry);
    ZipArchiveInputStream zis = new ZipArchiveInputStream(is);

    if (zis.canReadEntryData(zipArchiveEntry)) {
      while ((n = is.read(buf)) != -1) {
        if (n > 0) {
          hashes.add(DigestUtils.md5Hex(buf));
        }
      }
    }
    zis.close();
  }

  return hashes;
}
 
开发者ID:sysunite,项目名称:excel-microservice,代码行数:25,代码来源:ExcelWriteControllerTest.java

示例5: returnArchiveInputStream

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
/**
 * return archive input stream
 *
 * @param inputStream - file  input Stream
 * @param archiveSuffix   - archive suffix
 * @return archive input stream
 * @throws IOException
 */
public static ArchiveInputStream returnArchiveInputStream(InputStream inputStream, String archiveSuffix)
        throws IOException {
    if (isZipFamilyArchive(archiveSuffix)) {
        return new ZipArchiveInputStream(inputStream);
    }

    if (isTarArchive(archiveSuffix)) {
        return new TarArchiveInputStream(inputStream);
    }

    if (isTgzFamilyArchive(archiveSuffix) || isGzCompress(archiveSuffix)) {
        return new TarArchiveInputStream(new GzipCompressorInputStream(inputStream));
    }
    return null;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:24,代码来源:ZipUtils.java

示例6: readZipFromResource

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
private Map<String, byte[]> readZipFromResource(String path) throws IOException {
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    URL url = cl.getResource(path);
    Validate.isTrue(url != null);
    
    Map<String, byte[]> ret = new LinkedHashMap<>();
    
    try (InputStream is = url.openStream();
            ZipArchiveInputStream zais = new ZipArchiveInputStream(is)) {
        ZipArchiveEntry entry;
        while ((entry = zais.getNextZipEntry()) != null) {
            ret.put(entry.getName(), IOUtils.toByteArray(zais));
        }
    }
    
    return ret;
}
 
开发者ID:offbynull,项目名称:coroutines,代码行数:18,代码来源:CoroutinesAgentTest.java

示例7: readZipFromResource

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
/**
 * Loads up a ZIP file that's contained in the classpath.
 * @param path path of ZIP resource
 * @return contents of files within the ZIP
 * @throws IOException if any IO error occurs
 * @throws NullPointerException if any argument is {@code null} or contains {@code null} elements
 * @throws IllegalArgumentException if {@code path} cannot be found, or if zipPaths contains duplicates
 */
public static Map<String, byte[]> readZipFromResource(String path) throws IOException {
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    URL url = cl.getResource(path);
    Validate.isTrue(url != null);
    
    Map<String, byte[]> ret = new LinkedHashMap<>();
    
    try (InputStream is = url.openStream();
            ZipArchiveInputStream zais = new ZipArchiveInputStream(is)) {
        ZipArchiveEntry entry;
        while ((entry = zais.getNextZipEntry()) != null) {
            ret.put(entry.getName(), IOUtils.toByteArray(zais));
        }
    }
    
    return ret;
}
 
开发者ID:offbynull,项目名称:coroutines,代码行数:26,代码来源:TestUtils.java

示例8: getMediaType

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
static MediaType getMediaType(ArchiveInputStream stream) {
    if (stream instanceof JarArchiveInputStream) {
        return JAR;
    } else if (stream instanceof ZipArchiveInputStream) {
        return ZIP;
    } else if (stream instanceof ArArchiveInputStream) {
        return AR;
    } else if (stream instanceof CpioArchiveInputStream) {
        return CPIO;
    } else if (stream instanceof DumpArchiveInputStream) {
        return DUMP;
    } else if (stream instanceof TarArchiveInputStream) {
        return TAR;
    } else {
        return MediaType.OCTET_STREAM;
    }
}
 
开发者ID:kolbasa,项目名称:OCRaptor,代码行数:18,代码来源:PackageParser.java

示例9: getConfiguration

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
public Configuration getConfiguration(InputStreamDataSource configStream) throws IOException {
    Configuration configuration = new Configuration(false);
    try (ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(configStream.getInputStream())) {
        ZipArchiveEntry zipEntry = zipInputStream.getNextZipEntry();
        while (zipEntry != null) {
            String name = zipEntry.getName();
            if ( name.endsWith("core-site.xml") || name.endsWith("hdfs-site.xml") ) {
                if ( verbose ) System.err.println("Reading \"" + name + "\" into Configuration.");
                ByteArrayOutputStream boas = new ByteArrayOutputStream();
                IOUtils.copy(zipInputStream, boas);
                configuration.addResource(new ByteArrayInputStream(boas.toByteArray()), name);
            }
            zipEntry = zipInputStream.getNextZipEntry();
        }
    }
    return configuration;
}
 
开发者ID:ezbake,项目名称:ezbakehelpers-cdh-config-exporter,代码行数:18,代码来源:Cdh2EzProperties.java

示例10: unZip

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
/** uncompresses a single file content that had zip applied */
private static byte[] unZip(byte[] content) throws IOException {
    // this code only works if we throw an exception above, meaning we can't uncompress with the generalized approach
    try (
            ByteArrayInputStream compressedIn = new ByteArrayInputStream(content);
            ZipArchiveInputStream zipArcInStream = new ZipArchiveInputStream(compressedIn);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ) {
        ZipArchiveEntry entry = zipArcInStream.getNextZipEntry();
        long entrySize = entry.getSize();
        final byte[] buffer = new byte[8192];
        int n;
        while ((n = zipArcInStream.read(buffer,0, 8192 )) != -1) {
            out.write(buffer, 0, n);
        }

        byte[] uncompressed = out.toByteArray();
        return uncompressed;
    }
}
 
开发者ID:stucco,项目名称:collectors,代码行数:21,代码来源:UnpackUtils.java

示例11: extract

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
/**
 * Extracts a Zip Entry from an archive to a directory
 *
 * @param zis
 *            Archive
 * @param entry
 *            Zip Entry
 * @param targetDir
 *            Directory to extract file to
 * @throws IOException
 *             in case of error
 */
protected static void extract(ZipArchiveInputStream zis, ArchiveEntry entry, File targetDir, boolean mkdirs) throws IOException {
    BufferedOutputStream bos = null;
    FileOutputStream fos = null;
    try {
        File targetFile = new File(targetDir.getAbsolutePath() + File.separator + entry.getName());

        if (mkdirs) {
            targetFile.getParentFile().mkdirs();
        }

        fos = new FileOutputStream(targetFile);
        bos = new BufferedOutputStream(fos, BUFFER);

        int count;
        byte[] data = new byte[BUFFER];

        while ((count = zis.read(data, 0, BUFFER)) != -1) {
            bos.write(data, 0, count);
        }
    } finally {
        IOUtils.closeQuietly(bos);
        IOUtils.closeQuietly(fos);
    }

}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:38,代码来源:ZipFileUtil.java

示例12: getEntries

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
private Set<String> getEntries(final NodeRef downloadNode)
{
    return TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback<Set<String>>()
    {

        @Override
        public Set<String> execute() throws Throwable
        {
            Set<String> entryNames = new TreeSet<String>();
            ContentReader reader = CONTENT_SERVICE.getReader(downloadNode, ContentModel.PROP_CONTENT);
            ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(reader.getContentInputStream());
            try 
            {
                ZipArchiveEntry zipEntry = zipInputStream.getNextZipEntry();
                while (zipEntry != null)
                {
                    String name = zipEntry.getName();
                    entryNames.add(name);
                    zipEntry = zipInputStream.getNextZipEntry();
                }
            }
            finally
            {
                zipInputStream.close();
            }
            return entryNames;
        }
    });
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:30,代码来源:DownloadServiceIntegrationTest.java

示例13: analyseRlc

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
/**
 * This method takes a potential RLC file and unpacks it as a ZIP file. Then
 * filters through the entries in the ZIP file to find the XML file for
 * processing. XML is then parsed through XStream and stored in an engine
 * for data collection.
 *
 * @param file
 *            - file for processing
 * @throws FileNotFoundException
 * @throws IOException
 */
private void analyseRlc(final File file) throws FileNotFoundException, IOException, RuntimeException {
	final InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
	final ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(inputStream);
	ZipArchiveEntry entry;
	try {
		while ((entry = zipInputStream.getNextZipEntry()) != null) {
			// Find the XML configuration file and ignore the rest
			if (!entry.isDirectory()) {
				final String entryName = entry.getName().trim().toLowerCase();
				final int directoryIndex = entryName.indexOf('/');

				if (entryName.length() > 4 && entryName.endsWith(".xml") && directoryIndex <= 0) {
					if (!zipInputStream.canReadEntryData(entry)) {
						throw new RuntimeException("RLC file could not be processed.");
					}
					logger.info("[PROCESSING] : " + entryName);

					final Engine engine = parser.parse(zipInputStream);

					if (engine == null) {
						// Null returned do not add to engine list
						logger.error("[ERROR] : Could not process " + entryName);
					} else {
						this.fileCounter++; // increment file count.
						// file count used as a way to name files and distinguish RLC's with same names.
						// Name of a file: FileCoutner + ":" + <FileName>. n is the file count.
						engine.setFileName(this.fileCounter + ":" + file.getName());
						this.engineList.add(engine);
						this.dataCollector.collectData(engine);
					}
				}
			}
		}
	} finally {
		zipInputStream.close();
	}
}
 
开发者ID:orionhealth,项目名称:rlc-analyser,代码行数:49,代码来源:RlcAnalyser.java

示例14: require_that_valid_zip_application_can_be_unpacked

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
@Test
public void require_that_valid_zip_application_can_be_unpacked() throws IOException {
    File outFile = createZipFile();
    CompressedApplicationInputStream unpacked = CompressedApplicationInputStream.createFromCompressedStream(
            new ZipArchiveInputStream(new FileInputStream(outFile)));
    File outApp = unpacked.decompress();
    assertTestApp(outApp);
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:9,代码来源:CompressedApplicationInputStreamTest.java

示例15: extractToDirectory

import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; //导入依赖的package包/类
private static Manifest extractToDirectory(File directory, ZipArchiveInputStream input) throws IOException
{
  Manifest manifest = null;
  File manifestFile = new File(directory, JarFile.MANIFEST_NAME);
  manifestFile.getParentFile().mkdirs();

  ZipArchiveEntry entry = input.getNextZipEntry();
  while (entry != null) {
    File newFile = new File(directory, entry.getName());
    if (entry.isDirectory()) {
      newFile.mkdirs();
    } else {
      if (JarFile.MANIFEST_NAME.equals(entry.getName())) {
        manifest = new Manifest(input);
        try (FileOutputStream output = new FileOutputStream(newFile)) {
          manifest.write(output);
        }
      } else {
        try (FileOutputStream output = new FileOutputStream(newFile)) {
          IOUtils.copy(input, output);
        }
      }
    }
    entry = input.getNextZipEntry();
  }
  return manifest;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:28,代码来源:AppPackage.java


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