Java XML Base64 Encode Decode compressToBase64(byte[] message)

Here you can find the source of compressToBase64(byte[] message)

Description

compress To Base

License

Open Source License

Declaration

public static String compressToBase64(byte[] message) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.DatatypeConverter;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.zip.GZIPOutputStream;

public class Main {
    public static String compressToBase64(byte[] message) throws IOException {
        return DatatypeConverter.printBase64Binary(compress(message));
    }/* w w  w  .j a va 2 s.  com*/

    public static byte[] compress(byte[] message) throws IOException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        GZIPOutputStream gzipOut = new GZIPOutputStream(outputStream);

        gzipOut.write(message);
        gzipOut.finish();

        byte[] result = outputStream.toByteArray();

        gzipOut.close();

        return result;
    }
}

Related

  1. base64FromString(String value)
  2. base64ToByte(String data)
  3. byteArrayToBase64String(byte[] data)
  4. BytesToBase64String(final byte[] value)
  5. byteToBase64(byte[] data)
  6. createBase64EncodedStringFromURL(URL url)
  7. decode(String base64)
  8. decodeBase64(File file)
  9. decodeBase64(String b64data)