List of usage examples for org.apache.commons.compress.archivers.sevenz SevenZArchiveEntry setContentMethods
public void setContentMethods(final Iterable<? extends SevenZMethodConfiguration> methods)
From source file:at.treedb.backup.Export.java
/** * Writes an uncompressed binary archive data file. * //w ww . ja va 2 s . c om * @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.util.Compress.java
/** * Adds a file to the archive// w w 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 the {@code DBFSblock} objects of a {@code DBfile} to an archive * file.//from w w 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(); }
From source file:org.apache.ant.compress.taskdefs.SevenZ.java
public SevenZ() { setFactory(new SevenZStreamFactory() { public ArchiveOutputStream getArchiveOutputStream(File f, String encoding) throws IOException { SevenZArchiveOutputStream o = (SevenZArchiveOutputStream) super.getArchiveOutputStream(f, encoding); if (contentCompression != null) { o.setContentCompression(asMethod(contentCompression)); }// w w w . ja v a 2s. c o m if (contentMethods != null) { o.setContentMethods(contentMethods); } return o; } }); setEntryBuilder(new ArchiveBase.EntryBuilder() { public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) { SevenZArchiveEntry entry = new SevenZArchiveEntry(); entry.setName(r.getName()); entry.setDirectory(r.getResource().isDirectory()); entry.setLastModifiedDate(new Date(r.getResource().getLastModified())); entry.setSize(r.getResource().getSize()); if (keepCompression && r.getResourceFlags().hasContentMethods()) { entry.setContentMethods(r.getResourceFlags().getContentMethods()); } return entry; } }); setFileSetBuilder(new ArchiveBase.FileSetBuilder() { public ArchiveFileSet buildFileSet(Resource dest) { ArchiveFileSet afs = new SevenZFileSet(); afs.setSrcResource(dest); return afs; } }); }