From 8cd208ebaa33627daf05d8ffff7b28e53a7067d0 Mon Sep 17 00:00:00 2001 From: "Christopher Lott (cl778h)" Date: Thu, 7 Sep 2017 08:52:41 -0400 Subject: Adjust code for Sonar issues Made non-functional updates to address static code analysis issues. Update license header with simple double-quote characters. Issue: PORTAL-72, PORTAL-90 Change-Id: Ic2c330daea07d721f0e6b350ebf03da97073f7ce Signed-off-by: Christopher Lott (cl778h) --- .../core/onboarding/rest/RestWebServiceClient.java | 29 ++++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java') diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java index 7c9f72a1..1533db79 100644 --- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java +++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java @@ -6,7 +6,7 @@ * =================================================================== * * Unless otherwise specified, all software contained herein is licensed - * under the Apache License, Version 2.0 (the “License”); + * under the Apache License, Version 2.0 (the "License"); * you may not use this software except in compliance with the License. * You may obtain a copy of the License at * @@ -19,7 +19,7 @@ * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed - * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * @@ -365,7 +365,7 @@ public class RestWebServiceClient { con.getOutputStream().close(); int responseCode = con.getResponseCode(); - logger.debug("Response Code : " + responseCode); + logger.debug("RestWebServiceClient.post: response code " + responseCode); final String response = readAndCloseStream(con.getInputStream()); return response; } @@ -461,7 +461,7 @@ public class RestWebServiceClient { throws IOException { if (logger.isDebugEnabled()) - logger.debug("RestWebServiceClient.post to URL " + url); + logger.debug("RestWebServiceClient.delete to URL " + url); if (appName == null || appName.trim().length() == 0) appName = "Unknown"; if (requestId == null || requestId.trim().length() == 0) @@ -505,14 +505,13 @@ public class RestWebServiceClient { con.getOutputStream().close(); int responseCode = con.getResponseCode(); - logger.debug("Response Code : " + responseCode); + logger.debug("RestWebServiceClient.delete: response code " + responseCode); final String response = readAndCloseStream(con.getInputStream()); return response; } /** - * Reads content of string to a StringBuffer, decoded as UTF-8, and returns as - * string. + * Reads content of stream, decodes as UTF-8, and returns as string. * * @param inputStream * Stream to read @@ -520,17 +519,15 @@ public class RestWebServiceClient { * @throws IOException */ private String readAndCloseStream(InputStream inputStream) throws IOException { - StringBuffer sb = new StringBuffer(); - InputStreamReader in = null; - char[] buf = new char[8196]; - int bytes; - try { - in = new InputStreamReader(inputStream, "UTF-8"); + StringBuilder sb = new StringBuilder(); + try (InputStreamReader in = new InputStreamReader(inputStream, "UTF-8")) { + char[] buf = new char[8196]; + int bytes; while ((bytes = in.read(buf)) > 0) sb.append(new String(buf, 0, bytes)); - } finally { - if (in != null) - in.close(); + } + catch (Exception ex) { + logger.error("readAndCloseStream", ex); } return sb.toString(); } -- cgit 1.2.3-korg