EventStoreDownloadMojo extends AbstractEventStoreMojo { public static void unTarGz(final File archive, final File destDir) throws MojoExecutionException { try { final TarArchiveInputStream tarIn = new TarArchiveInputStream( new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(archive)))); try { TarArchiveEntry entry; while ((entry = (TarArchiveEntry) tarIn.getNextEntry()) != null) { LOG.info("Extracting: " + entry.getName()); final File file = new File(destDir, entry.getName()); if (entry.isDirectory()) { mkDirsIfNecessary(file); } else { mkDirsIfNecessary(file.getParentFile()); int count; final byte[] data = new byte[MB]; final FileOutputStream fos = new FileOutputStream(file); final BufferedOutputStream dest = new BufferedOutputStream(fos, MB); try { while ((count = tarIn.read(data, 0, MB)) != -1) { dest.write(data, 0, count); } } finally { dest.close(); } entry.getMode(); } applyFileMode(file, new FileMode(entry.getMode())); } } finally { tarIn.close(); } } catch (final IOException ex) { throw new MojoExecutionException("Error uncompressing event store archive: " + archive, ex); } }  final File getDownloadFile(); static void unzip(final File zipFile, final File destDir); static void unTarGz(final File archive, final File destDir);  }
@Test public void testUnTarGz() throws MojoExecutionException, IOException { final String name = this.getClass().getSimpleName() + "-testUnTarGz"; final File archive = File.createTempFile(name + "-", ".tar.gz"); final File destDir = new File(Utils4J.getTempDir(), name); init("example.tar.gz", archive, destDir); EventStoreDownloadMojo.unTarGz(archive, destDir); assertAllExists(destDir); }
@Test public void testUnTarGzFilesOnly() throws MojoExecutionException, IOException { final String name = this.getClass().getSimpleName() + "-testUnTarGzFilesOnly"; final File archive = File.createTempFile(name + "-", ".tar.gz"); final File destDir = new File(Utils4J.getTempDir(), name); init("files-only.tar.gz", archive, destDir); EventStoreDownloadMojo.unTarGz(archive, destDir); assertAllExists(destDir); }