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