public static byte[] compress(String str) throws IOException {
  if (str == null || str.length() == 0) {
    return null;
  }
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  GZIPOutputStream gzip=new GZIPOutputStream(out);
  gzip.write(str.getBytes("UTF-8"));
  gzip.close();
  byte[] outBytes=out.toByteArray();
  return outBytes;
}

public static byte [ ] compress ( String str ) throws IOException { if ( str == null || str . length ( ) == 0 ) { return null ; } ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; GZIPOutputStream gzip = new GZIPOutputStream ( out ) ; gzip . write ( str . getBytes ( "UTF-8" ) ) ; gzip . close ( ) ; byte [ ] outBytes = out . toByteArray ( ) ; return outBytes ; }
compresses a given string . it is encoded using iso - 8859 - 1 , so any decompression of the compressed string should also use iso - 8859 - 1
