diff options
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/controller')
-rw-r--r-- | ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/controller/FileServletController.java | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/controller/FileServletController.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/controller/FileServletController.java index d54e0579..a03c9539 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/controller/FileServletController.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/fusion/controller/FileServletController.java @@ -141,12 +141,10 @@ public class FileServletController { private void serveFile(HttpServletResponse response, File inFile) throws Exception { - OutputStream os = null; - InputStream is = null; - try { + + try(InputStream is = new BufferedInputStream(new FileInputStream(inFile)); + OutputStream os = new BufferedOutputStream(response.getOutputStream());) { response.reset(); - is = new BufferedInputStream(new FileInputStream(inFile)); - os = new BufferedOutputStream(response.getOutputStream()); response.setContentLength((int) inFile.length()); response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment; filename=\"" @@ -154,16 +152,7 @@ public class FileServletController { copyStream(is, os); os.flush(); } catch (Exception ex) { - if (os == null) - throw new Exception("Could not open output stream for file "); - if (is == null) - throw new Exception("Could not open input stream for file "); - } finally { - if (os != null) { - os.close(); - } - if (is != null) - is.close(); + throw new Exception("Could not open input or output stream for file "); } } |