A Kotlin Multiplatform (KMP) port of Java’s IO classes, bringing familiar IO operations to multiplatform projects—JVM, Android, iOS, macOS, Linux, Windows, Web, and beyond.
This library is organized into modular components for flexibility and clarity.
Note Direct file read/write APIs are not included. For file operations, use this library in combination with
kotlinx-io
orokio
, which support stream conversions.
Core components for buffer and charset management.
Buffer
: Base container (likejava.nio.Buffer
)ByteBuffer
,CharBuffer
CharBufferFactory
: Helper utilities to create buffersCloseable
,Readable
: Interfaces for IO components
Stream and reader abstractions.
- Character Streams
Reader
,BufferedReader
,StringReader
,CharArrayReader
PushbackReader
,FilterReader
- Byte Streams
InputStream
,ByteArrayInputStream
,InputStreamReader
OutputStream
,ByteArrayOutputStream
,BufferedOutputStream
,FilterOutputStream
- Charset Support CharsetsReadme.md
- Extension Functions
"Hello".byteInputStream() // return ByteArrayInputStream "Hello".reader() // return StringReader byteArray.inputStream() // return ByteArrayInputStream inputStream.reader() // return InputStreamReader inputStream.bufferedReader() // return BufferedReader reader.buffered() // return BufferedReader reader.buffered().readLines() bufferedReader.readString(count)```
Multiplatform-safe version of java.net.URI
.
URI
: Parse, resolve, normalize URIsURIFactory
: Use this instead ofURI.create()
Interop for working with kotlinx-io
streams:
Source.asInputStream(): InputStream
RawSource.asInputStream(): InputStream
InputStream.asSource(): RawSource
Interop for Okio-powered IO:
Source.asInputStream(): InputStream
InputStream.asSource(): Source
Support for standard and extended character sets:
- Standard:
com.fleeksoft.charset:charset:<version>
- Extended:
com.fleeksoft.charset:charset-ext:<version>
➡️ More info
Add dependencies in your build.gradle.kts
:
commonMain.dependencies {
implementation("com.fleeksoft.io:io-core:<version>")
implementation("com.fleeksoft.io:io:<version>")
// Optional integrations
implementation("com.fleeksoft.io:kotlinx-io:<version>")
implementation("com.fleeksoft.io:okio:<version>")
}
val str = "Hello, World!"
val byteArray = ByteArray(10)
val charArray = CharArray(10)
val byteArrayInputStream = str.byteInputStream()
val stringReader = str.reader()
val bufferedReader = stringReader.buffered()
val bufferedReader2 = byteArrayInputStream.bufferedReader()
val byteBuffer = ByteBufferFactory.wrap(byteArray)
val charBuffer = CharBufferFactory.wrap(charArray)
Contributions are welcome! Open an issue or submit a pull request to improve features, fix bugs, or enhance documentation.
Licensed under the Apache License 2.0. See LICENSE for full details.