Search in sources :

Example 96 with Inflater

use of java.util.zip.Inflater in project geode by apache.

the class CliUtil method uncompressBytes.

public static DeflaterInflaterData uncompressBytes(byte[] output, int compressedDataLength) throws DataFormatException {
    Inflater decompresser = new Inflater();
    decompresser.setInput(output, 0, compressedDataLength);
    byte[] buffer = new byte[512];
    byte[] result = new byte[0];
    int bytesRead;
    while (!decompresser.needsInput()) {
        bytesRead = decompresser.inflate(buffer);
        byte[] newResult = new byte[result.length + bytesRead];
        System.arraycopy(result, 0, newResult, 0, result.length);
        System.arraycopy(buffer, 0, newResult, result.length, bytesRead);
        result = newResult;
    }
    // System.out.println(new String(result));
    decompresser.end();
    return new DeflaterInflaterData(result.length, result);
}
Also used : Inflater(java.util.zip.Inflater)

Example 97 with Inflater

use of java.util.zip.Inflater in project bitsquare by bitsquare.

the class Utils method decompress.

private static byte[] decompress(byte[] compressedData, int length) {
    Inflater inflater = new Inflater();
    inflater.setInput(compressedData, 0, length);
    ByteArrayOutputStream bos = new ByteArrayOutputStream(length);
    byte[] buf = new byte[8192];
    while (!inflater.finished()) {
        try {
            int count = inflater.inflate(buf);
            bos.write(buf, 0, count);
        } catch (DataFormatException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    try {
        bos.close();
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    return bos.toByteArray();
}
Also used : DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 98 with Inflater

use of java.util.zip.Inflater in project gatk by broadinstitute.

the class IntelInflaterDeflaterIntegrationTest method deflateInflateWithIntel.

@Test
public void deflateInflateWithIntel() throws DataFormatException {
    if (!isIntelInflaterDeflaterSupported()) {
        throw new SkipException("IntelInflater/IntelDeflater not available on this platform");
    }
    // create buffers and random input
    final int LEN = 64 * 1024;
    final byte[] input = new RandomDNA().nextBases(LEN);
    final byte[] compressed = new byte[2 * LEN];
    final byte[] result = new byte[LEN];
    final IntelInflaterFactory intelInflaterFactory = new IntelInflaterFactory();
    final IntelDeflaterFactory intelDeflaterFactory = new IntelDeflaterFactory();
    Assert.assertTrue(intelInflaterFactory.usingIntelInflater());
    Assert.assertTrue(intelDeflaterFactory.usingIntelDeflater());
    for (int i = 0; i < 10; i++) {
        // create deflater with compression level i
        final Deflater deflater = intelDeflaterFactory.makeDeflater(i, true);
        // setup deflater
        deflater.setInput(input);
        deflater.finish();
        // compress data
        int compressedBytes = 0;
        // so this loop should always finish in one iteration
        while (!deflater.finished()) {
            compressedBytes = deflater.deflate(compressed, 0, compressed.length);
        }
        deflater.end();
        // decompress and check output == input
        Inflater inflater = intelInflaterFactory.makeInflater(true);
        inflater.setInput(compressed, 0, compressedBytes);
        inflater.inflate(result);
        inflater.end();
        Assert.assertEquals(input, result);
        // clear compressed and result buffers for next iteration
        Arrays.fill(compressed, (byte) 0);
        Arrays.fill(result, (byte) 0);
    }
}
Also used : IntelDeflaterFactory(com.intel.gkl.compression.IntelDeflaterFactory) IntelDeflater(com.intel.gkl.compression.IntelDeflater) Deflater(java.util.zip.Deflater) IntelInflaterFactory(com.intel.gkl.compression.IntelInflaterFactory) RandomDNA(org.broadinstitute.hellbender.utils.RandomDNA) Inflater(java.util.zip.Inflater) IntelInflater(com.intel.gkl.compression.IntelInflater) SkipException(org.testng.SkipException) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 99 with Inflater

use of java.util.zip.Inflater in project android_frameworks_base by crdroidandroid.

the class StrictJarFile method getZipInputStream.

private InputStream getZipInputStream(ZipEntry ze) {
    if (ze.getMethod() == ZipEntry.STORED) {
        return new RAFStream(raf, ze.getDataOffset(), ze.getDataOffset() + ze.getSize());
    } else {
        final RAFStream wrapped = new RAFStream(raf, ze.getDataOffset(), ze.getDataOffset() + ze.getCompressedSize());
        int bufSize = Math.max(1024, (int) Math.min(ze.getSize(), 65535L));
        return new ZipInflaterInputStream(wrapped, new Inflater(true), bufSize, ze);
    }
}
Also used : Inflater(java.util.zip.Inflater)

Aggregations

Inflater (java.util.zip.Inflater)99 InflaterInputStream (java.util.zip.InflaterInputStream)34 IOException (java.io.IOException)28 ByteArrayOutputStream (java.io.ByteArrayOutputStream)26 InputStream (java.io.InputStream)24 DataFormatException (java.util.zip.DataFormatException)24 GZIPInputStream (java.util.zip.GZIPInputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Deflater (java.util.zip.Deflater)9 BufferedInputStream (java.io.BufferedInputStream)6 DataInputStream (java.io.DataInputStream)6 OutputStream (java.io.OutputStream)6 Test (org.junit.Test)6 BufferedReader (java.io.BufferedReader)5 InputStreamReader (java.io.InputStreamReader)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 HttpURLConnection (java.net.HttpURLConnection)5 ByteBuffer (java.nio.ByteBuffer)5 DataOutputStream (java.io.DataOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4