當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。