Pierced is a lightweight Java library which handles basic TOML configuration files.
Using Groovy
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation include("com.github.KrLite:Pierced:$project.pierced_version")
}
pierced_version=?
[!NOTE] Replace
?
with the latesttag name
of Pierced.
Using Kotlin
repositories {
maven("https://jitpack.io")
}
dependencies {
include("com.github.KrLite:Pierced:${property("piercedVersion")}")?.let {
implementation(it)
}
}
piercedVersion=?
[!NOTE] Replace
?
with the latesttag name
of Pierced.
Once implemented, extend Pierced ↗
1 class and add your own configuration fields.
Pierced is only 16KB2. You can bring Pierced anywhere you want.
The sacrifice of such a small size is that Pierced is not a full-featured TOML parser. It only supports the most basic features of TOML, and so is not recommended for complex configuration files. Still, for those who want something fast and simple, Pierced is a solid choice.
public class Config extends Pierced {
public String name;
public int age;
public boolean isMale;
public String[] hobbies;
public List<String> friends;
public Map<String, Integer> scores;
public Config(File file) {
super(Config.class, file); // Config.class should be the same as this class
}
}
Config config = new Config(new File("config.toml"));
config.load();
System.out.println(config.name);
config.age = 18;
config.save();
Pierced supports most of the TOML features:
- (±)nan and (±)infinity
- Basic strings and literal strings3
- Boolean values
- Full-line comments and inline comments
- Integer (bin, oct, dec and hex) values and float values with underscores4
- Multiline basic strings and literal strings3
- Tables (dotted keys)
Warning
Pierced does not support these features for now:
- Array values
- Dates and times
Pierced supports annotations to customize the behavior of the options.
@Comment("THIS CONFIGURATION FILE IS FOR DEMO")
@Comment("DO NOT USE IN PRODUCTION")
public class Config extends Pierced<Config> {
public Config(File file) {
super(Config.class, file);
}
@Comment("The name of the user")
public String name = "Username";
}
# THIS CONFIGURATION FILE IS FOR DEMO
# DO NOT USE IN PRODUCTION
name = 'Username'
# The name of the user
@Table("user")
public String name = "Username"; // Categorized
public int people = 100; // Uncategorized
people = 100
[user]
name = 'Username'
public String name = "Username"; // Visible
public @Silent int age = 18; // Invisible
Important
Only fields not annotated with @Silent
will be saved and loaded.
Pierced is licensed under the GNU Lesser General Public License v3.0.
Footnotes
-
net.krlite.pierced.config.Pierced
↩ -
Currently, Pierced compiled and source JARs are only 16KB and 8KB, respectively. ↩
-
Literal strings can be read, but will be seen the same as basic strings for now. All strings are saved as literal strings in case of complex escaping. ↩ ↩2
-
Scientific notation is not supported yet. ↩