Code example for GZIPOutputStream

Methods: close, flush, write

0
	private byte[] gzip(byte[] in) {
		if (in != null && in.length > 0) {
			long tstart = System.currentTimeMillis();
			ByteArrayOutputStream bout = new ByteArrayOutputStream();
			try { 
				GZIPOutputStream gout = new GZIPOutputStream(bout);
				gout.write(in);
				gout.flush();
				gout.close();
				if (logger.isDebugEnabled()) { 
					logger.debug("gzipping took " 
							+ (System.currentTimeMillis() - tstart) + " msec");
				} 
				return bout.toByteArray();
			} catch (IOException io) {
				logger.error("io exception gzipping byte array", io);
			} 
		} 
		return new byte[0]; 
	} 
}