Example usage for org.apache.commons.compress.archivers.zip Zip64Mode AsNeeded

List of usage examples for org.apache.commons.compress.archivers.zip Zip64Mode AsNeeded

Introduction

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

Prototype

Zip64Mode AsNeeded

To view the source code for org.apache.commons.compress.archivers.zip Zip64Mode AsNeeded.

Click Source Link

Document

Use Zip64 extensions for all entries where they are required, don't use them for entries that clearly don't require them.

Usage

From source file:com.hw.util.CompressUtils.java

public static final void zip(String compressPath, String[] needCompressPaths) {
    File compressFile = new File(compressPath);

    List<File> files = new ArrayList<File>();
    for (String needCompressPath : needCompressPaths) {
        File needCompressFile = new File(needCompressPath);
        if (!needCompressFile.exists()) {
            continue;
        }/*from  w w w .  j  a  v a2  s .  c o m*/
        files.add(needCompressFile);
    }
    try {
        ZipArchiveOutputStream zaos = null;
        try {
            zaos = new ZipArchiveOutputStream(compressFile);
            zaos.setUseZip64(Zip64Mode.AsNeeded);
            zaos.setEncoding("GBK");

            for (File file : files) {
                addFilesToCompression(zaos, file, "");
            }

        } catch (IOException e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(zaos);
        }
    } catch (Exception e) {
        FileUtils.deleteQuietly(compressFile);
        throw new RuntimeException("", e);
    }
}

From source file:com.daphne.es.maintain.editor.web.controller.utils.CompressUtils.java

public static final void zip(String compressPath, String[] needCompressPaths) {
    File compressFile = new File(compressPath);

    List<File> files = Lists.newArrayList();
    for (String needCompressPath : needCompressPaths) {
        File needCompressFile = new File(needCompressPath);
        if (!needCompressFile.exists()) {
            continue;
        }/*from w ww. j a  v  a2 s.  com*/
        files.add(needCompressFile);
    }
    try {
        ZipArchiveOutputStream zaos = null;
        try {
            zaos = new ZipArchiveOutputStream(compressFile);
            zaos.setUseZip64(Zip64Mode.AsNeeded);
            zaos.setEncoding("GBK");

            for (File file : files) {
                addFilesToCompression(zaos, file, "");
            }

        } catch (IOException e) {
            throw e;
        } finally {
            IOUtils.closeQuietly(zaos);
        }
    } catch (Exception e) {
        FileUtils.deleteQuietly(compressFile);
        throw new RuntimeException("", e);
    }
}

From source file:com.google.jenkins.plugins.persistentmaster.volume.zip.ZipCreator.java

ZipCreator(Path zip) throws IOException {
    zipPath = Preconditions.checkNotNull(zip);
    Preconditions.checkArgument(!Files.exists(zipPath), "zip file exists");
    logger.finer("Creating zip volume for path: " + zipPath);
    zipStream = new ZipArchiveOutputStream(Files.newOutputStream(zipPath, StandardOpenOption.CREATE_NEW));
    // unfortunately there is no typesafe way of doing this
    zipStream.setEncoding(UTF_8);/*from w  w w  .  j a  v  a2  s .c o  m*/
    zipStream.setUseZip64(Zip64Mode.AsNeeded);
}

From source file:com.glaf.core.util.ZipUtils.java

/**
 * //from w  w w .  j a  va  2 s .c  om
 * ?zip?
 * 
 * @param files
 *            ?
 * 
 * @param zipFilePath
 *            ?zip ,"/var/data/aa.zip";
 */
public static void compressFile(File[] files, String zipFilePath) {
    if (files != null && files.length > 0) {
        if (isEndsWithZip(zipFilePath)) {
            ZipArchiveOutputStream zaos = null;
            try {
                File zipFile = new File(zipFilePath);
                zaos = new ZipArchiveOutputStream(zipFile);

                // Use Zip64 extensions for all entries where they are
                // required
                zaos.setUseZip64(Zip64Mode.AsNeeded);

                for (File file : files) {
                    if (file != null) {
                        ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry(file, file.getName());
                        zaos.putArchiveEntry(zipArchiveEntry);
                        InputStream is = null;
                        try {
                            is = new BufferedInputStream(new FileInputStream(file));
                            byte[] buffer = new byte[BUFFER];
                            int len = -1;
                            while ((len = is.read(buffer)) != -1) {
                                zaos.write(buffer, 0, len);
                            }

                            // Writes all necessary data for this entry.
                            zaos.closeArchiveEntry();
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        } finally {
                            IOUtils.closeStream(is);
                        }
                    }
                }
                zaos.finish();
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeStream(zaos);
            }
        }
    }
}

From source file:gzipper.algorithms.Zip.java

@Override
public void run() {
    /*check whether archive with given name already exists; 
    if so, add index to file name an re-check*/
    if (_createArchive) {
        try {/*from w  w  w. jav a  2  s .  co  m*/
            File file = new File(_path + _archiveName + ".zip");
            while (file.exists()) {
                ++_nameIndex;
                _archiveName = _archiveName.substring(0, 7) + _nameIndex;
                file = new File(_path + _archiveName + ".zip");
            }
            _zos = new ZipArchiveOutputStream(
                    new BufferedOutputStream(new FileOutputStream(_path + _archiveName + ".zip")));
            _zos.setUseZip64(Zip64Mode.AsNeeded);
        } catch (IOException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, "Error creating output stream", ex);
            System.exit(1);
        }
    }
    while (_runFlag) {
        try {
            long startTime = System.nanoTime();

            if (_selectedFiles != null) {
                if (_createArchive != false) {
                    compress(_selectedFiles, "");
                } else {
                    extract(_path, _archiveName);
                }
            } else {
                throw new GZipperException("File selection must not be null");
            }
            _elapsedTime = System.nanoTime() - startTime;
            stop(); //stop thread after successful operation

        } catch (IOException | GZipperException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, "Error compressing archive", ex);
        } finally {
            stop(); //stop thread after successful operation
        }
    }
}

From source file:org.fl.modules.excel.poi.exportExcel.multi.SXSSFWorkBookOperation.java

public void compressFiles2Zip() {
    org.apache.commons.io.output.ByteArrayOutputStream byteArrayOutputStream = new org.apache.commons.io.output.ByteArrayOutputStream();
    try {//from  w  ww.j a v  a  2  s.com
        byteArrayOutputStream = write(byteArrayOutputStream);
        ZipArchiveOutputStream zaos = null;
        zaos = new ZipArchiveOutputStream(byteArrayOutputStream);
        // Use Zip64 extensions for all entries where they are required
        zaos.setUseZip64(Zip64Mode.AsNeeded);
        if (byteArrayOutputStream != null) {
            ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry("excel");
            zaos.putArchiveEntry(zipArchiveEntry);
            try {
                byteArrayOutputStream.writeTo(zaos);
                zaos.closeArchiveEntry();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}