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

jvmMain.io.github.lyxnx.util.Properties.kt Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
package io.github.lyxnx.util

import java.io.File
import java.nio.charset.Charset
import java.nio.file.Path
import java.util.Properties
import kotlin.io.path.bufferedReader
import kotlin.io.path.reader

// These functions can be synthetic and Java callers can use PropertiesUtil functions

/**
 * Convenience function to load properties from a string
 *
 * @see Properties.load
 */
@JvmSynthetic
public fun Properties.load(string: String): Properties = apply {
    string.reader().use(::load)
}

/**
 * Convenience function to load properties from a file using the given [charset] and [bufferSize]
 *
 * If [bufferSize] is less than or equal to 0, the file will be read into a normal reader, without buffering
 */
@JvmSynthetic
public fun Properties.load(
    file: File,
    charset: Charset = Charsets.UTF_8,
    bufferSize: Int = DEFAULT_BUFFER_SIZE
): Properties = apply {
    (if (bufferSize <= 0) file.reader(charset) else file.bufferedReader(charset, bufferSize)).use(::load)
}

/**
 * Convenience function to load properties from a path using the given [charset] and [bufferSize]
 *
 * If [bufferSize] is less than or equal to 0, the file will be read into a normal reader, without buffering
 */
@JvmSynthetic
public fun Properties.load(
    path: Path,
    charset: Charset = Charsets.UTF_8,
    bufferSize: Int = DEFAULT_BUFFER_SIZE
): Properties = apply {
    (if (bufferSize <= 0) path.reader(charset) else path.bufferedReader(charset, bufferSize)).use(::load)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy