use of java.util.zip.Inflater in project hazelcast by hazelcast.
the class IOUtil method decompress.
public static byte[] decompress(byte[] compressedData) throws IOException {
if (compressedData.length == 0) {
return compressedData;
}
Inflater inflater = new Inflater();
inflater.setInput(compressedData);
ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);
byte[] buf = new byte[1024];
while (!inflater.finished()) {
try {
int count = inflater.inflate(buf);
bos.write(buf, 0, count);
} catch (DataFormatException e) {
Logger.getLogger(IOUtil.class).finest("Decompression failed", e);
}
}
bos.close();
inflater.end();
return bos.toByteArray();
}
use of java.util.zip.Inflater in project j2objc by google.
the class DeflaterTest method testDeflate.
public void testDeflate() throws DataFormatException {
deflater.setInput(new byte[] { 1, 2, 3 });
deflateInflate(Deflater.NO_FLUSH);
assertTrue(totalInflated < 3);
// the 3rd byte shouldn't have been flushed yet
assertEquals(0, decompressed[2]);
deflater.setInput(new byte[] { 4, 5, 6 });
deflateInflate(Deflater.SYNC_FLUSH);
assertEquals(6, totalInflated);
assertDecompressed(1, 2, 3, 4, 5, 6);
assertEquals(0, inflater.inflate(decompressed));
deflater.setInput(new byte[] { 7, 8, 9 });
deflateInflate(Deflater.FULL_FLUSH);
assertEquals(9, totalInflated);
assertDecompressed(1, 2, 3, 4, 5, 6, 7, 8, 9);
assertEquals(0, inflater.inflate(decompressed));
// safe because we did a FULL_FLUSH
inflater = new Inflater(true);
deflater.setInput(new byte[] { 10, 11, 12 });
deflateInflate(Deflater.SYNC_FLUSH);
assertEquals(12, totalInflated);
assertDecompressed(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
assertEquals(0, inflater.inflate(decompressed));
}
use of java.util.zip.Inflater in project android_frameworks_base by DirtyUnicorns.
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);
}
}
use of java.util.zip.Inflater in project android_frameworks_base by ResurrectionRemix.
the class StrictJarFile method getZipInputStream.
private InputStream getZipInputStream(ZipEntry ze) {
if (ze.getMethod() == ZipEntry.STORED) {
return new FDStream(fd, ze.getDataOffset(), ze.getDataOffset() + ze.getSize());
} else {
final FDStream wrapped = new FDStream(fd, 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);
}
}
use of java.util.zip.Inflater in project voltdb by VoltDB.
the class FileArchiver method unarchive.
public static void unarchive(String infilename, String outfilename, FileAccess storage, int compressionType) throws IOException {
InputStream f = null;
OutputStream outstream = null;
boolean completed = false;
try {
if (!storage.isStreamElement(infilename)) {
return;
}
storage.removeElement(outfilename);
byte[] b = new byte[COPY_BLOCK_SIZE];
f = storage.openInputStreamElement(infilename);
switch(compressionType) {
case COMPRESSION_ZIP:
f = new InflaterInputStream(f, new Inflater());
break;
case COMPRESSION_GZIP:
f = new GZIPInputStream(f, b.length);
break;
case COMPRESSION_NONE:
break;
default:
throw new RuntimeException("FileArchiver: " + compressionType);
}
outstream = storage.openOutputStreamElement(outfilename);
while (true) {
int l = f.read(b, 0, b.length);
if (l == -1) {
break;
}
outstream.write(b, 0, l);
}
completed = true;
} catch (Throwable e) {
throw FileUtil.toIOException(e);
} finally {
try {
if (f != null) {
f.close();
}
if (outstream != null) {
outstream.flush();
outstream.close();
}
if (!completed && storage.isStreamElement(outfilename)) {
storage.removeElement(outfilename);
}
} catch (Throwable e) {
throw FileUtil.toIOException(e);
}
}
}
Aggregations