Example usage for org.apache.commons.compress.archivers.zip ZipArchiveInputStream getNextEntry

List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveInputStream getNextEntry

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.zip ZipArchiveInputStream getNextEntry.

Prototype

public ArchiveEntry getNextEntry() throws IOException 

Source Link

Usage

From source file:org.zuinnote.hadoop.office.format.common.writer.msexcel.internal.EncryptedZipEntrySource.java

public void setInputStream(InputStream is) throws IOException {
    this.tmpFile = TempFile.createTempFile("hadoopoffice-protected", ".zip");

    ZipArchiveInputStream zis = new ZipArchiveInputStream(is);
    FileOutputStream fos = new FileOutputStream(tmpFile);
    ZipArchiveOutputStream zos = new ZipArchiveOutputStream(fos);
    ZipArchiveEntry ze;//from w w  w  . j  a  v a2 s.  co m
    while ((ze = (ZipArchiveEntry) zis.getNextEntry()) != null) {
        // rewrite zip entries to match the size of the encrypted data (with padding)
        ZipArchiveEntry zeNew = new ZipArchiveEntry(ze.getName());
        zeNew.setComment(ze.getComment());
        zeNew.setExtra(ze.getExtra());
        zeNew.setTime(ze.getTime());
        zos.putArchiveEntry(zeNew);
        FilterOutputStream fos2 = new FilterOutputStream(zos) {
            // do not close underlyzing ZipOutputStream
            @Override
            public void close() {
            }
        };
        OutputStream nos;
        if (this.ciEncoder != null) { // encrypt if needed
            nos = new CipherOutputStream(fos2, this.ciEncoder);
        } else { // do not encrypt
            nos = fos2;
        }
        IOUtils.copy(zis, nos);
        nos.close();
        if (fos2 != null) {
            fos2.close();
        }
        zos.closeArchiveEntry();

    }
    zos.close();
    fos.close();
    zis.close();
    IOUtils.closeQuietly(is);
    this.zipFile = new ZipFile(this.tmpFile);

}

From source file:test.camel.support.ZipFileEntryTypeConverter.java

@Converter
public static InputStream toInputStream(ZipFileEntry zipFileEntry, Exchange exchange) throws IOException {
    ZipArchiveInputStream zis = null;
    InputStream fileInputStream = null;

    try {/*from   w  w w. j  a  v  a2s.  c o m*/
        // Create input stream
        zis = new ZipArchiveInputStream(
                new BufferedInputStream(new FileInputStream(zipFileEntry.getZipFilePath())));

        ArchiveEntry entry;

        while ((entry = zis.getNextEntry()) != null) {
            if (!entry.isDirectory() && entry.getName().equals(zipFileEntry.getFileEntry())) {
                fileInputStream = zis;
                break;
            }
        }
    } finally {
        if (fileInputStream == null) {
            IOUtils.closeQuietly(zis);
        }
    }

    if (fileInputStream == null) {
        String msg = MessageFormat.format("No file entry is found for {0} withing the {0} archive",
                zipFileEntry.getFileEntry(), zipFileEntry.getZipFilePath());
        throw new FileNotFoundException(msg);
    }

    return fileInputStream;
}