org.apache.commons.compress.archivers.sevenz.SevenZOutputFile Java Examples

The following examples show how to use org.apache.commons.compress.archivers.sevenz.SevenZOutputFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilesArchiveCompressController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@Override
public boolean beforeHandleFiles() {
    try {
        targetFile = makeTargetFile(
                FileTools.getFilePrefix(targetFile.getName()),
                "." + FileTools.getFileSuffix(targetFile.getName()),
                targetFile.getParentFile());
        if (targetFile == null) {
            return false;
        }
        archiveFile = FileTools.getTempFile();
        if (archiver.equalsIgnoreCase(ArchiveStreamFactory.SEVEN_Z)) {
            sevenZOutput = new SevenZOutputFile(archiveFile);
            sevenZOutput.setContentCompression(sevenCompress);
        } else {
            ArchiveStreamFactory f = new ArchiveStreamFactory(
                    encodeBox.getSelectionModel().getSelectedItem());
            archiveOut = f.createArchiveOutputStream(
                    archiver, new FileOutputStream(archiveFile));
        }
        if (resultCheck.isSelected()) {
            archive = new ArrayList();
        } else {
            archive = null;
        }
        totalSize = 0;
        return true;
    } catch (Exception e) {
        logger.debug(e.toString());
        return false;
    }
}
 
Example #2
Source File: PressUtility.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
public static void compress7z(File fromDirectory, File toFile) {
	try (SevenZOutputFile archiveOutputStream = new SevenZOutputFile(toFile)) {
		byte[] buffer = new byte[BUFFER_SIZE];
		for (File file : fromDirectory.listFiles()) {
			try (FileInputStream fileInputStream = new FileInputStream(file)) {
				SevenZArchiveEntry archiveEntry = archiveOutputStream.createArchiveEntry(fromDirectory, file.getName());
				archiveOutputStream.putArchiveEntry(archiveEntry);
				int length = -1;
				while ((length = fileInputStream.read(buffer)) != -1) {
					archiveOutputStream.write(buffer, 0, length);
				}
				archiveOutputStream.closeArchiveEntry();
			}
		}
	} catch (IOException exception) {
		throw new IllegalStateException("压缩7Z异常", exception);
	}
}
 
Example #3
Source File: SevenZip.java    From gradle-plugins with MIT License 4 votes vote down vote up
@SneakyThrows
private WorkResult execute(CopyActionProcessingStream stream) {
    try (SevenZOutputFile outputFile = new SevenZOutputFile(getArchiveFile().get().getAsFile())) {

        if (contentCompression.isPresent()) {
            outputFile.setContentCompression(contentCompression.get());
        }

        stream.process(new StreamAction(outputFile));

        outputFile.finish();

        return WorkResults.didWork(true);
    }
}
 
Example #4
Source File: SevenZip.java    From gradle-plugins with MIT License 4 votes vote down vote up
@SneakyThrows
private WorkResult execute(CopyActionProcessingStream stream) {
    try (SevenZOutputFile outputFile = new SevenZOutputFile(getArchiveFile().get().getAsFile())) {

        if (contentCompression.isPresent()) {
            outputFile.setContentCompression(contentCompression.get());
        }

        stream.process(new StreamAction(outputFile));

        outputFile.finish();

        return WorkResults.didWork(true);
    }
}
 
Example #5
Source File: SevenZArchiver.java    From jarchivelib with Apache License 2.0 3 votes vote down vote up
public SevenZOutputStream(SevenZOutputFile file) {
    this.file = file;
}
 
Example #6
Source File: SevenZArchiver.java    From jarchivelib with Apache License 2.0 3 votes vote down vote up
public SevenZOutputFile getSevenZOutputFile() {
    return file;
}
 
Example #7
Source File: SevenZArchiver.java    From jarchivelib with Apache License 2.0 2 votes vote down vote up
@Override
protected ArchiveOutputStream createArchiveOutputStream(File archive) throws IOException {
    return new SevenZOutputStream(new SevenZOutputFile(archive));
}