Java Utililty Methods GZip

List of utility methods to do GZip

Description

The list of methods to do GZip are organized into topic(s).

Method

byte[]gzip(final T o)
passed object convert to gziped byte array.
if (o == null) {
    return null;
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final GZIPOutputStream gzip = new GZIPOutputStream(baos);) {
    gzip.write(MAPPER.writeValueAsBytes(o));
    ;
    gzip.close();
...
byte[]gzip(String s)
gzip
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(bos);
OutputStreamWriter osw = new OutputStreamWriter(gzip, StandardCharsets.UTF_8);
osw.write(s);
osw.close();
return bos.toByteArray();
Stringgzip(String str)
gzip
if (null == str || str.length() < 1) {
    return str;
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (GZIPOutputStream gzip = new GZIPOutputStream(out)) {
    gzip.write(str.getBytes());
return out.toString(CHARSET_ZIP.name());
...
StringgzipDecompress(byte[] compressed)
gzip Decompress
byte[] bytes = gzipDecompressBytes(compressed);
return new String(bytes, StandardCharsets.UTF_8);
BufferedReadergzipFileReader(String file)
gzip File Reader
return new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)), UTF8));
BufferedReadergzipReader(final InputStream inputStream)
gzip Reader
return reader(new GZIPInputStream(inputStream));
byte[]gzipString(String src, byte default_value[])
gzip String
if (src == null)
    return default_value;
return gzip(src.getBytes(utf8), default_value);