diff options
Diffstat (limited to 'rulemgt')
-rw-r--r-- | rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java index 8376daf..83555b2 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/resources/SwaggerResource.java @@ -18,11 +18,8 @@ package org.onap.holmes.rulemgt.resources; import io.swagger.annotations.Api; import io.swagger.annotations.SwaggerDefinition; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; + +import java.io.*; import java.net.URL; import java.net.URLDecoder; import javax.ws.rs.GET; @@ -44,12 +41,15 @@ public class SwaggerResource { URL url = SwaggerResource.class.getResource("/swagger.json"); String ret = "{}"; - BufferedReader br = null; + File file; try { System.out.println(URLDecoder.decode(url.getPath(), "UTF-8")); - File file = new File(URLDecoder.decode(url.getPath(), "UTF-8")); - - br = new BufferedReader(new FileReader(file)); + file = new File(URLDecoder.decode(url.getPath(), "UTF-8")); + } catch(IOException e) { + log.warn("An error occurred while reading swagger.json.", e); + return ret; + } + try(BufferedReader br = new BufferedReader(new FileReader(file));) { StringBuffer buffer = new StringBuffer(); String line = " "; while ((line = br.readLine()) != null) { @@ -60,16 +60,7 @@ public class SwaggerResource { log.warn("Failed to read the API description file.", e); } catch (IOException e) { log.warn("An error occurred while reading swagger.json.", e); - } finally { - if (br != null) { - try { - br.close(); - } catch (IOException e) { - log.warn("Failed to close the file reader. This may cause memory leak."); - } - } } - return ret; } } |