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

main.zone.cogni.semanticz.shaclviz.util.Utils.kt Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package zone.cogni.semanticz.shaclviz.util

import java.io.File

/**
 * Utility functions.
 */
object Utils {

    /**
     * Loads the content of a path as a String. The path can be either:
     * - a file on the filesystem
     * - a classpath resource (if prefixed with 'classpath:') taken from the classloader of the Utils class.
     *
     * @param path the path of a classpath resource/file
     * @return the path content, or null if the path is invalid
     */
    fun loadResourceContent(path: String): String? =
        if (path.startsWith("classpath:")) {
            val resourcePath = path.removePrefix("classpath:")
            object {}.javaClass.getResourceAsStream(resourcePath)?.bufferedReader()?.use { it.readText() }
        } else {
            File(path).takeIf { it.exists() }?.readText()
        }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy