public static void decompressTarGz(File tarGzFile, File destDir) { try { IOUtils.forceMkdir(destDir); TarInputStream tin = new TarInputStream(new GZIPInputStream(new FileInputStream(tarGzFile))); TarEntry tarEntry = tin.getNextEntry(); while (tarEntry != null) { File destPath = new File(destDir, tarEntry.getName()); if (tarEntry.isDirectory()) { IOUtils.forceMkdir(destPath); } else { FileOutputStream fout = new FileOutputStream(destPath); tin.copyEntryContents(fout); fout.close(); } tarEntry = tin.getNextEntry(); } tin.close(); } catch (IOException e) { throw new UncheckedIOException(e); } }
protected void getFileContent(Launcher launcher, String containerId, String filename, OutputStream outputStream) throws IOException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder() .add("cp", containerId + ":" + filename, "-"); ByteArrayOutputStream out = new ByteArrayOutputStream(); int status = launchDockerCLI(launcher, args) .stdout(out).stderr(launcher.getListener().getLogger()).join(); if (status != 0) { throw new IOException("Failed to get file"); } TarInputStream tar = new TarInputStream(new ByteArrayInputStream(out.toByteArray())); tar.getNextEntry(); tar.copyEntryContents(outputStream); tar.close(); }
destPath.delete(); fout = new FileOutputStream(destPath); tin.copyEntryContents(fout);
protected void getFileContent(Launcher launcher, String containerId, String filename, OutputStream outputStream) throws IOException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder() .add("cp", containerId + ":" + filename, "-"); ByteArrayOutputStream out = new ByteArrayOutputStream(); int status = launchDockerCLI(launcher, args) .stdout(out).stderr(launcher.getListener().getLogger()).join(); if (status != 0) { throw new IOException("Failed to get file"); } TarInputStream tar = new TarInputStream(new ByteArrayInputStream(out.toByteArray())); tar.getNextEntry(); tar.copyEntryContents(outputStream); tar.close(); }
private void untarTo(InputStream source, File path) throws IOException { TarInputStream is = new TarInputStream(source); TarEntry entry = null; try { while (null != (entry = is.getNextEntry())) { File target = new File(path, entry.getName()); ensureParentDirectory(target); if (entry.isDirectory()) { target.mkdirs(); } else { if (target.exists()) { target.delete(); } FileOutputStream os = new FileOutputStream(target); try { is.copyEntryContents(os); } finally { finallyClose(os); } } } } finally { finallyClose(is); } } public String getName() {