Skip to content

fredsuvn/fs

Repository files navigation

fs: a lightweight, high-performance, zero-dependency tool lib for java

Overview

fs is a lightweight, multi-version JDK support, high-performance, zero-dependency tool lib for java. It provides:

  • Annotations that can be used for code analysis;
  • Common utilities and interfaces for bytes, chars, coding, date, enum, exception, logging, math, number, process, random, resource, string, system, thread; reflect, etc.;
  • Extensions for functions, values, and options;
  • I/O kits and interfaces;
  • More light and fast cache interfaces and implementations;
  • Kits for collections, maps, arrays, etc.;
  • Kits for codec;
  • Concurrent supports;
  • Network kits and interfaces for http, tcp, udp, etc.;
  • Object parsing and conversion;
  • Dynamic invocation, supporting reflection, method-handle and asm;
  • Dynamic proxy and aspect, supporting JDK dynamic proxy and asm;
  • Third-party supporting: asm, protobuf;

Multi-Version JDK Support

fs provides adaptive implementation loading that automatically selects the optimal class version based on the runtime JDK environment (from JDK8 to JDK17). Its main code is based on JDK8, but some interfaces have multiple implementation classes of different jdk versions.

For example, the implementation class of space.sunqian.fs.net.http.HttpCaller has two versions: JDK8 and JDK11. The former is based on java.net.HttpURLConnection, and the latter is based on java.net.http.HttpClient.

This ensures:

  • Backward Compatibility: Seamlessly runs on older JDK versions (JDK8+);
  • Forward Optimization: Leverages newer JDK features when available (up to JDK17);
  • Automatic Detection: No manual configuration required -- the library automatically loads the appropriate implementation at runtime;

High Performance

fs has higher performance than other common libraries in many places, Here are some examples:

  • Simple Cache (space.sunqian.fs.cache.SimpleCache): SimpleCache only considers common cache functions, so it has higher performance in common functions. Here is the benchmark: CacheBenchmark

  • CopyProperties (Fs.copyProperties / space.sunqian.fs.object.convert.DataMapper): DataMapper has better performance and more comprehensive support. Here is the benchmark: CopyPropertiesBenchmark

  • TCP Server (space.sunqian.fs.net.tcp.TcpServer): Rare interface server implementation with slightly better performance than netty. Here is the benchmark: TcpServerBenchmark

Here is the full benchmark result: results.json.

And here is the benchmark result chart: JMH Visualizer.

Zero Dependency

fs has no strong dependency on any other libraries (except for JDK and its own modules, and fs-all aggregates all the classes of all modules without module dependencies). It implements some of the classes from the javax package in jsr305, such as javax.annotation.Nonnull, and based on this, it also implements its own annotations, such as: space.sunqian.annotatations.Nonnull and space.sunqian.annotatations.Nullable.

Some functions of fs are based on ASM and protobuf, such as bytecode proxy, aspect, and object conversion about protobuf. The ASM uses built-in package space.sunqian.fs.asm, so this lib has no dependencies for package org.objectweb.asm.

For protobuf, although it depends on com.google.protobuf, the protobuf classes will not be loaded unless necessary.

Test passing rate and coverage: 100%

The test passing rate and JaCoCo coverage for this library are both 100%:

fs-asm is excluded from the test and coverage report because it is total copied from ASM framework.

Documents and Samples

Clone and Build

fs uses gradle as the build tool:

# clone and build
git clone -b master https://github.com/fredsuvn/fs.git
cd fs && gradle clean build

fs needs multi JDK versions to build: from 1.8 to 17.

The root gradle properties file (gradle.properties) configures the multi JDK versions in:

org.gradle.java.installations.paths=\
  ~/.jdks/azul-1.8.0_462,\
  ~/.jdks/azul-17.0.17,\
  ~/.jdks/openjdk-25,

Change this property to your local JDK paths, or let gradle automatically download required JDK versions without manual configuration.

Contact

License

Apache 2.0 license

About

fs is a lightweight, multi-version JDK support, high-performance, zero-dependency tool lib for java.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •