本文整理汇总了Java中org.apache.commons.compress.archivers.sevenz.SevenZOutputFile类的典型用法代码示例。如果您正苦于以下问题:Java SevenZOutputFile类的具体用法?Java SevenZOutputFile怎么用?Java SevenZOutputFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SevenZOutputFile类属于org.apache.commons.compress.archivers.sevenz包,在下文中一共展示了SevenZOutputFile类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compressData
import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile; //导入依赖的package包/类
/**
* Compress data
*
* @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();
}
示例2: compress
import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile; //导入依赖的package包/类
@Override
public void compress(InputStream source, OutputStream target) {
File sourceFile = null;
File targetFile = null;
try {
targetFile = File.createTempFile("7ztrgt", "tmp");
sourceFile = File.createTempFile("7zsrc", "tmp");
try (FileOutputStream fos = new FileOutputStream(sourceFile);
BufferedOutputStream bos = new BufferedOutputStream(fos)) {
IOUtils.copy(source, bos);
}
try (SevenZOutputFile sevenZOutput = new SevenZOutputFile(targetFile)) {
SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(sourceFile, "entry");
sevenZOutput.putArchiveEntry(entry);
sevenZOutput.write(Files.readAllBytes(sourceFile.toPath()));
sevenZOutput.closeArchiveEntry();
}
try (InputStream is = new BufferedInputStream(new FileInputStream(targetFile))) {
IOUtils.copy(is, target);
}
} catch (IOException e) {
throw new IllegalStateException(e);
} finally {
FileUtils.deleteQuietly(sourceFile);
FileUtils.deleteQuietly(targetFile);
IOUtils.closeQuietly(source);
}
}
示例3: createArchiveOutputStream
import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile; //导入依赖的package包/类
@Override
protected ArchiveOutputStream createArchiveOutputStream(File archive) throws IOException {
return new SevenZOutputStream(new SevenZOutputFile(archive));
}
示例4: SevenZOutputStream
import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile; //导入依赖的package包/类
public SevenZOutputStream(SevenZOutputFile file) {
this.file = file;
}
示例5: getSevenZOutputFile
import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile; //导入依赖的package包/类
public SevenZOutputFile getSevenZOutputFile() {
return file;
}