List of usage examples for org.apache.commons.compress.archivers.sevenz SevenZOutputFile SevenZOutputFile
public SevenZOutputFile(final SeekableByteChannel channel) throws IOException
From source file:com.espringtran.compressor4j.processor.SevenZipProcessor.java
/** * Compress data/*w w w . j ava 2 s .c o m*/ * * @param fileCompressor * FileCompressor object * @return * @throws Exception */ @Override public byte[] compressData(FileCompressor fileCompressor) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); SevenZOutputFile sevenZOutput = new SevenZOutputFile(new File(fileCompressor.getCompressedPath())); try { for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) { SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(new File(binaryFile.getSrcPath()), binaryFile.getDesPath()); entry.setSize(binaryFile.getActualSize()); sevenZOutput.putArchiveEntry(entry); sevenZOutput.write(binaryFile.getData()); sevenZOutput.closeArchiveEntry(); } sevenZOutput.finish(); } catch (Exception e) { FileCompressor.LOGGER.error("Error on compress data", e); } finally { sevenZOutput.close(); baos.close(); } return baos.toByteArray(); }
From source file:at.treedb.util.Compress.java
/** * Creates the archive./*from w ww .j a va2s. com*/ * * @throws IOException */ public void compress() throws IOException { sevenZOutput = new SevenZOutputFile(new File(archive)); sevenZOutput.setContentCompression(compressionMehtod); for (String f : fileList) { compressFile(new File(baseDir + f)); } sevenZOutput.close(); }
From source file:inventory.pl.services.BackupService.java
private void archive(File outputFile) { try {/* w w w . j a va2 s. c om*/ 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); } }
From source file:at.treedb.backup.Export.java
private void initBackup(BACKUP_TYPE type, Domain d) throws Exception { dao = DAO.getDAO();/*w ww . j a v a2 s .com*/ archive = new File(path); sevenZOutput = new SevenZOutputFile(archive); sevenZOutput.setContentCompression(compressionMethod); dbInfo = new DBexportInfo(type, d, serialization, compressionMethod); date = new Date(System.currentTimeMillis()); createDirEntry(ROOT_DIR, date); createDirEntry(FILES_DIR, date); }
From source file:org.codehaus.plexus.archiver.sevenz.SevenZCompressor.java
/** * perform the BZip2 compression operation. *///from w ww .j a v a 2 s. c om public void compress() throws ArchiverException { try { zOut = new SevenZOutputFile(getDestFile()); PlexusIoResource source = getSource(); SevenZArchiveEntry entry = new SevenZArchiveEntry(); entry.setName(source.getName()); entry.setDirectory(source.isDirectory()); zOut.putArchiveEntry(entry); InputStream inputStream = source.getContents(); int read = 0; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { zOut.write(bytes, 0, read); } zOut.closeArchiveEntry(); } catch (IOException ioe) { String msg = "Problem creating 7z " + ioe.getMessage(); throw new ArchiverException(msg, ioe); } }
From source file:org.rauschig.jarchivelib.SevenZArchiver.java
@Override protected ArchiveOutputStream createArchiveOutputStream(File archive) throws IOException { return new SevenZOutputStream(new SevenZOutputFile(archive)); }