Example usage for org.apache.commons.compress.archivers.sevenz SevenZMethodConfiguration SevenZMethodConfiguration

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

Introduction

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

Prototype

public SevenZMethodConfiguration(final SevenZMethod method) 

Source Link

Document

Doesn't configure any additional options.

Usage

From source file:at.treedb.util.Compress.java

/**
 * Adds a file to the archive/*ww  w .j a  v a  2s. c  o m*/
 * 
 * @param file
 *            file to be compressed
 * @throws IOException
 */
private void addFile(File file) throws IOException {
    if (!exclude.isEmpty()) {
        String extension = getFileExtension(file);
        if (!extension.isEmpty() && exclude.contains(extension.toLowerCase())) {
            return;
        }
    }

    SevenZArchiveEntry entry = new SevenZArchiveEntry();
    entry.setName(file.getAbsolutePath().substring(baseDir.length()).replace('\\', '/'));
    entry.setAccessDate(file.lastModified());
    entry.setCreationDate(file.lastModified());
    entry.setLastModifiedDate(file.lastModified());
    entry.setDirectory(false);

    sevenZOutput.putArchiveEntry(entry);

    FileInputStream is = new FileInputStream(file);
    long size = file.length();
    byte[] buffer = new byte[BUFFER_SIZE];
    boolean setCompressMethod = false;
    while (size > 0) {
        long read = Math.min(buffer.length, size);
        is.read(buffer, 0, (int) read);
        if (!setCompressMethod) {
            setCompressMethod = true;
            entry.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(
                    Export.findBestCompressionMethod(buffer, compressionMehtod))));
        }
        sevenZOutput.write(buffer, 0, (int) read);
        size -= read;
    }
    is.close();
    sevenZOutput.closeArchiveEntry();
}

From source file:at.treedb.backup.Export.java

/**
 * Writes an uncompressed binary archive data file.
 * //  w w  w  . j  ava  2s  .c o m
 * @param path
 *            archive path
 * @param data
 *            binary data
 * @param date
 *            file creation date
 * @throws IOException
 */
private void write(String path, byte data[], Date date) throws IOException {
    SevenZArchiveEntry entry = createFileEntry(path, date);
    entry.setContentMethods(Arrays.asList(new SevenZMethodConfiguration(SevenZMethod.COPY)));
    sevenZOutput.putArchiveEntry(entry);
    System.out.println(path);
    sevenZOutput.write(data);
    sevenZOutput.closeArchiveEntry();
}

From source file:at.treedb.backup.Export.java

/**
 * Writes the {@code DBFSblock} objects of a {@code DBfile} to an archive
 * file.//ww  w . j  a  v a  2  s.c o  m
 * 
 * @param directory
 *            archive directory
 * @param file
 *            {@code DBfile}
 * @param date
 *            file creation date
 * @throws IOException
 */
private void write(String directory, DBfile file, Date date) throws IOException {
    SevenZArchiveEntry entry = createFileEntry(directory + file.getHistId(), date);
    sevenZOutput.putArchiveEntry(entry);
    DBinputStream is = new DBinputStream(file, dao);
    long size = file.getSize();
    byte[] buffer = new byte[BUFFER_SIZE];
    boolean setCompressMethod = false;
    while (size > 0) {
        long read = Math.min(buffer.length, size);
        is.read(buffer, 0, (int) read);
        if (!setCompressMethod) {
            setCompressMethod = true;
            entry.setContentMethods(Arrays.asList(
                    new SevenZMethodConfiguration(findBestCompressionMethod(buffer, compressionMethod))));
        }
        sevenZOutput.write(buffer, 0, (int) read);
        size -= read;
    }
    is.close();
    sevenZOutput.closeArchiveEntry();

}