Package-level declarations

Platform information and other useful utilities. Includes basic program settings support at the Platform object (like loading and retrieving system settings).

Provides a logging management capabilities abstracting the application from logging libraries.

The following code block shows the most common use cases for the logging utilities:

Types

Link copied to clipboard
object ClasspathHandler : URLStreamHandler
Link copied to clipboard
class CodedException(val code: Int, message: String = "", cause: Throwable? = null) : RuntimeException

Exception with a numeric code.

Link copied to clipboard
class MultipleException(val causes: List<Throwable>, message: String = "") : RuntimeException

Exception with a list of causes. Cause is null as it can't be told which one of the list is the cause.

Link copied to clipboard
enum OsKind : Enum<OsKind>
Link copied to clipboard
object Platform

Object with utilities to gather information about the running platform.

Link copied to clipboard
class ResourceNotFoundException(message: String) : IOException

Properties

Link copied to clipboard
val ALL_INTERFACES: InetAddress

Internet address used to bind services to all local network interfaces.

Link copied to clipboard
val assertEnabled: Boolean

This flag is true when assertions are enabled in the JVM (-ea flag). Assertions are disabled by default in the JVM, but they are enabled (and should be that way) on the tests.

Link copied to clipboard
val fail: Nothing

Syntax sugar to throw errors.

Link copied to clipboard
val GMT_ZONE: ZoneId

GMT zone ID.

Link copied to clipboard
val logger: System.Logger

Default logger for when you feel too lazy to declare one.

Link copied to clipboard
val LOOPBACK_INTERFACE: InetAddress

Internet address used to bind services to the loop-back interface.

Functions

Link copied to clipboard
fun <T> T.debug(prefix: String = ""): T

Use this T to log a message with a prefix using DEBUG level.

fun System.Logger.debug(message: () -> Any?)

Log a message using DEBUG level.

Link copied to clipboard
fun System.Logger.error(message: () -> Any?)

Log a message using ERROR level.

fun <E : Throwable> System.Logger.error(exception: E?, message: (E?) -> Any? = { "" })

Log a message using ERROR level with associated exception information.

Link copied to clipboard
fun URL.exists(): Boolean
Link copied to clipboard
fun <T : Any> fieldsMapOf(vararg fields: Pair<KProperty1<T, *>, *>): Map<String, *>
Link copied to clipboard
fun <T : Any> fieldsMapOfNotNull(vararg fields: Pair<KProperty1<T, *>, *>): Map<String, *>
Link copied to clipboard
fun <V> Collection<V?>.filterNotEmpty(): Collection<V>
fun <K, V> Map<K, V?>.filterNotEmpty(): Map<K, V>
Link copied to clipboard
fun Collection<*>.filterNotEmptyRecursive(): Collection<*>
fun Map<*, *>.filterNotEmptyRecursive(): Map<*, *>
Link copied to clipboard
fun Throwable.filterStackTrace(prefix: String): Array<out StackTraceElement>

Return the stack trace array of the frames that starts with the given prefix.

Link copied to clipboard
fun URL.firstVariant(vararg suffixes: String): URL
Link copied to clipboard
fun freePort(): Int

Return a random free port (not used by any other local process).

Link copied to clipboard
inline operator fun <T : Any> Map<*, *>.get(key: KProperty1<*, *>): T?
Link copied to clipboard
fun Map<*, *>.getBoolean(key: KProperty1<*, *>): Boolean?
Link copied to clipboard
fun Map<*, *>.getBooleans(key: KProperty1<*, *>): Collection<Boolean>?
Link copied to clipboard
fun Map<*, *>.getBooleansOrEmpty(key: KProperty1<*, *>): Collection<Boolean>
Link copied to clipboard
fun Map<*, *>.getDouble(key: KProperty1<*, *>): Double?
Link copied to clipboard
fun Map<*, *>.getDoubles(key: KProperty1<*, *>): Collection<Double>?
Link copied to clipboard
fun Map<*, *>.getDoublesOrEmpty(key: KProperty1<*, *>): Collection<Double>
Link copied to clipboard
fun Map<*, *>.getFloat(key: KProperty1<*, *>): Float?
Link copied to clipboard
fun Map<*, *>.getFloats(key: KProperty1<*, *>): Collection<Float>?
Link copied to clipboard
fun Map<*, *>.getFloatsOrEmpty(key: KProperty1<*, *>): Collection<Float>
Link copied to clipboard
fun Map<*, *>.getInt(key: KProperty1<*, *>): Int?
Link copied to clipboard
fun Map<*, *>.getInts(key: KProperty1<*, *>): Collection<Int>?
Link copied to clipboard
fun Map<*, *>.getIntsOrEmpty(key: KProperty1<*, *>): Collection<Int>
Link copied to clipboard
fun Map<*, *>.getList(key: KProperty1<*, *>): Collection<*>?
Link copied to clipboard
fun Map<*, *>.getListOrEmpty(key: KProperty1<*, *>): Collection<*>
Link copied to clipboard
fun Map<*, *>.getLists(key: KProperty1<*, *>): Collection<List<*>>?
Link copied to clipboard
fun Map<*, *>.getListsOrEmpty(key: KProperty1<*, *>): Collection<Collection<*>>
Link copied to clipboard
fun Map<*, *>.getLong(key: KProperty1<*, *>): Long?
Link copied to clipboard
fun Map<*, *>.getLongs(key: KProperty1<*, *>): Collection<Long>?
Link copied to clipboard
fun Map<*, *>.getLongsOrEmpty(key: KProperty1<*, *>): Collection<Long>
Link copied to clipboard
fun Map<*, *>.getMap(key: KProperty1<*, *>): Map<String, *>?
Link copied to clipboard
fun Map<*, *>.getMapOrEmpty(key: KProperty1<*, *>): Map<String, *>
Link copied to clipboard
fun Map<*, *>.getMaps(key: KProperty1<*, *>): Collection<Map<String, *>>?
Link copied to clipboard
fun Map<*, *>.getMapsOrEmpty(key: KProperty1<*, *>): Collection<Map<String, *>>
Link copied to clipboard
inline fun <T : Any> Map<*, *>.getOrDefault(key: KProperty1<*, *>, default: T): T
Link copied to clipboard
inline fun <T : Any> Map<*, *>.getPath(vararg keys: Any): T?
Link copied to clipboard
fun Map<*, *>.getString(key: KProperty1<*, *>): String?
Link copied to clipboard
fun Map<*, *>.getStrings(key: KProperty1<*, *>): Collection<String>?
Link copied to clipboard
fun Map<*, *>.getStringsOrEmpty(key: KProperty1<*, *>): Collection<String>
Link copied to clipboard
fun inetAddress(vararg bytes: Byte): InetAddress

Syntactic sugar to create an Internet address.

Link copied to clipboard
fun <T> T.info(prefix: String = ""): T

Use this T to log a message with a prefix using INFO level.

fun System.Logger.info(message: () -> Any?)

Log a message using INFO level.

Link copied to clipboard
fun isPortOpened(port: Int): Boolean

Check if a port is already opened.

Link copied to clipboard
fun URL.localized(locale: Locale): URL
Link copied to clipboard
fun <E : Throwable> System.Logger.log(level: System.Logger.Level, exception: E, message: (E) -> Any?)

Log a message, with associated exception information.

Link copied to clipboard
fun loggerOf(name: String): System.Logger
fun loggerOf(type: KClass<*>): System.Logger

Logger constructor function.

Link copied to clipboard
fun <K : Any> mapOfNotNull(vararg pairs: Pair<K, *>): Map<K, *>
Link copied to clipboard
fun merge(maps: Collection<Map<*, *>>): Map<*, *>
fun merge(mapA: Map<*, *>, mapB: Map<*, *>): Map<*, *>
Link copied to clipboard
fun <V> notEmpty(value: V?): Boolean
Link copied to clipboard
fun <K, V> Map<K, Collection<V>>.pairs(): Collection<Pair<K, V>>
Link copied to clipboard
fun parseDuration(text: String): Duration

Parse a time duration allowing a more relaxed format: with spaces or commas, lowercase characters and not forcing the text to start with 'P', however, the 'T' is still mandatory to separate date and time durations.

Link copied to clipboard
fun parseLocalDate(text: String): LocalDate

Parse a local date allowing only to specify the year or the year and the month. Missing month and day will be defaulted to january and one respectively.

Link copied to clipboard
fun parsePeriod(text: String): Period

Parse a time period allowing a more relaxed format: with spaces or commas, lowercase characters and not forcing the text to start with 'P'.

Link copied to clipboard
fun <K, V> Map<K, V>.require(name: K): V
Link copied to clipboard
fun Map<*, *>.requireBoolean(key: KProperty1<*, *>): Boolean
Link copied to clipboard
fun Map<*, *>.requireBooleans(key: KProperty1<*, *>): Collection<Boolean>
Link copied to clipboard
fun Map<*, *>.requireDouble(key: KProperty1<*, *>): Double
Link copied to clipboard
fun Map<*, *>.requireDoubles(key: KProperty1<*, *>): Collection<Double>
Link copied to clipboard
fun Map<*, *>.requireFloat(key: KProperty1<*, *>): Float
Link copied to clipboard
fun Map<*, *>.requireFloats(key: KProperty1<*, *>): Collection<Float>
Link copied to clipboard
fun Map<*, *>.requireInt(key: KProperty1<*, *>): Int
Link copied to clipboard
fun Map<*, *>.requireInts(key: KProperty1<*, *>): List<Int>
Link copied to clipboard
inline fun <T : Any> Map<*, *>.requireKey(key: KProperty1<*, *>): T
Link copied to clipboard
fun Map<*, *>.requireList(key: KProperty1<*, *>): Collection<*>
Link copied to clipboard
fun Map<*, *>.requireLists(key: KProperty1<*, *>): Collection<Collection<*>>
Link copied to clipboard
fun Map<*, *>.requireLong(key: KProperty1<*, *>): Long
Link copied to clipboard
fun Map<*, *>.requireLongs(key: KProperty1<*, *>): Collection<Long>
Link copied to clipboard
fun Map<*, *>.requireMap(key: KProperty1<*, *>): Map<String, *>
Link copied to clipboard
fun Map<*, *>.requireMaps(key: KProperty1<*, *>): Collection<Map<String, *>>
Link copied to clipboard
inline fun <T : Any> Map<*, *>.requirePath(vararg name: Any): T
Link copied to clipboard
fun Map<*, *>.requireString(key: KProperty1<*, *>): String
Link copied to clipboard
fun Map<*, *>.requireStrings(key: KProperty1<*, *>): Collection<String>
Link copied to clipboard
fun URL.responseCode(): Int
Link copied to clipboard
fun URL.responseFound(): Boolean
Link copied to clipboard
fun URL.responseSuccessful(): Boolean
Link copied to clipboard
fun LocalDate.toDate(): Date

Convert a local date to a date.

fun LocalDateTime.toDate(): Date

Convert a local date time to a date.

fun ZonedDateTime.toDate(): Date

Convert a zoned date time to a date.

Link copied to clipboard
fun Date.toLocalDate(): LocalDate

Convert a date to a local date.

Link copied to clipboard
fun Date.toLocalDateTime(): LocalDateTime

Convert a date to a local date time.

Link copied to clipboard
fun Throwable.toText(prefix: String = ""): String

Return this throwable as a text.

Link copied to clipboard
fun Period.toTotalDays(): Double

Calculate the aproximate number of days comprised in a time period.

Link copied to clipboard
fun <T> T.trace(prefix: String = ""): T

Use this T to log a message with a prefix using TRACE level.

fun System.Logger.trace(message: () -> Any?)

Log a message using TRACE level.

Link copied to clipboard
fun urlOf(url: String): URL
Link copied to clipboard
fun System.Logger.warn(message: () -> Any?)

Log a message using WARNING level.

fun <E : Throwable> System.Logger.warn(exception: E?, message: (E?) -> Any? = { "" })

Log a message using WARNING level with associated exception information.

Link copied to clipboard
fun LocalDateTime.withZone(zoneId: ZoneId = Platform.timeZone.toZoneId()): ZonedDateTime

Return the date time in a given time zone for a local date time.