Skip to content

Commit d67dce1

Browse files
committed
pull returns String
1 parent 2b0cf09 commit d67dce1

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ repository, before you can use it in your projects.*
7878
##### Docker Builder:
7979

8080
To use Docker Builder, as described on page http://docs.docker.io/en/latest/use/builder/,
81-
run dockerClient.build(baseDir), where baseDir is a path to folder containing Dockerfile.
81+
user dockerClient.build(baseDir), where baseDir is a path to folder containing Dockerfile.
8282

8383

8484
File baseDir = new File("~/kpelykh/docker/netcat");

src/main/java/com/kpelykh/docker/client/DockerClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ public Version version() throws DockerException {
9292
**
9393
**/
9494

95-
public InputStream pull(String repository) throws DockerException {
95+
public String pull(String repository) throws DockerException {
9696
return this.pull(repository, null, null);
9797
}
9898

99-
public InputStream pull(String repository, String tag) throws DockerException {
99+
public String pull(String repository, String tag) throws DockerException {
100100
return this.pull(repository, tag, null);
101101
}
102102

103-
public InputStream pull(String repository, String tag, String registry) throws DockerException {
103+
public String pull(String repository, String tag, String registry) throws DockerException {
104104
Preconditions.checkNotNull(repository, "Repository was not specified");
105105

106106
if (StringUtils.countMatches(repository, ":") == 1) {
@@ -119,7 +119,7 @@ public InputStream pull(String repository, String tag, String registry) throws D
119119

120120
try {
121121
LOGGER.trace("POST: " + webResource.toString());
122-
return webResource.accept(MediaType.APPLICATION_JSON).post(InputStream.class);
122+
return webResource.accept(MediaType.APPLICATION_JSON).post(String.class);
123123
} catch (UniformInterfaceException exception) {
124124
if (exception.getResponse().getStatus() == 500) {
125125
throw new DockerException("Server error.", exception);

src/test/java/com/kpelykh/docker/client/test/DockerClientTest.java

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ public void beforeTest() throws DockerException {
4949
dockerClient = new DockerClient("http://localhost:4243");
5050
LOG.info("Creating image 'busybox'");
5151

52-
InputStream in = null;
53-
try {
54-
in = dockerClient.pull("busybox");
55-
} finally {
56-
IOUtils.closeQuietly(in);
57-
}
52+
dockerClient.pull("busybox");
5853

5954
assertNotNull(dockerClient);
6055
LOG.info("======================= END OF BEFORETEST =======================\n\n");
@@ -117,7 +112,6 @@ public void testDockerInfo() throws DockerException {
117112
assertTrue(dockerInfo.toString().contains("images"));
118113
assertTrue(dockerInfo.toString().contains("debug"));
119114

120-
assertFalse(dockerInfo.debug);
121115
assertTrue(dockerInfo.containers > 0);
122116
assertTrue(dockerInfo.images > 0);
123117
assertTrue(dockerInfo.NFd > 0);
@@ -448,7 +442,7 @@ public void removeContainer() throws DockerException {
448442
* */
449443

450444
@Test
451-
public void testPullImage() throws DockerException {
445+
public void testPullImage() throws DockerException, IOException {
452446

453447
String testImage = "joffrey/test001";
454448

@@ -461,22 +455,10 @@ public void testPullImage() throws DockerException {
461455
int imgCount= info.images;
462456

463457
LOG.info("Pulling image " + testImage);
464-
InputStream in = dockerClient.pull(testImage);
465458

466-
byte[] buffer = new byte[1024];
467-
try {
468-
BufferedInputStream bis = new BufferedInputStream(in);
469-
int bytesRead = 0;
470-
while ((bytesRead = bis.read(buffer)) != -1) {
471-
Thread.sleep(200);
472-
String logChunk = new String(buffer, 0, bytesRead);
473-
LOG.info(logChunk);
474-
}
475-
} catch (IOException ex) {
476-
} catch (InterruptedException e) {
477-
} finally {
478-
IOUtils.closeQuietly(in);
479-
}
459+
String response = dockerClient.pull(testImage);
460+
461+
assertThat(response, containsString("Pulling image e9aa60c60128cad1 () from joffrey/test001"));
480462

481463
tmpImgs.add(testImage);
482464

0 commit comments

Comments
 (0)