/jayo

A fast synchronous I/O and TLS library for the JVM

Primary LanguageJavaApache License 2.0Apache-2.0

License Version Java

Jayo

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 !

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.
  • 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.

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