/** * @param str * @return Base64 encoded byte array. */ public static String compress(final String str) { if (str == null || str.length() == 0) { return str; } final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { final GZIPOutputStream gzip = new GZIPOutputStream(out); gzip.write(str.getBytes()); gzip.close(); return Base64Helper.encodeObject(out.toByteArray()); } catch (final IOException ex) { log.error("Error while compressing string: " + ex.getMessage(), ex); return null; } }