diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java index 5a0956dcdd..a7b53cfcc8 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/restapi/RestApiServlet.java @@ -105,6 +105,7 @@ import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.EOFException; +import java.io.FilterOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -767,10 +768,15 @@ public class RestApiServlet extends HttpServlet { b64 = new BinaryResult() { @Override public void writeTo(OutputStream out) throws IOException { - try (OutputStreamWriter w = new OutputStreamWriter(out, ISO_8859_1); + try (OutputStreamWriter w = new OutputStreamWriter( + new FilterOutputStream(out) { + @Override + public void close() { + // Do not close out, but only w and e. + } + }, ISO_8859_1); OutputStream e = BaseEncoding.base64().encodingStream(w)) { src.writeTo(e); - e.flush(); } } };