summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-15 14:44:58 -0500
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-18 13:56:01 -0500
commitc2cbc1a708ce82678e8177ca4985d5324f7d027f (patch)
treeeccd01bba58d8c1d6bf87d4315698446ce14bd59 /components
parent631c45b3426df8ed93bdf45fa1f11a68c991abb4 (diff)
Implement CBA upload through REST
Change-Id: I417254c5107f8b0031932e6a7cf0599561ee9a3c Issue-ID: CCSDK-910 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'components')
-rwxr-xr-xcomponents/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt65
1 files changed, 19 insertions, 46 deletions
diff --git a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
index ab5175de..fe7929e8 100755
--- a/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
+++ b/components/core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/utils/BluePrintArchiveUtils.kt
@@ -24,13 +24,18 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
import org.apache.commons.io.IOUtils
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
-import java.io.*
+import org.slf4j.LoggerFactory
+import java.io.BufferedInputStream
+import java.io.File
+import java.io.FileInputStream
+import java.io.IOException
import java.nio.charset.Charset
import java.util.zip.ZipFile
class BluePrintArchiveUtils {
companion object {
+ private val log = LoggerFactory.getLogger(BluePrintArchiveUtils::class.java)
fun getFileContent(fileName: String): String = runBlocking {
async {
@@ -51,50 +56,20 @@ class BluePrintArchiveUtils {
/**
* Create a new Zip from a root directory
*
- * @param directory the base directory
- * @param filename the output filename
+ * @param source the base directory
+ * @param destination the output filename
* @param absolute store absolute filepath (from directory) or only filename
* @return True if OK
*/
fun compress(source: File, destination: File, absolute: Boolean): Boolean {
- // recursive call
- val zaos: ZipArchiveOutputStream
try {
- zaos = ZipArchiveOutputStream(FileOutputStream(destination))
- } catch (e: FileNotFoundException) {
- return false
- }
-
- try {
- recurseFiles(source, source, zaos, absolute)
- } catch (e2: IOException) {
- try {
- zaos.close()
- } catch (e: IOException) {
- // ignore
+ ZipArchiveOutputStream(destination).use {
+ recurseFiles(source, source, it, absolute)
}
-
+ } catch (e: Exception) {
+ log.error("Fail to compress folder(:$source) to path(${destination.path}", e)
return false
}
-
- try {
- zaos.finish()
- } catch (e1: IOException) {
- // ignore
- }
-
- try {
- zaos.flush()
- } catch (e: IOException) {
- // ignore
- }
-
- try {
- zaos.close()
- } catch (e: IOException) {
- // ignore
- }
-
return true
}
@@ -113,21 +88,19 @@ class BluePrintArchiveUtils {
if (file.isDirectory) {
// recursive call
val files = file.listFiles()
- for (file2 in files!!) {
- recurseFiles(root, file2, zaos, absolute)
+ for (fileChild in files!!) {
+ recurseFiles(root, fileChild, zaos, absolute)
}
} else if (!file.name.endsWith(".zip") && !file.name.endsWith(".ZIP")) {
- var filename: String? = null
- if (absolute) {
- filename = file.absolutePath.substring(root.absolutePath.length)
+ val filename = if (absolute) {
+ file.absolutePath.substring(root.absolutePath.length)
} else {
- filename = file.name
+ file.name
}
val zae = ZipArchiveEntry(filename)
- zae.setSize(file.length())
+ zae.size = file.length()
zaos.putArchiveEntry(zae)
- val fis = FileInputStream(file)
- IOUtils.copy(fis, zaos)
+ FileInputStream(file).use { IOUtils.copy(it, zaos) }
zaos.closeArchiveEntry()
}
}