summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYan Yang <yangyanyj@chinamobile.com>2018-03-21 00:58:52 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-21 00:58:52 +0000
commitcae4110224a71f7678a13231c9050939c5d73f98 (patch)
treecff7752d8dda077c2a9f6415683348a0296de361
parent849c25e46eba70936966bb33e5741430f7ac2936 (diff)
parentc5ddf8a78d43fc947cc011d9d572b4dea1dd59eb (diff)
Merge "Code improvements in Common Utils"
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java19
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DriverThread.java3
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Gunzip.java9
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java6
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java14
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java22
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java9
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java27
8 files changed, 43 insertions, 66 deletions
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java
index 9e84374..d1e5898 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java
@@ -71,18 +71,13 @@ public class DateUtil {
}
public static String addTime(String srcTimeString, String period) throws ParseException {
- try{
- String finaldate = getTimeString(srcTimeString);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = sdf.parse(finaldate);
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- calendar.add(Calendar.MINUTE, Integer.valueOf(period));
- return sdf.format(calendar.getTime());
- }catch( ParseException e){
- throw e;
- }
-
+ String finaldate = getTimeString(srcTimeString);
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Date date = sdf.parse(finaldate);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ calendar.add(Calendar.MINUTE, Integer.valueOf(period));
+ return sdf.format(calendar.getTime());
}
}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DriverThread.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DriverThread.java
index 64b518b..8e57d5e 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DriverThread.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DriverThread.java
@@ -44,7 +44,7 @@ public abstract class DriverThread implements Runnable {
public abstract void dispose();
- final public void run() {
+ public final void run() {
t = Thread.currentThread();
if (name != null)
t.setName(name);
@@ -52,7 +52,6 @@ public abstract class DriverThread implements Runnable {
try {
dispose();
} catch (Exception e) {
- //e.printStackTrace();
log.error(" printStackTrace :", e);
}
this.setEnd(true);
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Gunzip.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Gunzip.java
index e6ed9d5..edbeebc 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Gunzip.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Gunzip.java
@@ -29,7 +29,7 @@ public class Gunzip {
moveBytes(gzIn, fileOutput, -1, -1, 1024);
}
}catch(IOException e){
- throw e;
+ throw new IOException ("Gunzip", e);
}
}
@@ -44,10 +44,10 @@ public class Gunzip {
}
public long moveBytes(InputStream input, OutputStream output, long off, long len, int bufsize) throws IOException {
- long skipped=0;
- if (off > 0)
+ /* long skipped=0;
+ if (off > 0)
skipped = input.skip(off); // check if skipped is same as off
-
+ */
long totalNum = 0;
byte[] buf = new byte[bufsize];
@@ -65,7 +65,6 @@ public class Gunzip {
output.write(buf, 0, readNum);
totalNum += readNum;
}
- buf = null;
return totalNum;
}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java
index e09ff8d..5fa0f9a 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java
@@ -46,10 +46,6 @@ public class StringUtil {
}
public static boolean isBank(String str) {
- if (str == null || str.trim().length() == 0) {
-
- return true;
- }
- return false;
+ return (str == null || str.trim().length() == 0);
}
}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java
index 504a47b..6d49d10 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java
@@ -58,26 +58,22 @@ public class UnZip {
}
}
} catch (IOException e) {
- throw e;
+ throw new IOException("deCompress: ",e);
}
}
protected void deCompressFile(InputStream input, String toPath)
throws IOException {
- byte byteBuf[] = new byte[2048];
+ byte[] byteBuf = new byte[2048];
String path = new File(toPath).getParent();
if (!new File(path).exists()) {
new File(path).mkdirs();
}
- FileOutputStream output = new FileOutputStream(toPath, false);
- try {
+ try(FileOutputStream output = new FileOutputStream(toPath, false)){
for (int count = 0; (count = input.read(byteBuf, 0, byteBuf.length)) != -1; )
output.write(byteBuf, 0, count);
} catch (IOException e) {
- throw e;
- } finally {
- output.close();
- input.close();
- }
+ throw new IOException ("deCompressFile: ", e);
+ }
}
}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java
index 0e3f27c..5ea9a90 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java
@@ -25,12 +25,12 @@ import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-final public class VarExprParser {
+ public final class VarExprParser {
private static Log log = LogFactory.getFactory().getInstance(VarExprParser.class);
private static Pattern varPattern = Pattern.compile("(\\$\\{([^\\}]+)\\})",
Pattern.CASE_INSENSITIVE);
- final static public String replaceVar(String str, long scan_start_time, long scan_stop_time) {
+ public static final String replaceVar(String str, long scanStartTime, long scanStopTime) {
if (str.indexOf("${") == -1)
return str;
@@ -46,16 +46,16 @@ final public class VarExprParser {
str = str.replace("${e_hour}", "${SCAN_STOP_TIME,HH}");
str = str.replace("${e_min}", "${SCAN_STOP_TIME,mm}");
- String expr = null, varName = null, value = null;
+ String expr, varName, value ;
Matcher matcher = varPattern.matcher(str);
while (matcher.find()) {
value = null;
expr = matcher.group(1);
varName = matcher.group(2);
if (expr.indexOf("${SCAN_START_TIME") != -1) {
- value = getTime(scan_start_time, varName, "yyyy-MM-dd HH:mm:ss");
+ value = getTime(scanStartTime, varName, "yyyy-MM-dd HH:mm:ss");
} else if (expr.indexOf("${SCAN_STOP_TIME") != -1) {
- value = getTime(scan_stop_time, varName, "yyyy-MM-dd HH:mm:ss");
+ value = getTime(scanStopTime, varName, "yyyy-MM-dd HH:mm:ss");
}
if (value == null) {
log.warn(" expr [" + str + "] var["
@@ -64,8 +64,6 @@ final public class VarExprParser {
}
str = str.replace(expr, value);
}
- expr = value = null;
- matcher = null;
return str;
}
@@ -111,11 +109,11 @@ final public class VarExprParser {
/**
* Support two variable substitutions
* @param result
- * @param scan_start_time
- * @param scan_stop_time
+ * @param scanStartTime
+ * @param scanStopTime
* @return
*/
- public static String replaceTimeVar(String result,String scan_start_time, String scan_stop_time) {
+ public static String replaceTimeVar(String result,String scanStartTime, String scanStopTime) {
boolean isReplace = false;
if (result.indexOf("${SCAN_ST") != -1) {
isReplace = true;
@@ -123,11 +121,11 @@ final public class VarExprParser {
if (isReplace) {
if (result.indexOf("${SCAN_START_TIME}") != -1) {
- result = StringUtils.replace(result, "${SCAN_START_TIME}", scan_start_time);
+ result = StringUtils.replace(result, "${SCAN_START_TIME}", scanStartTime);
}
if (result.indexOf("${SCAN_STOP_TIME") != -1) {
- result = StringUtils.replace(result, "${SCAN_STOP_TIME}", scan_stop_time);
+ result = StringUtils.replace(result, "${SCAN_STOP_TIME}", scanStopTime);
}
}
return result;
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java
index 19483ca..c08d8b0 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java
@@ -26,9 +26,8 @@ import java.io.InputStream;
public class XmlUtil {
- public static Document getDocument(InputStream is) throws XMLStreamException, JDOMException, IOException {
- SAXBuilder builder = new SAXBuilder();
- Document doc = builder.build(is);
- return doc;
- }
+ public static Document getDocument(InputStream is) throws JDOMException, IOException {
+ SAXBuilder builder = new SAXBuilder();
+ return builder.build(is);
+ }
}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java
index d79e89d..b48287d 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/Zip.java
@@ -68,7 +68,7 @@ public class Zip {
if (directoryPath.isFile()) {
compressFile(directoryPath.getAbsolutePath());
} else {
- File listFiles[] = directoryPath.listFiles();
+ File[] listFiles = directoryPath.listFiles();
for (int i = 0; i < listFiles.length; i++)
if (listFiles[i].isFile()) {
compressFile(listFiles[i].getAbsolutePath());
@@ -80,21 +80,16 @@ public class Zip {
}
protected void compressFile(String absolutePath) throws IOException {
- try{
- compressFileCount++;
- byte byteBuf[] = new byte[2048];
- zipOutput.putNextEntry(new ZipEntry(absolutePath.substring(relativeAddrIdx)));
- FileInputStream input = new FileInputStream(absolutePath);
- try{
- for (int count = 0; (count = input.read(byteBuf, 0, byteBuf.length)) != -1; )
- zipOutput.write(byteBuf, 0, count);
- }finally{
- input.close();
- zipOutput.closeEntry();
- }
- }catch(IOException e){
- throw e;
- }
+ compressFileCount++;
+ byte[] byteBuf = new byte[2048];
+ zipOutput.putNextEntry(new ZipEntry(absolutePath.substring(relativeAddrIdx)));
+
+ try( FileInputStream input = new FileInputStream(absolutePath)){
+ for (int count = 0; (count = input.read(byteBuf, 0, byteBuf.length)) != -1; )
+ zipOutput.write(byteBuf, 0, count);
+ }finally{
+ zipOutput.closeEntry();
+ }
}
public void setCompressLevel(int level) {