2  *  Copyright © 2019 IBM.
 
   4  *  Licensed under the Apache License, Version 2.0 (the "License");
 
   5  *  you may not use this file except in compliance with the License.
 
   6  *  You may obtain a copy of the License at
 
   8  *      http://www.apache.org/licenses/LICENSE-2.0
 
  10  *  Unless required by applicable law or agreed to in writing, software
 
  11  *  distributed under the License is distributed on an "AS IS" BASIS,
 
  12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13  *  See the License for the specific language governing permissions and
 
  14  *  limitations under the License.
 
  17 package org.onap.ccsdk.apps.controllerblueprints.core
 
  19 import org.apache.commons.io.FileUtils
 
  20 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
 
  22 import java.io.InputStream
 
  23 import java.nio.file.Paths
 
  25 fun InputStream.toFile(path: String): File {
 
  27     file.outputStream().use { this.copyTo(it) }
 
  31 fun File.reCreateDirs(): File {
 
  33         this.deleteRecursively()
 
  36     FileUtils.forceMkdir(this)
 
  37     check(this.exists()) {
 
  38         throw BluePrintException("failed to re create dir(${this.absolutePath})")
 
  43 fun File.compress(targetZipFileName: String): File {
 
  44     return this.compress(Paths.get(targetZipFileName).toFile())
 
  48  * Compress the current Dir to the target zip file and return the target zip file
 
  50 fun File.compress(targetZipFile: File): File {
 
  51     BluePrintArchiveUtils.compress(this, targetZipFile, true)
 
  55 fun File.deCompress(targetFileName: String): File {
 
  56     return this.deCompress(Paths.get(targetFileName).toFile())
 
  60  * De-Compress the current zip file to the target file and return the target file
 
  62 fun File.deCompress(targetFile: File): File {
 
  63     BluePrintArchiveUtils.deCompress(this, targetFile.path)
 
  67 fun deleteDir(path: String) {
 
  68     Paths.get(path).toFile().deleteRecursively()
 
  72 fun normalizedFile(path: String): File {
 
  73     return Paths.get(path).toFile().normalize()