summaryrefslogtreecommitdiffstats
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
commitbece50a90f6510f0ec3d109ff4dc4a9257881ac1 (patch)
tree5697c92b1a0473cf0781bcfe71753d2dff1837bf
parentafa5c2df6c53dfce43c72c05457ec5a108ae0ed7 (diff)
Implement CBA upload through REST
Change-Id: I417254c5107f8b0031932e6a7cf0599561ee9a3c Issue-ID: CCSDK-910 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
-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 ab5175dea..fe7929e85 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()
}
}