Skip to content

jayo-projects/jayo

Repository files navigation

License Version Java

Jayo

A fast and simple synchronous I/O library for the JVM that relies on Java 21+ virtual threads, see Project Loom.

Virtual threads allow to run as many threads as we need without requiring thread pools or event-loop. With blocking IO that runs inside virtual threads, Jayo offers great performances and scalability, leading to simple, readable and debuggable code.

Jayo is available on Maven Central.

Maven:

<dependency>
    <groupId>dev.jayo</groupId>
    <artifactId>jayo</artifactId>
    <version>X.Y.Z</version>
</dependency>

Gradle:

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 serverWriter = Jayo.buffer(Jayo.writer(acceptedSocket))) {
        serverWriter.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 clientReader = Jayo.buffer(Jayo.reader(clientSocket))) {
    assertThat(clientReader.readUtf8String())
        .isEqualTo("The Answer to the Ultimate Question of Life is 42");
}
serverThread.join();

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 are natively included in this project.

Jayo's source code is derived and inspired 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 related binary content
    • Utf8 is a ByteString that contains UTF-8 encoded bytes only.
  • RawReader and RawWriter (and their buffered versions Reader and Writer) 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