public static long gzip ( InputStream inputStream , OutputStream out ) throws IOException { try ( GZIPOutputStream outputStream = new GZIPOutputStream ( out ) ) { final long result = ByteStreams . copy ( inputStream , outputStream ) ; out . flush ( ) ; return result ; } finally { inputStream . close ( ) ; } }
Copy inputStream to out while wrapping out in a GZIPOutputStream Closes both input and output