Skip to content

jayo-projects/jayo

Repository files navigation

License Version Java Kotlin

Jayo

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

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!).

// Let the system pick up a local free port
try (NetworkServer listener = NetworkServer.bindTcp(new InetSocketAddress(0))) {
  Thread serverThread = Thread.startVirtualThread(() -> {
    try (NetworkEndpoint serverEndpoint = listener.accept();
         Writer serverWriter = Jayo.buffer(serverEndpoint.getWriter())) {
      serverWriter.write("The Answer to the Ultimate Question of Life is ")
            .writeUtf8CodePoint('4')
            .writeUtf8CodePoint('2');
    }
  });
  try (NetworkEndpoint clientEndpoint = NetworkEndpoint.connectTcp(listener.getLocalAddress());
       Reader clientReader = Jayo.buffer(clientEndpoint.getReader())) {
    assertThat(clientReader.readString())
        .isEqualTo("The Answer to the Ultimate Question of Life is 42");
  }
  serverThread.join();
}

Jayo is available on Maven Central.

Gradle:

dependencies {
    implementation("dev.jayo:jayo:X.Y.Z")
}

Maven:

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

Jayo is written in plain Java without the use of any external dependencies, to be 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 Kotlin extension functions are natively included in this project.

Jayo's source code is derived and inspired from Okio, but does not preserve backward compatibility with it.

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

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

Jayo is a Multi-Release JAR with base Java version set to 17. Its Java 21 sources activate internal use of virtual threads.

Contributions are very welcome, simply clone this repo and submit a PR when your fix, new feature or optimization 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 as-is.
    • Utf8 is a specific ByteString that contains UTF-8 encoded bytes only with a lot more functions.
  • RawReader and RawWriter, and mostly their buffered versions Reader and Writer, offer great improvements over InputStream and OutputStream.
  • NetworkEndpoint is a nice replacement for java.net.Socket, and NetworkServer for java.net.ServerSocket.

Jayo also provides some useful tools for TLS

  • 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.
  • JssePlatform eases access to platform-specific Java Secure Socket Extension (JSSE) features.

When used within Java 21+ virtual threads (see Project Loom), synchronous I/O will use non-blocking network APIs and trigger very fast context switches between a few platform OS-level threads instead of blocking them like they did before Loom. Virtual threads allow to run as many threads as we need without requiring thread pools or event-loop.

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 [email protected]: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 fast synchronous I/O and TLS library for the JVM

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published