summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.server
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2020-01-04 17:03:52 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2020-01-06 11:40:05 +0100
commit4209a0f84b1917c0640d781ac54e8c5ffbadd574 (patch)
treeaf85f082a0cbc303be064a06ea477eecb5eb01e1 /org.eclipse.jgit.http.server
parent14bfe08757fa6267df2844c7365af9fb9ebc1578 (diff)
downloadjgit-4209a0f84b1917c0640d781ac54e8c5ffbadd574.tar.gz
jgit-4209a0f84b1917c0640d781ac54e8c5ffbadd574.zip
Fix unclosed resource warning in SmartOutputStream
Change-Id: Ia4b96ae1c2cc9357802487384ee32a80ed40334b Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.http.server')
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java30
1 files changed, 16 insertions, 14 deletions
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
index ad5e8d479e..0dfaec2567 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
@@ -105,17 +105,16 @@ class SmartOutputStream extends TemporaryBuffer {
// If output hasn't started yet, the entire thing fit into our
// buffer. Try to use a proper Content-Length header, and also
// deflate the response with gzip if it will be smaller.
- TemporaryBuffer out = this;
-
- if (256 < out.length() && acceptsGzipEncoding(req)) {
+ if (256 < this.length() && acceptsGzipEncoding(req)) {
TemporaryBuffer gzbuf = new TemporaryBuffer.Heap(LIMIT);
try {
try (GZIPOutputStream gzip = new GZIPOutputStream(gzbuf)) {
- out.writeTo(gzip, null);
+ this.writeTo(gzip, null);
}
- if (gzbuf.length() < out.length()) {
- out = gzbuf;
+ if (gzbuf.length() < this.length()) {
rsp.setHeader(HDR_CONTENT_ENCODING, ENCODING_GZIP);
+ writeResponse(gzbuf);
+ return;
}
} catch (IOException err) {
// Most likely caused by overflowing the buffer, meaning
@@ -123,15 +122,18 @@ class SmartOutputStream extends TemporaryBuffer {
// copy and use the original.
}
}
+ writeResponse(this);
+ }
+ }
- // The Content-Length cannot overflow when cast to an int, our
- // hardcoded LIMIT constant above assures us we wouldn't store
- // more than 2 GiB of content in memory.
- rsp.setContentLength((int) out.length());
- try (OutputStream os = rsp.getOutputStream()) {
- out.writeTo(os, null);
- os.flush();
- }
+ private void writeResponse(TemporaryBuffer out) throws IOException {
+ // The Content-Length cannot overflow when cast to an int, our
+ // hardcoded LIMIT constant above assures us we wouldn't store
+ // more than 2 GiB of content in memory.
+ rsp.setContentLength((int) out.length());
+ try (OutputStream os = rsp.getOutputStream()) {
+ out.writeTo(os, null);
+ os.flush();
}
}
}