FileDecompressor { public static void main(String[] args) throws Exception { String uri = args[0]; Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(URI.create(uri), conf); Path inputPath = new Path(uri); CompressionCodecFactory factory = new CompressionCodecFactory(conf); CompressionCodec codec = factory.getCodec(inputPath); if (codec == null) { System.err.println("No codec found for " + uri); System.exit(1); } String outputUri = CompressionCodecFactory.removeSuffix(uri, codec.getDefaultExtension()); InputStream in = null; OutputStream out = null; try { in = codec.createInputStream(fs.open(inputPath)); out = fs.create(new Path(outputUri)); IOUtils.copyBytes(in, out, conf); } finally { IOUtils.closeStream(in); IOUtils.closeStream(out); } }  static void main(String[] args);  }
@Test public void decompressesGzippedFile() throws Exception { File file = File.createTempFile("file", ".gz"); file.deleteOnExit(); InputStream in = this.getClass().getResourceAsStream("/file.gz"); IOUtils.copyBytes(in, new FileOutputStream(file), 4096, true); String path = file.getAbsolutePath(); FileDecompressor.main(new String[] { path }); String decompressedPath = path.substring(0, path.length() - 3); assertThat(readFile(new File(decompressedPath)), is("Text\n")); }