当前位置: 首页>>代码示例>>Java>>正文


Java XZCompressorOutputStream类代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:acs6610987,项目名称:secram,代码行数:39,代码来源:ApacheCompressTest.java

示例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();
}
 
开发者ID:espringtran,项目名称:compressor4j,代码行数:35,代码来源:XzProcessor.java

示例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);
}
 
开发者ID:batterseapower,项目名称:timeseries-compression,代码行数:37,代码来源:ConditionerParameterSearchTest.java

示例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();
    }
}
 
开发者ID:PeterLaker,项目名称:archive-fs,代码行数:12,代码来源:TarXzFileSystem.java

示例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();
}
 
开发者ID:debop,项目名称:debop4j,代码行数:12,代码来源:XZCompressor.java

示例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);
}
 
开发者ID:saalfeldlab,项目名称:n5,代码行数:6,代码来源:XzCompression.java

示例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);
}
 
开发者ID:batterseapower,项目名称:timeseries-compression,代码行数:5,代码来源:JMHCompressorTest.java

示例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);
}
 
开发者ID:batterseapower,项目名称:timeseries-compression,代码行数:5,代码来源:JMHCompressorTest.java

示例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);
}
 
开发者ID:batterseapower,项目名称:timeseries-compression,代码行数:5,代码来源:JMHCompressorTest.java

示例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);
}
 
开发者ID:hamishmorgan,项目名称:WAG,代码行数:7,代码来源:CompressorStreamFactory2.java

示例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();
}
 
开发者ID:mizdebsk,项目名称:java-deptools,代码行数:18,代码来源:Database.java


注:本文中的org.apache.commons.compress.compressors.xz.XZCompressorOutputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。