Java Code Examples for org.apache.commons.compress.archivers.zip.ZipArchiveEntry#getCompressedSize()

The following examples show how to use org.apache.commons.compress.archivers.zip.ZipArchiveEntry#getCompressedSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScatterZipOutputStream.java    From importer-exporter with Apache License 2.0 6 votes vote down vote up
void writeTo(ZipArchiveOutputStream target) throws IOException {
    entryStore.closeForWriting();
    backingStore.closeForWriting();
    String line;

    try (InputStream stream = backingStore.getInputStream();
         BufferedReader reader = new BufferedReader(new InputStreamReader(entryStore.getInputStream(), StandardCharsets.UTF_8))) {
        while ((line = reader.readLine()) != null) {
            String[] values = line.split(",");
            if (values.length != 5)
                throw new IOException("Failed to read temporary zip entry.");

            ZipArchiveEntry entry = new ZipArchiveEntry(values[0]);
            entry.setMethod(Integer.parseInt(values[1]));
            entry.setCrc(Long.parseLong(values[2]));
            entry.setCompressedSize(Long.parseLong(values[3]));
            entry.setSize(Long.parseLong(values[4]));

            try (BoundedInputStream rawStream = new BoundedInputStream(stream, entry.getCompressedSize())) {
                target.addRawArchiveEntry(entry, rawStream);
            }
        }
    } catch (NumberFormatException e) {
        throw new IOException("Failed to read temporary zip entry.", e);
    }
}
 
Example 2
Source File: Zip.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private File unzipEntry(ZipFile zipFile, ZipArchiveEntry entry, Path targetDirectory,
        Consumer<ZipExtractionResult> unzipCallback) {
    final String fileName = entry.getName();
    final long compressedSize = entry.getCompressedSize();

    final Path targetPath = targetDirectory.resolve(fileName);
    try {
        if (entry.isDirectory()) {
            LOGGER.info(String.format("Attempting to create output directory %s.", targetPath.toString()));

            Files.createDirectories(targetPath);
        } else {
            Files.createDirectories(targetPath.getParent());

            try (InputStream in = zipFile.getInputStream(entry)) {
                LOGGER.info(String.format("Creating output file %s.", targetPath.toString()));

                Files.copy(in, targetPath, StandardCopyOption.REPLACE_EXISTING);

                // update progress bar
                unzipCallback.accept(new ZipExtractionResult(compressedSize, fileName));
            }
        }

        return targetPath.toFile();
    } catch (IOException e) {
        throw new ArchiveException(String.format("Unable to extract file \"%s\"", fileName), e);
    }
}