Example usage for org.apache.commons.compress.compressors.xz XZCompressorOutputStream XZCompressorOutputStream

List of usage examples for org.apache.commons.compress.compressors.xz XZCompressorOutputStream XZCompressorOutputStream

Introduction

In this page you can find the example usage for org.apache.commons.compress.compressors.xz XZCompressorOutputStream XZCompressorOutputStream.

Prototype

public XZCompressorOutputStream(final OutputStream outputStream) throws IOException 

Source Link

Document

Creates a new XZ compressor using the default LZMA2 options.

Usage

From source file:kr.debop4j.core.compress.XZCompressor.java

@Override
protected byte[] doCompress(byte[] plain) throws IOException {

    @Cleanup/*from   www  .j  a va  2s  . c o  m*/
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    @Cleanup
    XZCompressorOutputStream xz = new XZCompressorOutputStream(bos);

    xz.write(plain);
    xz.close();

    return bos.toByteArray();
}

From source file:com.espringtran.compressor4j.processor.XzProcessor.java

/**
 * Compress data/* www.j a  v  a  2 s. c om*/
 * 
 * @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();
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.CompressionUtils.java

/**
 * Make sure the target directory exists and get a stream writing to the specified file within.
 * If the file name ends with a typical extension for compressed files, the stream will be
 * compressed.//from   w w w. ja v a 2s . com
 * 
 * @param aFile
 *            the target file.
 * @return a stream to write to.
 * 
 * @see CompressionMethod
 */
public static OutputStream getOutputStream(File aFile) throws IOException {
    // Create parent folders for output file and set up stream
    if (aFile.getParentFile() != null) {
        forceMkdir(aFile.getParentFile());
    }

    String lcFilename = aFile.getName().toLowerCase();

    OutputStream os = new FileOutputStream(aFile);
    if (lcFilename.endsWith(GZIP.getExtension())) {
        os = new GZIPOutputStream(os);
    } else if (lcFilename.endsWith(BZIP2.getExtension()) || lcFilename.endsWith(".bzip2")) {
        os = new BZip2CompressorOutputStream(os);
    } else if (lcFilename.endsWith(XZ.getExtension())) {
        os = new XZCompressorOutputStream(os);
    }
    return os;
}

From source file:io.druid.java.util.common.CompressionUtilsTest.java

@Test
public void testDecompressXz() throws IOException {
    final File tmpDir = temporaryFolder.newFolder("testDecompressXz");
    final File xzFile = new File(tmpDir, testFile.getName() + ".xz");
    Assert.assertFalse(xzFile.exists());
    try (final OutputStream out = new XZCompressorOutputStream(new FileOutputStream(xzFile))) {
        ByteStreams.copy(new FileInputStream(testFile), out);
    }//from  ww w .j  a va2  s  . c  o m
    try (final InputStream inputStream = CompressionUtils.decompress(new FileInputStream(xzFile),
            xzFile.getName())) {
        assertGoodDataStream(inputStream);
    }
}

From source file:org.apache.ant.compress.util.XZStreamFactory.java

/**
 * @param stream the stream to write to, should be buffered
 *//* www .  ja  v a 2 s  . c o  m*/
public CompressorOutputStream getCompressorStream(OutputStream stream) throws IOException {
    return new XZCompressorOutputStream(stream);
}

From source file:org.apache.camel.impl.XZDataFormat.java

@Override
public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
    InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, exchange,
            graph);//from  ww w. ja v a2 s  . c  om

    XZCompressorOutputStream zipOutput = new XZCompressorOutputStream(stream);
    try {
        IOHelper.copy(is, zipOutput);
    } finally {
        IOHelper.close(is, zipOutput);
    }
}

From source file:org.apache.camel.processor.aggregate.XZDataFormatTest.java

protected byte[] getCompressedBody() throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    XZCompressorOutputStream zout = new XZCompressorOutputStream(bout);
    try {//from www.  j a  va  2s .  com
        zout.write(getPlainTextBody().getBytes("UTF-8"));
    } finally {
        IOHelper.close(zout);
    }
    return bout.toByteArray();
}

From source file:org.codehaus.plexus.archiver.xz.XZCompressor.java

@Override
public void compress() throws ArchiverException {
    try {//ww  w .j  av  a2  s. co m
        xzOut = new XZCompressorOutputStream(bufferedOutputStream(fileOutputStream(getDestFile())));
        compress(getSource(), xzOut);
    } catch (IOException ioe) {
        throw new ArchiverException("Problem creating xz " + ioe.getMessage(), ioe);
    }
}

From source file:org.crosswire.common.compress.XZ.java

public ByteArrayOutputStream compress() throws IOException {
    BufferedInputStream in = new BufferedInputStream(input);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    CompressorOutputStream out = new XZCompressorOutputStream(bos);
    IOUtils.copy(in, out);//from ww w.j  ava 2  s.  c o  m
    in.close();
    out.flush();
    out.close();
    return bos;
}

From source file:org.eclipse.jgit.archive.TxzFormat.java

/**
 * @since 4.0//from w ww . j  a  v a2s . co m
 */
public ArchiveOutputStream createArchiveOutputStream(OutputStream s, Map<String, Object> o) throws IOException {
    XZCompressorOutputStream out = new XZCompressorOutputStream(s);
    return tarFormat.createArchiveOutputStream(out, o);
}