Java Utililty Methods Zip Byte Array

List of utility methods to do Zip Byte Array

Description

The list of methods to do Zip Byte Array are organized into topic(s).

Method

byte[]doZip(byte[] data)
do Zip
ByteArrayOutputStream out = new ByteArrayOutputStream();
java.util.zip.GZIPOutputStream gout = new GZIPOutputStream(out);
gout.write(data);
gout.close();
return out.toByteArray();
byte[]zip(byte[] bytes)
Compresses the given byte array using the standard Java deflater (which uses the zlib compression library internally).
if (bytes == null)
    return null;
if (bytes.length == 0)
    return new byte[0];
Deflater deflater = new Deflater();
deflater.setInput(bytes);
ByteArrayOutputStream out = new ByteArrayOutputStream(bytes.length);
deflater.finish();
...
byte[]zip(byte[] data)
zip
byte[] b = null;
try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ZipOutputStream zip = new ZipOutputStream(bos);
    ZipEntry entry = new ZipEntry("zip");
    entry.setSize(data.length);
    zip.putNextEntry(entry);
    zip.write(data);
...
byte[]zip(byte[] datas)
zip
ByteArrayOutputStream out = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(out);
dos.write(datas);
dos.close();
return out.toByteArray();
byte[]zip(byte[] in)
Returns an gzipped copy of the input array.
try {
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream(in.length / EXPECTED_COMPRESSION_RATIO);
    GZIPOutputStream outStream = new GZIPOutputStream(byteOut);
    try {
        outStream.write(in);
    } catch (Exception e) {
        e.printStackTrace();
    try {
        outStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    return byteOut.toByteArray();
} catch (IOException e) {
    e.printStackTrace();
    return null;
byte[]zip(byte[] input)
zip
if (input == null || input.length == 0) {
    return input;
try {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(out);
    gzip.write(input);
    gzip.close();
...
byte[]zip(byte[] input)
zip
final Deflater compressor = new Deflater();
compressor.setLevel(Deflater.BEST_COMPRESSION);
compressor.setInput(input);
compressor.finish();
final ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
byte[] buf = new byte[1024];
while (!compressor.finished()) {
    int count = compressor.deflate(buf);
...
byte[]zip(byte[] source)
zip
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Deflater deflater = new Deflater();
deflater.setInput(source);
deflater.finish();
byte[] buffer = new byte[BUFFER_SIZE_FOR_ZIP];
int writeByte = 0;
while ((writeByte = deflater.deflate(buffer)) != 0) {
    baos.write(buffer, 0, writeByte);
...
byte[]zip(byte[] uncompressedBytes)
Zips bytes to compressed bytes
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream zos = new GZIPOutputStream(baos);
zos.write(uncompressedBytes, 0, uncompressedBytes.length);
zos.close();
return baos.toByteArray();
byte[]zipByte(byte[] data)
zip Byte
Deflater compresser = new Deflater();
compresser.reset();
compresser.setInput(data);
compresser.finish();
byte result[] = new byte[0];
ByteArrayOutputStream o = new ByteArrayOutputStream(1);
try {
    byte[] buf = new byte[CacheSize];
...