diff options
author | andre.schmid <andre.schmid@est.tech> | 2019-09-19 16:14:01 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-11-03 15:41:37 +0000 |
commit | 433947b5ab5e28fc29aee447de934de89a707419 (patch) | |
tree | a485b95b2ae7716ced4825fb7b9eb2b6eeb3433b /openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java | |
parent | ee64a64fb0705422c18608304e63a505d10d8ba1 (diff) |
Centralize onboarding package validation
Change-Id: I3cc58cf15f62008e83cfc7ddb095d07ab216b82a
Issue-ID: SDC-2583
Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java')
-rw-r--r-- | openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java index 31338dcda4..f69a2a060a 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java @@ -229,9 +229,15 @@ public class FileUtils { public static FileContentHandler getFileContentMapFromZip(byte[] zipData) throws ZipException { final Map<String, byte[]> zipFileAndByteMap = ZipUtils.readZip(zipData, true); - final FileContentHandler mapFileContent = new FileContentHandler(); - mapFileContent.setFiles(zipFileAndByteMap); - return mapFileContent; + final FileContentHandler fileContentHandler = new FileContentHandler(); + zipFileAndByteMap.forEach((path, bytes) -> { + if (bytes == null) { + fileContentHandler.addFolder(path); + } else { + fileContentHandler.addFile(path, bytes); + } + }); + return fileContentHandler; } @@ -280,24 +286,23 @@ public class FileUtils { */ public static Map<String, String> writeFilesFromFileContentHandler(final FileContentHandler fileContentHandler, final Path dir) throws IOException { - File file; final File dirFile = dir.toFile(); final Map<String, String> filePaths = new HashMap<>(); + File file; + for (final String folderPath : fileContentHandler.getFolderList()) { + file = new File(dirFile, folderPath); + filePaths.put(folderPath, file.getAbsolutePath()); + if (!file.exists() && !file.mkdirs()) { + throw new IOException("Could not create directory " + file.getAbsolutePath()); + } + } for (final Map.Entry<String, byte[]> fileEntry : fileContentHandler.getFiles().entrySet()) { file = new File(dirFile, fileEntry.getKey()); filePaths.put(fileEntry.getKey(), file.getAbsolutePath()); final byte[] fileBytes = fileEntry.getValue(); - if (fileBytes == null) { - if (!file.exists() && !file.mkdirs()) { - throw new IOException("Could not create directory " + file.getAbsolutePath()); - } - continue; - } else { - if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { - throw new IOException("Could not create parent directory for " + file.getAbsolutePath()); - } + if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { + throw new IOException("Could not create parent directory for " + file.getAbsolutePath()); } - try (final FileOutputStream fop = new FileOutputStream(file.getAbsolutePath());) { fop.write(fileBytes); fop.flush(); |