jayo-projects / jayo

A synchronous I/O library for the JVM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

License Version Java

Jayo

Jayo is a synchronous I/O library for the JVM based on java.io.

Jayo library is available on Maven Central.

repositories {
    mavenCentral()
}

dependencies {
    implementation("dev.jayo:jayo:X.Y.Z")
}
var freePortNumber = 54321;
var serverThread = Thread.startVirtualThread(() -> {
    try (var serverSocket = new ServerSocket(freePortNumber);
        var acceptedSocket = serverSocket.accept();
        var serverSink = Jayo.buffer(Jayo.sink(acceptedSocket))) {
        serverSink.writeUtf8("The Answer to the Ultimate Question of Life is ")
            .writeUtf8CodePoint('4')
            .writeUtf8CodePoint('2');
    } catch (IOException e) {
        fail("Unexpected exception", e);
    }
});
try (var clientSocket = new Socket("localhost", freePortNumber);
    var clientSource = Jayo.buffer(Jayo.source(clientSocket))) {
    assertThat(clientSource.readUtf8())
        .isEqualTo("The Answer to the Ultimate Question of Life is 42");
}
serverThread.join();

Jayo relies on Java 21 Virtual Threads, that allow to run as many threads as we need without requiring thread pools or event-loop. With blocking code that uses virtual threads we achieve blazing fast performances and scalability, leading to simple, readable and debuggable code.

Jayo is written in Java without any external dependencies, to stay as light as possible.

We also love Kotlin ! Jayo is fully usable and optimized from Kotlin code thanks to @NonNull annotations, Kotlin friendly method naming (get* and set*) and a lot of Kotlin extension functions included in this project.

Jayo's source code is derived from Okio and kotlinx-io, but does not preserve strict backward compatibility with them.

By the way, Jayo simply refers to Java IO, revisited.

See the project website (coming soon) for documentation and APIs.

Java 21 is required to use Jayo.

Contributions are very welcome, simply clone this repo and submit a PR when your fix or feature is ready !

Main concepts

Jayo offers solid I/O foundations by providing the tools we need for binary data manipulation

  • Buffer is a mutable sequence of bytes one can easily write to and read from.
  • ByteString is an immutable and serializable sequence of bytes that stores a String binary content.
  • RawSource and RawSink (and their buffered versions Source and Sink) offer great improvements over InputStream and OutputStream.

You can also read concepts and draft ideas.

Third-party integration modules

Jayo includes modules to integrate it with third-party external libraries

Build

You need a JDK 21 to build Jayo.

  1. Clone this repo
git clone git@github.com:jayo-projects/jayo.git
  1. Build the project
./gradlew clean build

License

Apache-2.0

Copyright (c) 2024-present, pull-vert and Jayo contributors

About

A synchronous I/O library for the JVM

License:Apache License 2.0


Languages

Language:Java 64.5%Language:Kotlin 35.5%