All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.codecentric.hikaku.extensions.PathExtensions.kt Maven / Gradle / Ivy

Go to download

A library that tests if the implementation of a REST-API meets its specification. This module contains the core elements which can be used to create additional converters and reporters.

There is a newer version: 3.3.0
Show newest version
package de.codecentric.hikaku.extensions

import java.nio.file.Files
import java.nio.file.Path

fun Path.checkFileValidity(vararg extensions: String) {
    if (!Files.exists(this)) {
        throw IllegalArgumentException("Given file does not exist.")
    }

    if (!Files.isRegularFile(this)) {
        throw IllegalArgumentException("Given file is not a regular file.")
    }

    if (extensions.isNotEmpty()) {
        extensions.filter {
            this.fileName.toString().endsWith(it)
        }
        .ifEmpty {
            throw IllegalArgumentException("Given file is not of type ${extensions.joinToString()}")
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy