summaryrefslogtreecommitdiffstats
path: root/vnfmarket-be/vnf-sdk-marketplace/src/main
diff options
context:
space:
mode:
authorMurali Mohan Murthy Potham <murali.p@huawei.com>2017-09-18 14:15:33 +0000
committerGerrit Code Review <gerrit@onap.org>2017-09-18 14:15:33 +0000
commit7f40ddd5bcfcc753eb6a4ba0c625fc484dd76678 (patch)
tree9454d8392e032b340d8d1eab1b5b36626f52753c /vnfmarket-be/vnf-sdk-marketplace/src/main
parentb0c5f865b35158e26583e2422e02dd4dead5f208 (diff)
parentc9d59e2a08cf353ab9e4047f0b02045b5842f1a5 (diff)
Merge "fix patch 6"
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace/src/main')
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java89
1 files changed, 29 insertions, 60 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java
index e81a8bb4..1d5d46f9 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java
@@ -17,7 +17,6 @@ package org.onap.vnfsdk.marketplace.filemanage.http;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -31,6 +30,8 @@ import org.slf4j.LoggerFactory;
public class ToolUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(ToolUtil.class);
+ private ToolUtil() {
+ }
/**
* copy from directory.
* @param srcDirName source directory name
@@ -42,49 +43,36 @@ public class ToolUtil {
public static boolean copyDirectory(String srcDirName, String destDirName, boolean overlay)
throws IOException {
File srcDir = new File(srcDirName);
- if (!srcDir.exists()) {
- return false;
- } else if (!srcDir.isDirectory()) {
+ if (!srcDir.exists() || !srcDir.isDirectory()) {
return false;
}
- if (!destDirName.endsWith(File.separator)) {
- destDirName = destDirName + File.separator;
+ String useDestDirName = destDirName;
+ if (!useDestDirName.endsWith(File.separator)) {
+ useDestDirName += File.separator;
}
- File destDir = new File(destDirName);
- if (destDir.exists()) {
- if (overlay) {
+ File destDir = new File(useDestDirName);
+ if (destDir.exists() && overlay) {
new File(destDirName).delete();
- } else {
- return false;
- }
- } else {
- if (!destDir.mkdirs()) {
+ } else if ((destDir.exists() && !overlay) || (!destDir.exists() && !destDir.mkdirs())) {
return false;
- }
}
boolean flag = true;
File[] files = srcDir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
flag = copyFile(files[i].getAbsolutePath(), destDirName + files[i].getName(), true);
- if (!flag) {
- break;
- }
} else if (files[i].isDirectory()) {
flag = copyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName(), overlay);
- if (!flag) {
- break;
- }
+ }
+ if (!flag) {
+ String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!";
+ LOGGER.error(message);
+ return false;
}
}
- if (!flag) {
- String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!";
- LOGGER.error(message);
- return false;
- } else {
- return true;
- }
+
+ return true;
}
/**
@@ -97,56 +85,36 @@ public class ToolUtil {
public static boolean copyFile(String srcFileName, String destFileName, boolean overlay) {
File srcFile = new File(srcFileName);
- if (!srcFile.exists()) {
+ if (!srcFile.exists() || !srcFile.isFile()) {
String message = "Source file : " + srcFileName + " not exist !";
LOGGER.error(message);
return false;
- } else if (!srcFile.isFile()) {
- return false;
}
File destFile = new File(destFileName);
- if (destFile.exists()) {
- if (overlay) {
+ if (destFile.exists() && overlay) {
new File(destFileName).delete();
- }
- } else {
- if (!destFile.getParentFile().exists()) {
- if (!destFile.getParentFile().mkdirs()) {
- return false;
- }
- }
+ } else if (!destFile.exists() && !destFile.getParentFile().exists() && !destFile.getParentFile().mkdirs()) {
+ return false;
}
int byteread = 0;
- InputStream in = null;
- OutputStream out = null;
- try {
- in = new FileInputStream(srcFile);
- out = new FileOutputStream(destFile);
+ try (
+ InputStream in = new FileInputStream(srcFile);
+ OutputStream out = new FileOutputStream(destFile);
+ ) {
byte[] buffer = new byte[1024];
while ((byteread = in.read(buffer)) != -1) {
out.write(buffer, 0, byteread);
}
return true;
- } catch (FileNotFoundException e1) {
+ } catch (IOException e) {
+ LOGGER.error("IOException in copyFile", e);
return false;
- } catch (IOException e1) {
- return false;
- } finally {
- try {
- if (out != null) {
- out.close();
- }
- if (in != null) {
- in.close();
- }
- } catch (IOException e1) {
- e1.printStackTrace();
- }
}
+
}
/**
@@ -188,9 +156,10 @@ public class ToolUtil {
}
return dir.delete();
}
-
+
public static String getAppDeployPath()
{
return Thread.currentThread().getContextClassLoader().getResource("/").getPath();
}
}
+