CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-ktor--ktor-utils-jvm

Ktor utilities library for JVM platform containing common utility functions, cryptographic operations, date handling, logging utilities, pipeline functionality, I/O adapters, encoding/decoding utilities, network address handling, and various platform-specific implementations for the Ktor framework.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Ktor Utils JVM

Ktor Utils JVM is a comprehensive utility library for the Ktor asynchronous web framework, providing essential functionality for cryptographic operations, date handling, platform-specific utilities, logging infrastructure, pipeline processing, I/O operations, network address handling, and various collection utilities. It serves as a foundational component for Ktor applications running on the JVM platform.

Package Information

  • Package Name: ktor-utils-jvm
  • Package Type: maven
  • Language: Kotlin
  • Installation: Add to your Gradle build file:
    implementation("io.ktor:ktor-utils-jvm:3.2.0")

Core Imports

import io.ktor.util.*
import io.ktor.util.pipeline.*
import io.ktor.util.logging.*
import io.ktor.util.date.*
import io.ktor.util.collections.*

Basic Usage

import io.ktor.util.*
import io.ktor.util.pipeline.*

// Create attributes for type-safe storage
val key = AttributeKey<String>("example")
val attributes = Attributes()
attributes.put(key, "value")

// Base64 encoding/decoding
val encoded = "Hello World".encodeBase64()
val decoded = encoded.decodeBase64String()

// Pipeline execution
val pipeline = Pipeline<String, Unit>()
pipeline.execute(Unit, "subject")

// Network address handling
val address = NetworkAddress("localhost", 8080)

Architecture

Ktor Utils JVM is organized around several key architectural components:

  • Attributes System: Type-safe attribute storage with generic keys for storing contextual data across different parts of the application
  • Pipeline Framework: Asynchronous execution pipeline with configurable phases and interceptors for request/response processing
  • Cryptographic Utilities: Thread-safe implementations of common cryptographic operations including hashing, encoding, and nonce generation
  • I/O Abstractions: Efficient I/O handling through NIO and channel-based operations with platform-specific optimizations
  • Collection Extensions: Case-insensitive maps, concurrent collections, and other specialized data structures
  • Logging Infrastructure: Structured logging with multiple levels and lazy evaluation for performance
  • Date and Time Handling: GMT-based date operations with HTTP date format support
  • Platform Utilities: JVM-specific implementations and platform detection capabilities

Capabilities

Attributes & Type System

Type-safe attribute storage system for associating typed values with keys across application contexts.

data class AttributeKey<T : Any>(val name: String, private val type: TypeInfo = typeInfo<Any>())

interface Attributes {
    fun <T : Any> get(key: AttributeKey<T>): T
    fun <T : Any> getOrNull(key: AttributeKey<T>): T?
    fun <T : Any> put(key: AttributeKey<T>, value: T)
    fun <T : Any> remove(key: AttributeKey<T>)
    fun <T : Any> computeIfAbsent(key: AttributeKey<T>, block: () -> T): T
    val allKeys: List<AttributeKey<*>>
}

fun Attributes(concurrent: Boolean = false): Attributes

Attributes & Type System

Cryptography & Encoding

Cryptographic operations, encoding/decoding utilities, and secure random generation.

fun String.encodeBase64(): String
fun ByteArray.encodeBase64(): String
fun String.decodeBase64String(): String
fun String.decodeBase64Bytes(): ByteArray

fun hex(bytes: ByteArray): String
fun hex(s: String): ByteArray
fun sha1(bytes: ByteArray): ByteArray
fun generateNonce(): String

Cryptography & Encoding

String & Text Processing

String handling utilities including case-insensitive operations and HTML processing.

interface StringValues {
    val caseInsensitiveName: Boolean
    operator fun get(name: String): String?
    fun getAll(name: String): List<String>?
    fun names(): Set<String>
    fun entries(): Set<Map.Entry<String, List<String>>>
    operator fun contains(name: String): Boolean
    fun isEmpty(): Boolean
}

interface StringValuesBuilder {
    operator fun set(name: String, value: String)
    fun append(name: String, value: String)
    fun appendAll(stringValues: StringValues)
    fun remove(name: String)
    fun build(): StringValues
}

fun valuesOf(vararg pairs: Pair<String, List<String>>, caseInsensitiveKey: Boolean = false): StringValues
fun String.escapeHTML(): String

String & Text Processing

Collections & Data Structures

Specialized collection types including case-insensitive maps, concurrent collections, and caching utilities.

fun <V> caseInsensitiveMap(): MutableMap<String, V>
fun caseInsensitiveSet(): MutableSet<String>

interface ConcurrentMap<K, V> : MutableMap<K, V>
class CopyOnWriteHashMap<K, V> : MutableMap<K, V>
class LRUCache<K, V>(val maxSize: Int) : MutableMap<K, V>

Collections & Data Structures

Pipeline System

Asynchronous execution pipeline with configurable phases for request/response processing.

open class Pipeline<TSubject : Any, TContext : Any>(vararg phases: PipelinePhase) {
    val attributes: Attributes
    val developmentMode: Boolean
    val isEmpty: Boolean
    
    suspend fun execute(context: TContext, subject: TSubject): TSubject
    fun addPhase(phase: PipelinePhase)
    fun intercept(phase: PipelinePhase, block: PipelineInterceptor<TSubject, TContext>)
}

class PipelinePhase(val name: String)
class PipelineContext<TSubject : Any, TContext : Any>

typealias PipelineInterceptor<TSubject, TContext> = suspend PipelineContext<TSubject, TContext>.(TSubject) -> Unit

Pipeline System

I/O & Networking

Network address handling, file channel operations, and stream adapters for efficient I/O.

typealias NetworkAddress = java.net.SocketAddress
fun NetworkAddress(hostname: String, port: Int): NetworkAddress
val NetworkAddress.hostname: String
val NetworkAddress.port: Int

// File channel operations
fun File.readChannel(): ByteReadChannel
fun File.writeChannel(append: Boolean = false): ByteWriteChannel

// Stream adapters
fun ByteReadChannel.toInputStream(): InputStream
fun ByteWriteChannel.toOutputStream(): OutputStream

// NIO utilities
fun ReadableByteChannel.readChannel(): ByteReadChannel
fun WritableByteChannel.writeChannel(): ByteWriteChannel

I/O & Networking

Data Conversion

Type conversion service with customizable converters for data transformation.

interface ConversionService {
    fun <T> fromValues(values: List<String>, type: TypeInfo): T
    fun <T> toValues(value: T?): List<String>
}

interface DataConversion {
    fun <T> convert(value: String, type: TypeInfo): T
}

Data Conversion

Date & Time

GMT date handling with HTTP date format support and timezone operations.

class GMTDate(
    val seconds: Int,
    val minutes: Int, 
    val hours: Int,
    val dayOfMonth: Int,
    val month: Month,
    val year: Int,
    val dayOfWeek: WeekDay,
    val dayOfYear: Int,
    val timestamp: Long
)

enum class Month { JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER }
enum class WeekDay { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }

fun GMTDate(timestamp: Long): GMTDate
fun GMTDate.toHttpDate(): String
fun String.fromHttpDate(): GMTDate

Date & Time

Logging

Multi-level logging interface with lazy evaluation for performance optimization.

interface Logger {
    fun trace(message: String)
    fun debug(message: String)
    fun info(message: String)
    fun warn(message: String)
    fun error(message: String)
    fun error(message: String, exception: Throwable)
}

class KtorSimpleLogger(name: String, val level: LogLevel = LogLevel.INFO) : Logger

fun KtorSimpleLogger(name: String): Logger

Logging

Compression & Encoding

Content encoding and compression utilities including GZip and Deflate support.

interface Encoder {
    fun encode(source: ByteReadChannel): ByteReadChannel
}

interface Decoder {
    fun decode(source: ByteReadChannel): ByteReadChannel
}

abstract class ContentEncoder : Encoder {
    abstract val name: String
}

object GZipEncoder : ContentEncoder
object DeflateEncoder : ContentEncoder

Compression & Encoding

Types

// Type information for reflection
class TypeInfo

inline fun <reified T> typeInfo(): TypeInfo

// Hash function interface
interface HashFunction {
    fun digest(data: ByteArray): ByteArray
}

// Nonce management
interface NonceManager {
    suspend fun newNonce(): String
    suspend fun verifyNonce(nonce: String): Boolean
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.ktor/ktor-utils-jvm@3.2.x
Publish Source
CLI
Badge
tessl/maven-io-ktor--ktor-utils-jvm badge