aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-config-adaptor/provider
diff options
context:
space:
mode:
authorTomek Kaminski <tomasz.kaminski@nokia.com>2018-02-23 15:43:45 +0100
committerPatrick Brady <pb071s@att.com>2018-02-26 19:10:14 +0000
commita050062ff4a19586d52a045e79f2f065477adec0 (patch)
tree4cbb2188dec43b853fe574cb956d2b4b8898de6c /appc-config/appc-config-adaptor/provider
parent49561fcacc76c5fe6f431d926702bf24b0c7beb3 (diff)
Fix Sonar Bug
Fix for: https://sonar.onap.org/project/issues?id=org.onap.appc%3Aappc&issues=AWGYEYwt8TZzbCgU6gOm&open=AWGYEYwt8TZzbCgU6gOm Change-Id: I632c21efb8e69c04fc346841900d98d4908b360e Issue-ID: APPC-668 Signed-off-by: Tomek Kaminski <tomasz.kaminski@nokia.com>
Diffstat (limited to 'appc-config/appc-config-adaptor/provider')
-rw-r--r--appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java36
1 files changed, 18 insertions, 18 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 d812507ea..4d81b6c24 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
@@ -549,28 +549,28 @@ public class SshJcraftWrapper {
}
public String getLastFewLinesOfFile(File file, int linesToRead) throws IOException {
- RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
- int lines = 0;
- StringBuilder builder = new StringBuilder();
String tail = "";
- long length = file.length();
- length--;
- randomAccessFile.seek(length);
- for (long seek = length; seek >= 0; --seek) {
- randomAccessFile.seek(seek);
- char c = (char) randomAccessFile.read();
- builder.append(c);
- if (c == '\n') {
- builder = builder.reverse();
- tail = builder.toString() + tail;
- lines++;
- builder.setLength(0);
- if (lines == linesToRead) {
- break;
+ try(RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r")) {
+ int lines = 0;
+ StringBuilder builder = new StringBuilder();
+ long length = file.length();
+ length--;
+ randomAccessFile.seek(length);
+ for (long seek = length; seek >= 0; --seek) {
+ randomAccessFile.seek(seek);
+ char c = (char) randomAccessFile.read();
+ builder.append(c);
+ if (c == '\n') {
+ builder = builder.reverse();
+ tail = builder.append(tail).toString();
+ lines++;
+ builder.setLength(0);
+ if (lines == linesToRead) {
+ break;
+ }
}
}
}
- randomAccessFile.close();
if (log.isDebugEnabled()) {
log.debug("Content read from file={0} was tail={1}", file.getName(), tail);
}