diff options
author | 2017-09-21 19:35:35 +0800 | |
---|---|---|
committer | 2017-09-21 19:37:10 +0800 | |
commit | 8926c547cb3c9b07df87c6f31fda5d43b5ae76a4 (patch) | |
tree | 73290c232ae14c5c44b97386af560f2efebbbd9d /vnfmarket-be/vnf-sdk-marketplace | |
parent | fc3837b1068fae21923f7be29ee67121595f14c2 (diff) |
split function into smaller ones
major: L43 L85
Change-Id: Ide232d40c493c009358c0e84aea65e6829fb6c33
Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
Issue-Id: VNFSDK-85
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace')
-rw-r--r-- | vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/filemanage/http/ToolUtil.java | 88 |
1 files changed, 58 insertions, 30 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 1d5d46f9..432ee219 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 @@ -32,6 +32,36 @@ public class ToolUtil { private ToolUtil() { } + + /** + * copy in directory. + * @param srcDirName source directory name + * @param destDirName destination directory name + * @param files file list in directory + * @param overlay overwrite or not + * @return boolean + * @throws IOException e + */ + public static boolean copyInDirectory(String srcDirName, String destDirName, File[] files, boolean overlay) + throws IOException + { + for (int i = 0; i < files.length; i++) { + boolean flag = false; + if (files[i].isFile()) { + flag = copyFile(files[i].getAbsolutePath(), destDirName + files[i].getName(), true); + } + if (files[i].isDirectory()) { + flag = copyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName(), overlay); + } + if (!flag) { + String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!"; + LOGGER.error(message); + return false; + } + } + return true; + } + /** * copy from directory. * @param srcDirName source directory name @@ -57,22 +87,36 @@ public class ToolUtil { } 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); - } else if (files[i].isDirectory()) { - flag = copyDirectory(files[i].getAbsolutePath(), destDirName + files[i].getName(), overlay); - } - if (!flag) { - String message = "Copy catagory " + srcDirName + " to " + destDirName + " failed!"; - LOGGER.error(message); - return false; + + return copyInDirectory(srcDirName, destDirName, files, overlay); + } + + /** + * copy byte. + * @param srcFileName source file name + * @param destFileName target file name + * @return boolean + */ + public static boolean copyByte(File srcFile, File destFile) + { + try ( + InputStream in = new FileInputStream(srcFile); + OutputStream out = new FileOutputStream(destFile); + ) { + + byte[] buffer = new byte[1024]; + int byteread = 0; + + while ((byteread = in.read(buffer)) != -1) { + out.write(buffer, 0, byteread); } + return true; + } catch (IOException e) { + LOGGER.error("IOException in copyFile", e); + return false; } - - return true; } /** @@ -98,23 +142,7 @@ public class ToolUtil { return false; } - int byteread = 0; - - 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 (IOException e) { - LOGGER.error("IOException in copyFile", e); - return false; - } - + return copyByte(srcFile, destFile); } /** |