Java XML Data Type Converter compress(String string)

Here you can find the source of compress(String string)

Description

compress

License

Apache License

Declaration

public static byte[] compress(String string) 

Method Source Code

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

import java.io.ByteArrayOutputStream;

import java.util.zip.GZIPOutputStream;
import javax.xml.bind.DatatypeConverter;

public class Main {
    public static byte[] compress(String string) {
        byte[] compressed = null;
        try {/*from   w  w w .j av a2s  .c o m*/
            ByteArrayOutputStream os = new ByteArrayOutputStream(string.length());
            GZIPOutputStream gos = new GZIPOutputStream(os);
            gos.write(string.getBytes());
            gos.close();
            compressed = os.toByteArray();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return compressed;
    }

    public static byte[] toByteArray(String s) {
        return DatatypeConverter.parseHexBinary(s);
    }
}

Related

  1. addBasicAuthorization(String username, String password, HttpURLConnection connection)
  2. appendByteAsJavaByteInitializer(StringBuilder sb, byte b)
  3. byteArrayAsUrlString(byte[] bytes)
  4. calculateCR16(String value)
  5. calculateHMAC(final String secretKey, final String feedId)
  6. compress(String string)
  7. convertBpmnVariableValueToXslParam(final Object bpmnVariableValue)
  8. convertToFourBytes(int numberToConvert)
  9. convertToPEM(PublicKey key)