Example usage for org.apache.commons.compress.archivers.sevenz SevenZOutputFile write

List of usage examples for org.apache.commons.compress.archivers.sevenz SevenZOutputFile write

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.sevenz SevenZOutputFile write.

Prototype

public void write(final byte[] b, final int off, final int len) throws IOException 

Source Link

Document

Writes part of a byte array to the current archive entry.

Usage

From source file:inventory.pl.services.BackupService.java

private void archive(File outputFile) {
    try {//w w w.  j ava  2  s .co  m
        byte[] buffer = new byte[1024];

        File f;
        SevenZOutputFile sevenZOutput = new SevenZOutputFile(outputFile);

        System.out.println("Output to Zip : " + outputFile);

        long startTime = System.currentTimeMillis();
        for (String file : this.entries) {
            f = new File(SOURCE_FOLDER + File.separator + file);
            System.out.println("File Added : " + f.getAbsolutePath());
            SevenZArchiveEntry ze = sevenZOutput.createArchiveEntry(f, file);

            try {
                FileInputStream in = new FileInputStream(SOURCE_FOLDER + File.separator + file);
                sevenZOutput.putArchiveEntry(ze);
                int len;
                while ((len = in.read(buffer)) > 0) {
                    sevenZOutput.write(buffer, 0, len);
                }
                sevenZOutput.closeArchiveEntry();
                in.close();

            } catch (java.util.zip.ZipException zipException) {
                System.err.println("ex=" + zipException.getMessage());
            }

        }

        long endTime = System.currentTimeMillis();

        sevenZOutput.close();
        System.out.println("Done in " + (endTime - startTime));
    } catch (IOException ex) {
        Logger.getLogger(BackupService.class.getName()).log(Level.SEVERE, null, ex);
    }

}