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

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

Introduction

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

Prototype

public int read(byte b[]) throws IOException 

Source Link

Document

Reads some number of bytes from the input stream and stores them into the buffer array b.

Usage

From source file:deodex.tools.ZipTools.java

/**
 * extract an odex file from .xz file//from   w  ww. j  ava2s  .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();
}