*
* @param str The string to zip
* @return The zipped string
*/
public byte[] zip(String str) {
GZIPOutputStream zipStream = null;
try {
ByteArrayOutputStream targetStream = new ByteArrayOutputStream();
zipStream = new GZIPOutputStream(targetStream);
zipStream.write(str.getBytes());
zipStream.close();
byte[] zipped = targetStream.toByteArray();
targetStream.close();
return zipped;
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
try {
if (zipStream != null) {
zipStream.close();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}