From 67d62f9ad6392b881454db78bb65d61fe78fbe20 Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Fri, 12 Jan 2018 22:37:25 +0000 Subject: [PATCH] No functional changes. Replaces close() in finally by try-with-ressource git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1821039 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/ofbiz/base/util/UtilHttp.java | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java index be37c14818..2bae1ac825 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java @@ -1011,24 +1011,15 @@ public final class UtilHttp { } // create the streams - OutputStream out = response.getOutputStream(); - InputStream in = new ByteArrayInputStream(bytes); // stream the content - try { + try (OutputStream out = response.getOutputStream(); + InputStream in = new ByteArrayInputStream(bytes)) { streamContent(out, in, bytes.length); + out.flush(); } catch (IOException e) { - in.close(); - out.close(); // should we close the ServletOutputStream on error?? throw e; } - - // close the input stream - in.close(); - - // close the servlet output stream - out.flush(); - out.close(); } public static void streamContentToBrowser(HttpServletResponse response, byte[] bytes, String contentType) throws IOException { @@ -1060,17 +1051,12 @@ public final class UtilHttp { } // stream the content - OutputStream out = response.getOutputStream(); - try { + try (OutputStream out = response.getOutputStream()) { streamContent(out, in, length); + out.flush(); } catch (IOException e) { - out.close(); throw e; } - - // close the servlet output stream - out.flush(); - out.close(); } public static void streamContentToBrowser(HttpServletResponse response, InputStream in, int length, String contentType) throws IOException {