aboutsummaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt
diff options
context:
space:
mode:
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt')
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt74
1 files changed, 74 insertions, 0 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt
new file mode 100644
index 00000000..a433a31b
--- /dev/null
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/FileExtensionFunctions.kt
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.core
+
+import org.apache.commons.io.FileUtils
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
+import java.io.File
+import java.io.InputStream
+import java.nio.file.Paths
+
+fun InputStream.toFile(path: String): File {
+ val file = File(path)
+ file.outputStream().use { this.copyTo(it) }
+ return file
+}
+
+fun File.reCreateDirs(): File {
+ if (this.exists()) {
+ this.deleteRecursively()
+ }
+ // this.mkdirs()
+ FileUtils.forceMkdir(this)
+ check(this.exists()) {
+ throw BluePrintException("failed to re create dir(${this.absolutePath})")
+ }
+ return this
+}
+
+fun File.compress(targetZipFileName: String): File {
+ return this.compress(Paths.get(targetZipFileName).toFile())
+}
+
+/**
+ * Compress the current Dir to the target zip file and return the target zip file
+ */
+fun File.compress(targetZipFile: File): File {
+ BluePrintArchiveUtils.compress(this, targetZipFile, true)
+ return targetZipFile
+}
+
+fun File.deCompress(targetFileName: String): File {
+ return this.deCompress(Paths.get(targetFileName).toFile())
+}
+
+/**
+ * De-Compress the current zip file to the target file and return the target file
+ */
+fun File.deCompress(targetFile: File): File {
+ BluePrintArchiveUtils.deCompress(this, targetFile.path)
+ return targetFile
+}
+
+fun deleteDir(path: String) {
+ Paths.get(path).toFile().deleteRecursively()
+}
+
+
+fun normalizedFile(path: String): File {
+ return Paths.get(path).toFile().normalize()
+}