A fast synchronous I/O library for the JVM that relies on Java 21+ virtual threads, see Project Loom.
Synchronous APIs are easier to work with than asynchronous and non-blocking APIs; the code is easier to write, easier to
read, and easier to debug (with stack traces that make sense!).
Virtual threads allow to run as many threads as we need without requiring thread pools or event-loop. With synchronous
IO that runs inside virtual threads, Jayo offers great performances and scalability.
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;
try (var serverSocket = new ServerSocket(freePortNumber)) {
var serverThread = Thread.startVirtualThread(() -> {
try (var acceptedSocketEndpoint = SocketEndpoint.from(serverSocket.accept());
var serverWriter = Jayo.buffer(acceptedSocketEndpoint.getWriter())) {
serverWriter.write("The Answer to the Ultimate Question of Life is ")
.writeUtf8CodePoint('4')
.writeUtf8CodePoint('2');
} catch (IOException e) {
fail("Unexpected exception", e);
}
});
try (var clientSocketEndpoint = SocketEndpoint.from(new Socket("localhost", freePortNumber));
var clientReader = Jayo.buffer(clientSocketEndpoint.getReader())) {
assertThat(clientReader.readString())
.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 !
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 contentUtf8
is aByteString
that contains UTF-8 encoded bytes only.
RawReader
andRawWriter
(and their buffered versionsReader
andWriter
) offer great improvements overInputStream
andOutputStream
.TlsEndpoint
is an easy-to-use streaming API based on Jayo's reader and writer, that allows to secure JVM applications with minimal added complexity.
You can also read concepts and draft ideas.
Jayo includes modules to integrate it with third-party external libraries
- jayo-3p-kotlinx-serialization allow you to serialize JSON content directly into Jayo's writers and from Jayo's readers thanks to kotlinx.serialization
You need a JDK 21 to build Jayo.
- Clone this repo
git clone git@github.com:jayo-projects/jayo.git
- Build the project
./gradlew clean build
Copyright (c) 2024-present, pull-vert and Jayo contributors