summaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2020-06-12 12:12:19 +0200
committerJon Marius Venstad <venstad@gmail.com>2020-06-12 12:12:19 +0200
commit7c06d9d977969816204925b61d83b3d276a50e92 (patch)
tree00575c2f42828a30857eac7544a24f8a15c2db78 /container-core/src/main/java/com/yahoo
parenta7b28d8937fc3f8d28418dc278bb1e4d25b8ad21 (diff)
Make sure GZIPOutputStream is properly closed, but without closing channel
Diffstat (limited to 'container-core/src/main/java/com/yahoo')
-rw-r--r--container-core/src/main/java/com/yahoo/container/handler/LogReader.java19
1 files changed, 7 insertions, 12 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/LogReader.java b/container-core/src/main/java/com/yahoo/container/handler/LogReader.java
index e3fef4e0e44..ff1a7313540 100644
--- a/container-core/src/main/java/com/yahoo/container/handler/LogReader.java
+++ b/container-core/src/main/java/com/yahoo/container/handler/LogReader.java
@@ -82,10 +82,13 @@ class LogReader {
else
inProxy = in;
- // At the point when logs switch to un-zipped, replace the output stream with a zipping proxy.
- if ( ! zipped && ! (outputStream instanceof GZIPOutputStream))
- outputStream = new GZIPOutputStream(outputStream);
-
+ if ( ! zipped) {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ try (OutputStream outProxy = new GZIPOutputStream(buffer)) {
+ inProxy.transferTo(outProxy);
+ }
+ inProxy = new ByteArrayInputStream(buffer.toByteArray());
+ }
inProxy.transferTo(outputStream);
}
}
@@ -93,14 +96,6 @@ class LogReader {
catch (IOException e) {
throw new UncheckedIOException(e);
}
- finally {
- try {
- outputStream.close();
- }
- catch (IOException e) {
- throw new UncheckedIOException(e);
- }
- }
}
/** Returns log files which may have relevant entries, sorted by modification time — the first and last must be filtered. */