Example usage for org.apache.commons.compress.compressors.lzma LZMACompressorInputStream LZMACompressorInputStream

List of usage examples for org.apache.commons.compress.compressors.lzma LZMACompressorInputStream LZMACompressorInputStream

Introduction

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

Prototype

public LZMACompressorInputStream(final InputStream inputStream) throws IOException 

Source Link

Document

Creates a new input stream that decompresses LZMA-compressed data from the specified input stream.

Usage

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

/**
 * Read from compressed file/*from   w  ww. ja v a2 s .c om*/
 * 
 * @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);
    LZMACompressorInputStream cis = new LZMACompressorInputStream(bais);
    ZipInputStream zis = new ZipInputStream(cis);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        byte[] buffer = new byte[1024];
        int readByte;
        ZipEntry entry = zis.getNextEntry();
        while (entry != null) {
            long t2 = System.currentTimeMillis();
            baos = new ByteArrayOutputStream();
            readByte = zis.read(buffer);
            while (readByte != -1) {
                baos.write(buffer, 0, readByte);
                readByte = zis.read(buffer);
            }
            zis.closeEntry();
            BinaryFile binaryFile = new BinaryFile(entry.getName(), baos.toByteArray());
            fileCompressor.addBinaryFile(binaryFile);
            LogUtil.createAddFileLog(fileCompressor, binaryFile, t2, System.currentTimeMillis());
            entry = zis.getNextEntry();
        }
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on get compressor file", e);
    } finally {
        baos.close();
        zis.close();
        cis.close();
        bais.close();
    }
    LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1, System.currentTimeMillis());
}

From source file:itdelatrisu.opsu.replay.Replay.java

/**
 * Loads the replay data.//from w  w w  . j a v  a 2  s  .  c  o m
 * @param reader the associated reader
 * @throws IOException
 */
private void loadData(OsuReader reader) throws IOException {
    // life data
    String[] lifeData = reader.readString().split(",");
    List<LifeFrame> lifeFrameList = new ArrayList<LifeFrame>(lifeData.length);
    for (String frame : lifeData) {
        String[] tokens = frame.split("\\|");
        if (tokens.length < 2)
            continue;
        try {
            int time = Integer.parseInt(tokens[0]);
            float percentage = Float.parseFloat(tokens[1]);
            lifeFrameList.add(new LifeFrame(time, percentage));
        } catch (NumberFormatException e) {
            Log.warn(String.format("Failed to load life frame: '%s'", frame), e);
        }
    }
    this.lifeFrames = lifeFrameList.toArray(new LifeFrame[lifeFrameList.size()]);

    // timestamp
    this.timestamp = reader.readDate();

    // LZMA-encoded replay data
    this.replayLength = reader.readInt();
    if (replayLength > 0) {
        LZMACompressorInputStream lzma = new LZMACompressorInputStream(reader.getInputStream());
        String[] replayFrames = Utils.convertStreamToString(lzma).split(",");
        lzma.close();
        List<ReplayFrame> replayFrameList = new ArrayList<ReplayFrame>(replayFrames.length);
        int lastTime = 0;
        for (String frame : replayFrames) {
            if (frame.isEmpty())
                continue;
            String[] tokens = frame.split("\\|");
            if (tokens.length < 4)
                continue;
            try {
                if (tokens[0].equals(SEED_STRING)) {
                    seed = Integer.parseInt(tokens[3]);
                    continue;
                }
                int timeDiff = Integer.parseInt(tokens[0]);
                int time = timeDiff + lastTime;
                float x = Float.parseFloat(tokens[1]);
                float y = Float.parseFloat(tokens[2]);
                int keys = Integer.parseInt(tokens[3]);
                replayFrameList.add(new ReplayFrame(timeDiff, time, x, y, keys));
                lastTime = time;
            } catch (NumberFormatException e) {
                Log.warn(String.format("Failed to parse frame: '%s'", frame), e);
            }
        }
        this.frames = replayFrameList.toArray(new ReplayFrame[replayFrameList.size()]);
    }
}

From source file:com.skcraft.launcher.launch.JavaRuntimeFetcher.java

private void decompress(File lzma, File zip) {
    if (!lzma.exists()) {
        throw new UnsupportedOperationException("Attempted to decompress non-existent file: " + lzma);
    }/*from w w w.j av a2  s .  c o m*/

    if (zip.exists() && !zip.delete()) {
        log.log(Level.INFO, "Unable to clean up existing file {0} before unzipping", zip);
        return;
    }

    BufferedInputStream inputStream = null;
    LZMACompressorInputStream lzmaInputStream = null;

    try {
        inputStream = new BufferedInputStream(new FileInputStream(lzma));
        lzmaInputStream = new LZMACompressorInputStream(inputStream);
        copyFile(lzmaInputStream, zip, SharedLocale.tr("runtimeFetcher.decompress"), -1);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        Closer.close(lzmaInputStream);
        Closer.close(inputStream);
    }
}

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

/**
 * @param stream the stream to read from, should be buffered
 */// w  w  w. jav  a  2 s  .  co m
public CompressorInputStream getCompressorStream(InputStream stream) throws IOException {
    return new LZMACompressorInputStream(stream);
}