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);
}
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();
}
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);
}
}
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);
}
}
Aggregations