Java Gzip Class-Base64 compression and decompression

Source: Internet
Author: User
Tags base64

Public final class ziputil{public static string CompressToBase64 (String string) {try {BYTEARRAYOUTP            Utstream OS = new Bytearrayoutputstream (String.Length ());            Gzipoutputstream Gos = new Gzipoutputstream (OS);            Gos.write (String.getbytes ());            Gos.close ();            byte[] Compressed = Os.tobytearray ();            Os.close ();            String result = base64.encodetostring (compressed, base64.default);        return result;        } catch (IOException e) {e.printstacktrace ();    } catch (Exception ex) {} return ""; } public static string DecompressToBase64 (String texttodecode) {//string Texttodecode = "H4SIAAAAAAAAAPNIZCNJBWC        Cidh3bqaaaa==\n ";            try {byte[] compressed = Base64.decode (Texttodecode, Base64.default);            Final int buffer_size = 32;            Bytearrayinputstream InputStream = new Bytearrayinputstream (compressed); Gzipinputstream GIS =New Gzipinputstream (InputStream, buffer_size);            Bytearrayoutputstream BAOs = new Bytearrayoutputstream ();            byte[] data = new Byte[buffer_size];            int bytesread;            while ((Bytesread = (data))! =-1) {baos.write (data, 0, bytesread);        } return Baos.tostring ("UTF-8");        } catch (IOException e) {e.printstacktrace ();    } catch (Exception ex) {} return ""; }}

Java Gzip Class-Base64 compression and decompression

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.