Java GZip gzip(String str)

Here you can find the source of gzip(String str)

Description

gzip

License

Apache License

Declaration

public static String gzip(String str) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import java.util.zip.GZIPOutputStream;

public class Main {
    private static final Charset CHARSET_ZIP = StandardCharsets.ISO_8859_1;

    public static String gzip(String str) throws IOException {
        if (null == str || str.length() < 1) {
            return str;
        }/*from  ww  w .java  2  s  . c o m*/
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (GZIPOutputStream gzip = new GZIPOutputStream(out)) {
            gzip.write(str.getBytes());
        }
        return out.toString(CHARSET_ZIP.name());
    }
}

Related

  1. gzip(final T o)
  2. gzip(String s)
  3. gzipDecompress(byte[] compressed)
  4. gzipFileReader(String file)
  5. gzipReader(final InputStream inputStream)
  6. gzipString(String src, byte default_value[])