本文整理汇总了Java中org.apache.commons.compress.compressors.xz.XZCompressorOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java XZCompressorOutputStream类的具体用法?Java XZCompressorOutputStream怎么用?Java XZCompressorOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XZCompressorOutputStream类属于org.apache.commons.compress.compressors.xz包,在下文中一共展示了XZCompressorOutputStream类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
int[] intArray = new int[1000];
for (int i = 0; i < 1000; i++) {
intArray[i] = -300 + i;
}
ByteBuffer buf = ByteBuffer.allocate(50000000);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XZCompressorOutputStream dcos = new XZCompressorOutputStream(baos, 1);
for (int i = 0; i < 1000; i++) {
buf.putInt(intArray[i]);
}
buf.flip();
byte[] bufBytes = new byte[buf.limit()];
buf.get(bufBytes);
dcos.write(bufBytes, 0, bufBytes.length);
dcos.close();
byte[] newBytes = baos.toByteArray();
System.out
.println("Deflate coverage size: " + newBytes.length / 1000.0);
ByteArrayInputStream bais = new ByteArrayInputStream(newBytes);
XZCompressorInputStream dcis = new XZCompressorInputStream(bais);
byte[] newBufBytes = new byte[bufBytes.length];
buf.clear();
int n = -1;
while (-1 != (n = dcis.read(newBufBytes)))
buf.put(newBufBytes, 0, n);
buf.flip();
for (int i = 0; i < 1000; i++) {
int tmp = buf.getInt();
if (tmp != intArray[i]) {
System.out.println("Wrong compression at " + i + ": " + tmp
+ " " + intArray[i]);
System.exit(1);
}
}
}
示例2: compressData
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
/**
* Compress data
*
* @param fileCompressor
* FileCompressor object
* @return
* @throws Exception
*/
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XZCompressorOutputStream cos = new XZCompressorOutputStream(baos);
TarArchiveOutputStream aos = new TarArchiveOutputStream(cos);
try {
for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
.values()) {
TarArchiveEntry entry = new TarArchiveEntry(
binaryFile.getDesPath());
entry.setSize(binaryFile.getActualSize());
aos.putArchiveEntry(entry);
aos.write(binaryFile.getData());
aos.closeArchiveEntry();
}
aos.flush();
aos.finish();
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on compress data", e);
} finally {
aos.close();
cos.close();
baos.close();
}
return baos.toByteArray();
}
示例3: benchmark
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
@Test
public void benchmark() throws IOException {
/*
Snappy compress: 0.156672s
Compressed to 10876881 bytes
Uncompresses to 12908620 bytes
Snappy decompress: 0.162463s
Deflate Fastest compress: 6.017877s
Compressed to 7770401 bytes
Uncompresses to 12908620 bytes
Deflate Fastest decompress: 4.260146s
Deflate Slowest compress: 7.06043s
Compressed to 7492001 bytes
Uncompresses to 12908620 bytes
Deflate Slowest decompress: 3.968221s
Deflate Normal compress: 5.201332s
Compressed to 7515522 bytes
Uncompresses to 12908620 bytes
Deflate Normal decompress: 4.056792s
*/
benchmark("None", x -> x, x -> x);
benchmark("None", x -> x, x -> x);
benchmark("Snappy", SnappyOutputStream::new, SnappyInputStream::new);
benchmark("GZip", GZIPOutputStream::new, GZIPInputStream::new);
benchmark("Deflate Fastest", os -> new DeflaterOutputStream(os, new Deflater(Deflater.BEST_SPEED)), InflaterInputStream::new);
benchmark("Deflate Normal", os -> new DeflaterOutputStream(os, new Deflater(Deflater.DEFAULT_COMPRESSION)), InflaterInputStream::new);
benchmark("Deflate Slowest", os -> new DeflaterOutputStream(os, new Deflater(Deflater.BEST_COMPRESSION)), InflaterInputStream::new);
benchmark("BZip2 Fastest", os -> new BZip2CompressorOutputStream(os, BZip2CompressorOutputStream.MIN_BLOCKSIZE), BZip2CompressorInputStream::new);
benchmark("BZip2 Slowest", os -> new BZip2CompressorOutputStream(os, BZip2CompressorOutputStream.MAX_BLOCKSIZE), BZip2CompressorInputStream::new);
benchmark("XZ Fastest", os -> new XZCompressorOutputStream(os, LZMA2Options.PRESET_MIN), XZCompressorInputStream::new);
benchmark("XZ Normal", os -> new XZCompressorOutputStream(os, LZMA2Options.PRESET_DEFAULT), XZCompressorInputStream::new);
benchmark("XZ Slowest", os -> new XZCompressorOutputStream(os, LZMA2Options.PRESET_MAX), XZCompressorInputStream::new);
}
示例4: writeFile
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
@Override
protected void writeFile(byte[] tarBytes, Path path) throws IOException {
try (XZCompressorOutputStream outputStream = new XZCompressorOutputStream(
Files.newOutputStream(path,
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.WRITE))) {
outputStream.write(tarBytes, 0, tarBytes.length);
outputStream.finish();
outputStream.flush();
}
}
示例5: doCompress
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
@Override
protected byte[] doCompress(byte[] plain) throws IOException {
@Cleanup ByteArrayOutputStream bos = new ByteArrayOutputStream();
@Cleanup XZCompressorOutputStream xz = new XZCompressorOutputStream(bos);
xz.write(plain);
xz.close();
return bos.toByteArray();
}
示例6: getOutputStream
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
@Override
public OutputStream getOutputStream(final OutputStream out) throws IOException {
return new XZCompressorOutputStream(out, preset);
}
示例7: xzFastest
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
@Benchmark
public int xzFastest() throws IOException {
return benchmark(os -> new XZCompressorOutputStream(os, LZMA2Options.PRESET_MIN), XZCompressorInputStream::new);
}
示例8: xzNormal
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
@Benchmark
public int xzNormal() throws IOException {
return benchmark(os -> new XZCompressorOutputStream(os, LZMA2Options.PRESET_DEFAULT), XZCompressorInputStream::new);
}
示例9: xzSlowest
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
@Benchmark
public int xzSlowest() throws IOException {
return benchmark(os -> new XZCompressorOutputStream(os, LZMA2Options.PRESET_MAX), XZCompressorInputStream::new);
}
示例10: createXZCompressorOutputStream
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
public XZCompressorOutputStream createXZCompressorOutputStream(
OutputStream outputStream)
throws IOException {
return new XZCompressorOutputStream(checkNotNull(outputStream, "outputStream"),
xzPreset);
}
示例11: write
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream; //导入依赖的package包/类
/**
* Write database to given output stream
*
* @param os
* the output stream to write database to
* @throws IOException
* @throws FileNotFoundException
* @throws UnsupportedOptionsException
*/
public void write(OutputStream os) throws IOException {
System.err.println("Writing database...");
OutputStream zos = new XZCompressorOutputStream(os);
ObjectOutputStream oos = new ObjectOutputStream(zos);
oos.writeObject(cntmap);
oos.writeObject(refmap);
oos.close();
}