diff --git a/src/main/java/com/github/dockerjava/core/CompressArchiveUtil.java b/src/main/java/com/github/dockerjava/core/CompressArchiveUtil.java index 6a1a54809..0a93af3d8 100644 --- a/src/main/java/com/github/dockerjava/core/CompressArchiveUtil.java +++ b/src/main/java/com/github/dockerjava/core/CompressArchiveUtil.java @@ -2,9 +2,11 @@ import static com.github.dockerjava.core.FilePathUtil.relativize; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.zip.GZIPOutputStream; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; @@ -16,8 +18,8 @@ public static File archiveTARFiles(File base, Iterable files, String archi throws IOException { File tarFile = new File(FileUtils.getTempDirectoryPath(), archiveNameWithOutExtension + ".tar"); tarFile.deleteOnExit(); - TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile)); - try { + try(TarArchiveOutputStream tos = new TarArchiveOutputStream(new GZIPOutputStream( + new BufferedOutputStream(new FileOutputStream(tarFile))))) { tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); for (File file : files) { TarArchiveEntry tarEntry = new TarArchiveEntry(file); @@ -36,8 +38,6 @@ public static File archiveTARFiles(File base, Iterable files, String archi } tos.closeArchiveEntry(); } - } finally { - tos.close(); } return tarFile; diff --git a/src/main/java/com/github/dockerjava/core/async/ResultCallbackTemplate.java b/src/main/java/com/github/dockerjava/core/async/ResultCallbackTemplate.java index d94ce1950..857ca9177 100644 --- a/src/main/java/com/github/dockerjava/core/async/ResultCallbackTemplate.java +++ b/src/main/java/com/github/dockerjava/core/async/ResultCallbackTemplate.java @@ -63,10 +63,10 @@ public void onComplete() { @Override public void close() throws IOException { + closed = true; if (stream != null) stream.close(); completed.countDown(); - closed = true; } /** diff --git a/src/test/java/com/github/dockerjava/core/CompressArchiveUtilTest.java b/src/test/java/com/github/dockerjava/core/CompressArchiveUtilTest.java index 827f8d3be..90ca91fca 100644 --- a/src/test/java/com/github/dockerjava/core/CompressArchiveUtilTest.java +++ b/src/test/java/com/github/dockerjava/core/CompressArchiveUtilTest.java @@ -5,10 +5,12 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.zip.GZIPInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; @@ -43,7 +45,8 @@ private File extractFileByName(File archive, String filenameToExtract) throws IO expectedFile.delete(); assertThat(expectedFile.exists(), is(false)); - TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(new FileInputStream(archive)); + TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(new GZIPInputStream( + new BufferedInputStream(new FileInputStream(archive)))); TarArchiveEntry entry; while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) { String individualFiles = entry.getName(); diff --git a/src/test/java/com/github/dockerjava/core/command/BuildImageCmdImplTest.java b/src/test/java/com/github/dockerjava/core/command/BuildImageCmdImplTest.java index 6d2b4c805..5385287ef 100644 --- a/src/test/java/com/github/dockerjava/core/command/BuildImageCmdImplTest.java +++ b/src/test/java/com/github/dockerjava/core/command/BuildImageCmdImplTest.java @@ -225,4 +225,17 @@ public void testAddAndCopySubstitution() throws Exception { String response = dockerfileBuild(baseDir); assertThat(response, containsString("testENVSubstitution successfully completed")); } + + @Test + public void testBuilderPerformance() throws Exception { + File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("nginx").getFile()); + + String imageId = buildImage(baseDir); + + InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec(); + assertThat(inspectImageResponse, not(nullValue())); + LOG.info("Image Inspect: {}", inspectImageResponse.toString()); + + assertThat(inspectImageResponse.getAuthor(), equalTo("Guillaume J. Charmes \"guillaume@dotcloud.com\"")); + } }