public static void extractGzip ( File file ) throws FileNotFoundException , IOException { final String originalPath = file . getPath ( ) ; final File gzip = new File ( originalPath + ".gz" ) ; if ( gzip . isFile ( ) && ! gzip . delete ( ) ) { LOGGER . debug ( "Failed to delete initial temporary file when extracting 'gz' {}" , gzip . toString ( ) ) ; gzip . deleteOnExit ( ) ; } if ( ! file . renameTo ( gzip ) ) { throw new IOException ( "Unable to rename '" + file . getPath ( ) + "'" ) ; } final File newFile = new File ( originalPath ) ; try ( FileInputStream fis = new FileInputStream ( gzip ) ; GZIPInputStream cin = new GZIPInputStream ( fis ) ; FileOutputStream out = new FileOutputStream ( newFile ) ) { IOUtils . copy ( cin , out ) ; } finally { if ( gzip . isFile ( ) && ! org . apache . commons . io . FileUtils . deleteQuietly ( gzip ) ) { LOGGER . debug ( "Failed to delete temporary file when extracting 'gz' {}" , gzip . toString ( ) ) ; gzip . deleteOnExit ( ) ; } } }
Extracts the file contained in a gzip archive . The extracted file is placed in the exact same path as the file specified .