Example usage for org.apache.commons.compress.compressors.xz XZCompressorInputStream close

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

Introduction

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

Prototype

@Override
    public void close() throws IOException 

Source Link

Usage

From source file:deodex.tools.ZipTools.java

/**
 * extract an odex file from .xz file//  w  w w.j  av  a 2 s  . c o  m
 * 
 * @returns success only if an odex file was extracted
 * @param odex
 *            the odex file to decompress
 * @throws IOException
 *             well we are using IOs Exception might be thrown
 */
public static boolean extractOdex(File odex) throws IOException {
    File Decomdex;
    if (odex.getName().endsWith(S.ODEX_EXT)) {
        Logger.appendLog("[ZipTools][I]Decompressing  " + odex.getName() + " not needed");
        return true;
    } else if (odex.getName().endsWith(S.COMP_GZ_ODEX_EXT)) {
        Logger.appendLog("[ZipTools][I]Decompressing  " + odex.getName() + " gzip detected ...");
        return TarGzUtils.unGzipOdex(odex, odex.getParentFile());
    } else {
        Logger.appendLog("[ZipTools][I]Decompressing  " + odex.getName() + " xz compression detected ...");
        Decomdex = new File(odex.getParentFile().getAbsolutePath() + "/"
                + StringUtils.getCropString(odex.getName(), odex.getName().length() - 3));
        Logger.appendLog("[ZipTools][I]Decompressing  " + odex.getAbsolutePath() + "  to  "
                + Decomdex.getAbsolutePath());
        FileInputStream fin = new FileInputStream(odex);
        BufferedInputStream in = new BufferedInputStream(fin);
        FileOutputStream out = new FileOutputStream(Decomdex);
        XZCompressorInputStream xzIn = new XZCompressorInputStream(in);
        final byte[] buffer = new byte[32768];
        int n = 0;
        while (-1 != (n = xzIn.read(buffer))) {
            out.write(buffer, 0, n);
        }
        out.close();
        xzIn.close();

    }
    Logger.appendLog("[ZipTools][I]Decompressing  " + odex.getAbsolutePath() + "  to  "
            + Decomdex.getAbsolutePath() + " success ? " + Decomdex.exists());
    return Decomdex.exists();
}

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

/**
 * Read from compressed file//  w  ww . j  ava2 s.  co m
 * 
 * @param srcPath
 *            path of compressed file
 * @param fileCompressor
 *            FileCompressor object
 * @throws Exception
 */
@Override
public void read(String srcPath, FileCompressor fileCompressor) throws Exception {
    long t1 = System.currentTimeMillis();
    byte[] data = FileUtil.convertFileToByte(srcPath);
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    XZCompressorInputStream cis = new XZCompressorInputStream(bais);
    TarArchiveInputStream ais = new TarArchiveInputStream(cis);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        byte[] buffer = new byte[1024];
        int readByte;
        TarArchiveEntry entry = ais.getNextTarEntry();
        while (entry != null && entry.getSize() > 0) {
            long t2 = System.currentTimeMillis();
            baos = new ByteArrayOutputStream();
            readByte = ais.read(buffer);
            while (readByte != -1) {
                baos.write(buffer, 0, readByte);
                readByte = ais.read(buffer);
            }
            BinaryFile binaryFile = new BinaryFile(entry.getName(), baos.toByteArray());
            fileCompressor.addBinaryFile(binaryFile);
            LogUtil.createAddFileLog(fileCompressor, binaryFile, t2, System.currentTimeMillis());
            entry = ais.getNextTarEntry();
        }
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on get compressor file", e);
    } finally {
        baos.close();
        ais.close();
        cis.close();
        bais.close();
    }
    LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1, System.currentTimeMillis());
}