summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-config-adaptor/provider
diff options
context:
space:
mode:
authorKrishnajinka <kris.jinka@samsung.com>2018-07-06 11:40:55 +0900
committerKrishnajinka <kris.jinka@samsung.com>2018-07-09 10:08:05 +0900
commitda8d16cb974f9b203a59fb350e2179bf19ac3bce (patch)
treef48a34880dabe8fe14aa5cf3a1a47089c320daad /appc-config/appc-config-adaptor/provider
parentf5d3fa206b636a7e235b57b43a7812c92258208a (diff)
use try with resources
Issue-ID: APPC-1046 Change-Id: I28ca35b8a888875f91afda05c4dedee3ed301dde Signed-off-by: Krishnajinka <kris.jinka@samsung.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/DebugLog.java6
-rw-r--r--appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java70
2 files changed, 38 insertions, 38 deletions
diff --git a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/DebugLog.java b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/DebugLog.java
index fb9d7a392..18fcc8413 100644
--- a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/DebugLog.java
+++ b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/DebugLog.java
@@ -69,9 +69,9 @@ public class DebugLog {
// write to it. If it does not exist, don't write to it.
File tmpFile = new File(fileName);
if (tmpFile.exists()) {
- BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
- out.write(dataToWrite);
- out.close();
+ try(BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true))) {
+ out.write(dataToWrite);
+ }
}
} catch (IOException e) {
DebugLog.printRTAriDebug(fn, "writeToFile() exception: " + e);
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 53aaad331..28f00069a 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
@@ -583,11 +583,11 @@ public class SshJcraftWrapper {
// write to it. If it does not exist, don't write to it.
File tmpFile = new File(fileName);
if (tmpFile.exists()) {
- BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
- // out.write(dataToWrite);
- // out.write(getTheDate() +": " +Thread.currentThread().getName() +": "+dataToWrite);
- out.write(getTheDate() + ": " + tId + ": " + dataToWrite);
- out.close();
+ try(BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true))) {
+ // out.write(dataToWrite);
+ // out.write(getTheDate() +": " +Thread.currentThread().getName() +": "+dataToWrite);
+ out.write(getTheDate() + ": " + tId + ": " + dataToWrite);
+ }
}
} catch (IOException e) {
debugLog.printRTAriDebug(fn, "Caught an IOException: e=" + e);
@@ -604,9 +604,9 @@ public class SshJcraftWrapper {
// write to it. If it does not exist, don't write to it.
File tmpFile = new File(fileName);
if (tmpFile.exists()) {
- BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
- out.write(dataToWrite);
- out.close();
+ try(BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true))) {
+ out.write(dataToWrite);
+ }
}
} catch (IOException e) {
debugLog.printRTAriDebug(fn, "Caught an IOException: e=" + e);
@@ -635,10 +635,10 @@ public class SshJcraftWrapper {
{
// if ((tmpFile.exists()) && (tmpFile.setWritable(true, true)))
if (tmpFile.exists()) {
- BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
- // out.write("<!-- "+getTheDate() +": " +tId +" -->\n");
- out.write(dataToWrite.toString());
- out.close();
+ try(BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true))) {
+ // out.write("<!-- "+getTheDate() +": " +tId +" -->\n");
+ out.write(dataToWrite.toString());
+ }
}
}
} catch (IOException e) {
@@ -656,10 +656,10 @@ public class SshJcraftWrapper {
File tmpFile = new File(fileName);
// if ((tmpFile.exists()) && (tmpFile.setWritable(true, true)))
if (tmpFile.exists()) {
- BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
- // out.write("<!-- "+getTheDate() +": " +tId +" -->\n");
- out.write(charBuffer, 0, len);
- out.close();
+ try(BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true))) {
+ // out.write("<!-- "+getTheDate() +": " +tId +" -->\n");
+ out.write(charBuffer, 0, len);
+ }
}
} catch (IOException e) {
System.err.println("writeToFile() exception: " + e);
@@ -712,29 +712,29 @@ public class SshJcraftWrapper {
public String getLastFewLinesOfFile(File file, int linesToRead) throws IOException {
String fn = "SshJcraftWrapper.getLastFewLinesOfFile";
- 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();
- // System.out.println(builder.toString());
- 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();
+ // System.out.println(builder.toString());
+ tail = builder.toString() + tail;
+ lines++;
+ builder.setLength(0);
+ if (lines == linesToRead) {
+ break;
+ }
}
}
}
- randomAccessFile.close();
if (!jcraftReadSwConfigFileFromDisk()) {
debugLog.printRTAriDebug(fn, "tail='" + tail + "'");
}