Source:
protected String doBuildImage(String repository, File tar, final ProgressMonitor progressMonitor, URI dockerDaemonUri, AuthConfigs authConfigs) throws IOException, InterruptedException { if (authConfigs == null) { authConfigs = initialAuthConfig.getAuthConfigs(); } final List<Pair<String, ?>> headers = new ArrayList<>(3); headers.add(Pair.of("Content-Type", "application/x-compressed-tar")); headers.add(Pair.of("Content-Length", tar.length())); headers.add(Pair.of("X-Registry-Config", Base64.encodeBase64String(JsonHelper.toJson(authConfigs).getBytes()))); try (InputStream tarInput = new FileInputStream(tar); DockerConnection connection = openConnection(dockerDaemonUri).method("POST") .path("/build") .query("rm", 1) .query("pull", 1) .headers(headers) .entity(tarInput)) { if (repository != null) { connection.query("t", repository); } final DockerResponse response = connection.request(); final int status = response.getStatus(); if (200 != status) { throw new DockerException(getDockerExceptionMessage(response), status); } try (InputStream responseStream = response.getInputStream()) { JsonMessageReader<ProgressStatus> progressReader = new JsonMessageReader<>(responseStream, ProgressStatus.class); final ValueHolder<IOException> errorHolder = new ValueHolder<>(); final ValueHolder<String> imageIdHolder = new ValueHolder<>(); final Runnable runnable = new Runnable() { @Override public void run() { try { ProgressStatus progressStatus; while ((progressStatus = progressReader.next()) != null) { final String buildImageId = getBuildImageId(progressStatus); if (buildImageId != null) { imageIdHolder.set(buildImageId); } progressMonitor.updateProgress(progressStatus); } } catch (IOException e) { errorHolder.set(e); } synchronized (this) { notify(); } } }; executor.execute(runnable); synchronized (runnable) { runnable.wait(); } final IOException ioe = errorHolder.get(); if (ioe != null) { throw ioe; } if (imageIdHolder.get() == null) { throw new IOException("Docker image build failed"); } return imageIdHolder.get(); } } }

Target:
protected String doBuildImage(String repository, File tar, final ProgressMonitor progressMonitor, URI dockerDaemonUri, AuthConfigs authConfigs) throws IOException, InterruptedException { if (authConfigs == null) { authConfigs = initialAuthConfig.getAuthConfigs(); } final List<Pair<String, ?>> headers = new ArrayList<>(3); headers.add(Pair.of("Content-Type", "application/x-compressed-tar")); headers.add(Pair.of("Content-Length", tar.length())); headers.add(Pair.of("X-Registry-Config", Base64.encodeBase64String(JsonHelper.toJson(authConfigs).getBytes()))); try (InputStream tarInput = new FileInputStream(tar); DockerConnection connection = openConnection(dockerDaemonUri).method("POST") .path("/build") .query("rm", 1) .query("pull", 1) .headers(headers) .entity(tarInput)) { if (repository != null) { connection.query("t", repository); } final DockerResponse response = connection.request(); final int status = response.getStatus(); if (OK.getStatusCode() != status) { throw new DockerException(getDockerExceptionMessage(response), status); } try (InputStream responseStream = response.getInputStream()) { JsonMessageReader<ProgressStatus> progressReader = new JsonMessageReader<>(responseStream, ProgressStatus.class); final ValueHolder<IOException> errorHolder = new ValueHolder<>(); final ValueHolder<String> imageIdHolder = new ValueHolder<>(); final Runnable runnable = new Runnable() { @Override public void run() { try { ProgressStatus progressStatus; while ((progressStatus = progressReader.next()) != null) { final String buildImageId = getBuildImageId(progressStatus); if (buildImageId != null) { imageIdHolder.set(buildImageId); } progressMonitor.updateProgress(progressStatus); } } catch (IOException e) { errorHolder.set(e); } synchronized (this) { notify(); } } }; executor.execute(runnable); synchronized (runnable) { runnable.wait(); } final IOException ioe = errorHolder.get(); if (ioe != null) { throw ioe; } if (imageIdHolder.get() == null) { throw new IOException("Docker image build failed"); } return imageIdHolder.get(); } } }