summaryrefslogtreecommitdiffstats
path: root/juju/juju-vnfmadapter/Juju-vnfmadapterService
diff options
context:
space:
mode:
authorYan Yang <yangyanyj@chinamobile.com>2018-03-23 10:15:37 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-23 10:15:37 +0000
commitfb06c0c6c1708c1ded6f2ed842a6f4625d734ed6 (patch)
treec75dde4ed7a45c5c088a3f162441737997960d0a /juju/juju-vnfmadapter/Juju-vnfmadapterService
parent93f8b864339de0840906f53d854af9a10213e8ce (diff)
parent3ea75d14ed929390326dae4a43fff5965d8c161e (diff)
Merge "Code Smells in jujuvnfmadapter utils"
Diffstat (limited to 'juju/juju-vnfmadapter/Juju-vnfmadapterService')
-rw-r--r--juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java31
-rw-r--r--juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java2
-rw-r--r--juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java16
-rw-r--r--juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java7
-rw-r--r--juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java9
-rw-r--r--juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java35
6 files changed, 29 insertions, 71 deletions
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java
index d246705..a7cdf1e 100644
--- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java
+++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java
@@ -19,10 +19,7 @@ package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
@@ -41,8 +38,6 @@ import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
/**
* Utility class to download CSAR
@@ -100,8 +95,6 @@ public class DownloadCsarManager {
}
}
is.close();
- //fileout.flush();
- //fileout.close();
status = Constant.DOWNLOADCSAR_SUCCESS;
} catch (Exception e) {
@@ -168,10 +161,8 @@ public class DownloadCsarManager {
public static int unzipCSAR(String fileName,String filePath){
final int BUFFER = 2048;
int status=0;
-
- try ( ZipFile zipFile = new ZipFile(fileName)){
+ try (ZipFile zipFile = new ZipFile(fileName)){
Enumeration emu = zipFile.entries();
- int i=0;
while(emu.hasMoreElements()){
ZipEntry entry = (ZipEntry)emu.nextElement();
//read directory as file first,so only need to create directory
@@ -189,17 +180,14 @@ public class DownloadCsarManager {
parent.mkdirs();
}
try(FileOutputStream fos = new FileOutputStream(file);
- BufferedOutputStream bos = new BufferedOutputStream(fos,BUFFER)){
-
- int count;
- byte data[] = new byte[BUFFER];
- while ((count = bis.read(data, 0, BUFFER)) != -1)
- {
- bos.write(data, 0, count);
- }
+ BufferedOutputStream bos = new BufferedOutputStream(fos,BUFFER)){
+ int count;
+ byte[] data = new byte[BUFFER];
+ while ((count = bis.read(data, 0, BUFFER)) != -1)
+ {
+ bos.write(data, 0, count);
+ }
}
- //bos.flush();
- //bos.close();
bis.close();
if(entry.getName().endsWith(".zip")){
@@ -218,7 +206,6 @@ public class DownloadCsarManager {
zipFile.close();
} catch (Exception e) {
status=Constant.UNZIP_FAIL;
- //e.printStackTrace();
LOG.error("unzipCSAR Exception: ",e);
}
@@ -238,6 +225,6 @@ public class DownloadCsarManager {
return csarfilepath;
}
public static void main(String[] args) {
- System.out.println(getImagesPath("e:/juju/csar2/"));
+ LOG.info("AbsolutePath: " + getImagesPath("e:/juju/csar2/"));
}
}
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java
index 6b4c2cb..1cb803c 100644
--- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java
+++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java
index 357f2c5..3a8bc5c 100644
--- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java
+++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java
@@ -241,10 +241,10 @@ public class FileUtils {
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) {
- if (flag == false) {
+ if (!flag) {
delFiles(newPath);
}
- if (new File(newPath).exists() && flag == true) {
+ if (new File(newPath).exists() && flag) {
return;
}
newFile(newPath);
@@ -255,8 +255,6 @@ public class FileUtils {
fos.write(buffer, 0, byteread);
}
}
- //fos.close();
- //fis.close();
} else {
throw new FileNotFoundException("the " + oldfile + " is not exits ");
}
@@ -278,12 +276,12 @@ public class FileUtils {
return true;
if (myDelFile.isDirectory()) {
File[] fs = myDelFile.listFiles();
- for (int i = 0; i < fs.length; i++) {
+ for (int i = 0; i < fs.length; i++) {//no need to assign
if (fs[i].isFile())
- flag = fs[i].delete();
+ fs[i].delete();
if (fs[i].isDirectory()) {
- flag = delFiles(fs[i].getAbsolutePath());
- flag = fs[i].delete();
+ delFiles(fs[i].getAbsolutePath());
+ fs[i].delete();
}
}
}
@@ -317,7 +315,7 @@ public class FileUtils {
* */
public static List<File> getFiles(String path) {
- List<File> list = new ArrayList<File>();
+ List<File> list = new ArrayList<>();
File file = new File(path);
if (!file.exists()) {
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java
index 9cb8833..7cf6418 100644
--- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java
+++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright 2016 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,13 +38,12 @@ import org.slf4j.LoggerFactory;
* @version NFVO 0.5 Sep 19, 2016
*/
public class LocalComandUtils {
+ private static final Logger log = LoggerFactory.getLogger(LocalComandUtils.class);
+
private LocalComandUtils(){
}
- private static final Logger log = LoggerFactory.getLogger(LocalComandUtils.class);
-
-
/**
* <br>
*
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java
index 308adb2..f2098fc 100644
--- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java
+++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java
@@ -1,4 +1,4 @@
-/*
+/**
* Copyright (c) 2016, Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -51,9 +50,9 @@ public class UnCompressUtil {
private static Logger log = LoggerFactory.getLogger(UnCompressUtil.class);
- private static Map<String, String> archiveMap = new HashMap<String, String>();
+ private static Map<String, String> archiveMap = new HashMap<>();
- private static Map<String, String> compressorMap = new HashMap<String, String>();
+ private static Map<String, String> compressorMap = new HashMap<>();
static {
// archive type
@@ -160,7 +159,7 @@ public class UnCompressUtil {
FileUtils.mkDirs(fileName);
} else {
int count;
- byte data[] = new byte[2048];
+ byte[] data = new byte[2048];
File file = getRealFileName(targetPath, name);
fileNames.add(file.getName());
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java
index fa0344c..685785f 100644
--- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java
+++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java
@@ -79,41 +79,16 @@ public class RestHttpContentExchange extends ContentExchange {
if(data == null) {
return "";
}
- ByteArrayInputStream input = null;
- GZIPInputStream gzis = null;
- InputStreamReader reader = null;
final StringBuilder out = new StringBuilder();
- try {
- input = new ByteArrayInputStream(data);
- gzis = new GZIPInputStream(input);
- reader = new InputStreamReader(gzis, Charset.forName(RestfulClientConst.ENCODING));
+ try (
+ ByteArrayInputStream input = new ByteArrayInputStream(data);
+ GZIPInputStream gzis = new GZIPInputStream(input);
+ InputStreamReader reader = new InputStreamReader(gzis, Charset.forName(RestfulClientConst.ENCODING))){
final char[] buff = new char[1024];
for(int n; (n = reader.read(buff)) != -1;) {
out.append(new String(buff, 0, n));
}
- } finally {
- if(reader != null) {
- try {
- reader.close();
- } catch(final IOException e) {
- LOGGER.error("decompress Gzip reader exception:", e);
- }
- }
- if(gzis != null) {
- try {
- gzis.close();
- } catch(final IOException e) {
- LOGGER.error("decompress Gzip exception:", e);
- }
- }
- if(input != null) {
- try {
- input.close();
- } catch(final IOException e) {
- LOGGER.error("decompress Gzip input exception:", e);
- }
- }
- }
+ }
return out.toString();
}