static byte [ ] gzip ( byte [ ] val ) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream ( val . length ) ; GZIPOutputStream gos = null ; try { gos = new GZIPOutputStream ( bos ) ; gos . write ( val , 0 , val . length ) ; gos . finish ( ) ; gos . flush ( ) ; bos . flush ( ) ; val = bos . toByteArray ( ) ; } finally { if ( gos != null ) gos . close ( ) ; if ( bos != null ) bos . close ( ) ; } return val ; }
only called once in case no need for optimization