Skip to content

Commit

Permalink
Issue fabric8io#1205 Make constants for buffer sizes.
Browse files Browse the repository at this point in the history
Signed-off-by: William Rose <[email protected]>
  • Loading branch information
wrosenuance committed Apr 12, 2019
1 parent adc22e7 commit 38a7cb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public class DockerAccessWithHcClient implements DockerAccess {
// Minimal API version, independent of any feature used
public static final String API_VERSION = "1.18";

// Copy buffer size when saving images
private static final int COPY_BUFFER_SIZE = 65536;

// Logging
private final Logger log;

Expand Down Expand Up @@ -465,7 +468,7 @@ private ResponseHandler<Object> getImageResponseHandler(final String filename, f
public Object handleResponse(HttpResponse response) throws IOException {
try (InputStream stream = response.getEntity().getContent();
OutputStream out = compression.wrapOutputStream(new FileOutputStream(filename))) {
IOUtils.copy(stream, out, 65536);
IOUtils.copy(stream, out, COPY_BUFFER_SIZE);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ public static ArchiveCompression fromFileName(String filename) {
return ArchiveCompression.none;
}

private static final int GZIP_BUFFER_SIZE = 65536;
// According to https://bugs.openjdk.java.net/browse/JDK-8142920, 3 is a better default
private static final int GZIP_COMPRESSION_LEVEL = 3;

private static class GZIPOutputStream extends java.util.zip.GZIPOutputStream {
private GZIPOutputStream(OutputStream out) throws IOException {
super(out, 65536);
// According to https://bugs.openjdk.java.net/browse/JDK-8142920, 3 is a better default
def.setLevel(3);
super(out, GZIP_BUFFER_SIZE);
def.setLevel(GZIP_COMPRESSION_LEVEL);
}
}
}

0 comments on commit 38a7cb7

Please sign in to comment.