summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-config-adaptor/provider/src/main
diff options
context:
space:
mode:
authorTomek Kaminski <tomasz.kaminski@nokia.com>2018-01-10 18:03:41 +0100
committerSkip Wonnell <skip@att.com>2018-01-11 18:42:35 +0000
commitda5c8adf5e12114e6267a0b71cad4a50d9bbecf0 (patch)
treec7f8d81e0a419d297b7efec65a5b1cce50dc4ba8 /appc-config/appc-config-adaptor/provider/src/main
parent5a3148b4e01d473435c9fae01dbe741300a374e8 (diff)
Fix sonar blocker
Fix https://sonar.onap.org/issues/search#issues=AWBUkk54-08if2a6vTdT Change-Id: Ic50564d4d47d76ac9bfa83b8ecd6f3d23f11904c Issue-ID: APPC-383 Signed-off-by: Tomek Kaminski <tomasz.kaminski@nokia.com>
Diffstat (limited to 'appc-config/appc-config-adaptor/provider/src/main')
-rw-r--r--appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java22
1 files changed, 14 insertions, 8 deletions
diff --git a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java
index 1f161c3b0..4ef81ef1b 100644
--- a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java
+++ b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java
@@ -202,6 +202,7 @@ public class SshJcraftWrapper {
String CmdThatWasSent = removeWhiteSpaceAndNewLineCharactersAroundString(cmdThatWasSent);
int readCounts = 0;
aggregatedReceivedString = "";
+ FileWriter fileWriter = null;
long deadline = new Date().getTime() + timeout;
try {
@@ -235,7 +236,8 @@ public class SshJcraftWrapper {
StringTokenizer st = new StringTokenizer(cmdThatWasSent);
st.nextToken();
routerFileName = st.nextToken();
- out = new BufferedWriter(new FileWriter(routerFileName));
+ fileWriter = new FileWriter(routerFileName);
+ out = new BufferedWriter(fileWriter);
routerLogFileName = "/tmp/" + RouterName;
_tmpFile = new File(routerLogFileName);
debugLog.printRTAriDebug(fn,
@@ -308,10 +310,18 @@ public class SshJcraftWrapper {
debugLog.printRTAriDebug(fn, "Caught an IOException: ee=" + ee.toString());
dbLog.outputStackTrace(ee);
throw new TimedOutException(ee.toString());
+ } finally {
+ try {
+ if (fileWriter != null) {
+ fileWriter.close();
+ }
+ } catch(IOException ex) {
+ debugLog.printRTAriDebug(fn, "Failed to close fileWriter output stream: ex=" + ex);
+ }
}
String result = stripOffCmdFromRouterResponse(sbReceive.toString());
debugLog.printRTAriDebug(fn, "Leaving method successfully");
- return (result);
+ return result;
}
public boolean checkIfReceivedStringMatchesDelimeter(String delimeters, String receivedString,
@@ -332,11 +342,7 @@ public class SshJcraftWrapper {
appendToFile(debugLogFileName,
fn + " :::cmdThatWasSent='" + cmdThatWasSent + "' x=" + x + " y=" + y + "\n");
}
- if ((x != -1) && (y == x)) {
- return (true);
- } else {
- return (false);
- }
+ return (x != -1) && (y == x);
}
if (cmdThatWasSent.indexOf("show config") != -1) {
appendToFile(debugLogFileName, fn + "In the block for 'show config'\n");
@@ -794,7 +800,7 @@ public class SshJcraftWrapper {
}
}
} catch (JSchException e) {
- debugLog.printRTAriDebug(fn, "Caught an JSchException e=" + e.toString());
+ debugLog.printRTAriDebug(fn, "Caught an JSchException e=" + e);
debugLog.printRTAriDebug(fn,
"ncharsSent=" + ncharsSent + " ncharsTotalReceived=" + ncharsTotalReceived + " ncharsRead="
+ ncharsRead);