https://github.com/knio-org/knio-core
Kotlin + NIO : true non-blocking I/O : classic api
https://github.com/knio-org/knio-core
jvm kotlin kotlin-coroutines nio
Last synced: 3 months ago
JSON representation
Kotlin + NIO : true non-blocking I/O : classic api
- Host: GitHub
- URL: https://github.com/knio-org/knio-core
- Owner: knio-org
- License: apache-2.0
- Created: 2025-01-02T02:07:04.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-02-21T07:06:56.000Z (8 months ago)
- Last Synced: 2025-02-21T08:20:51.926Z (8 months ago)
- Topics: jvm, kotlin, kotlin-coroutines, nio
- Language: Kotlin
- Homepage: https://www.knio.org/
- Size: 1020 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/isaiah-v/Knio/actions/workflows/build.yml)
[](https://www.knio.org/knio-core/build/main/jacoco/)
[](https://www.knio.org/knio-core/build/main/kdoc/)
----# Knio
From files to sockets, a true non-blocking I/O library built with Kotlin Coroutines and NIO — offering an efficient,
readable, and user-friendly `java.io`-like API.---
## Features
- *Kotlin Coroutine Integration*: Enables concise, asynchronous, non-blocking code while maintaining the readability and maintainability of sequential programming.
- *NIO-Powered I/O*: Built on Java’s NIO framework for efficient, scalable, and truly non-blocking I/O operations.
- *Familiar API*: Provides a java.io-inspired API, allowing developers to modernize existing codebases effortlessly with minimal to no learning curve while transitioning to a fully non-blocking model.---
## Example: Buffered Reader
With the magic of `kotlin-coroutines`, operations like `readLine()` suspend instead of blocking, releasing the thread to
perform other tasks. And with `nio`, we aren't blocking a thread elsewhere. The underlying I/O operations are entirely
non-blocking. With no complicated callbacks or process streams, the code is easy to read and maintain.```kotlin
import org.knio.core.io.bufferedReader
import org.knio.core.io.knioInputStream
import org.knio.core.lang.use
import java.io.Filesuspend fun main() {
val filePath = "example.txt"// Create a buffered reader for a file
File(filePath).knioInputStream().bufferedReader().use { reader ->
var line: String? = reader.readLine() // Suspends instead of blockingwhile (line != null) {
println(line) // Print each line from the file
line = reader.readLine() // Suspends instead of blocking
}
}
}
```---
## SnapshotsSnapshot builds are available from the `main` branch. To use the latest snapshot, configure your build script to use the GitHub Maven repository and add the Knio dependency.
`build.gradle.kts`
```kotlin
repositories {
maven("https://maven.pkg.github.com/knio-org/knio-core")
}dependencies {
implementation("org.knio:knio-core:0.1.0-SNAPSHOT")
}
```