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

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

Introduction

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

Prototype

@Override
public void close() throws IOException 

Source Link

Usage

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.espringtran.compressor4j.processor.LzmaProcessor.java

/**
 * Read from compressed file/*from  w w  w.j  av a  2  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());
}