JProperties
JProperties is a small, highly efficient, and extensible library for parsing .properties
files.
It is a modern replacement for the java.util.Properties
class that utilizes the Java Collections Framework to parse properties directly to a Map<String, String>
.
Developer ease-of-use is another priority for this library, and as such, it includes the xyz.maow.jproperties.JProperties
class for easily reading properties from multiple supported sources within 1-2 lines.
The supported sources include InputStream
, File
, Path
, byte[]
, String
, Properties
, and input streams retrieved from resources via fromResource(String)
.
All of the above also have a concurrency-safe counterpart that utilizes ConcurrentHashMap
.
Other utilities are included amongst the necessities, these include things like PropertiesBuilder
, TextUtils
, etc.
Installation
JProperties is available on Maven Central
Groovy DSL
repositories {
mavenCentral()
}
dependencies {
implementation "xyz.maow:jproperties:<version>"
}
Kotlin DSL
repositories {
mavenCentral()
}
dependencies {
implementation("xyz.maow:jproperties:<version>")
}
Usage
Example: Reading properties from a file
# config.properties
option=value
// Properties
Path filePath = Paths.get("config.properties");
try (InputStream src = Files.newInputStream(filePath)) {
Properties props = new Properties();
props.load(src);
} catch (IOException e) {
e.printStackTrace();
}
// JProperties
Path filePath = Paths.get("config.properties");
Map<String, String> props = JProperties.from(filePath); // {"option": "value"}
Benchmark
Benchmark Mode Cnt Score Error Units
PropBenchmark.benchmark_JProperties thrpt 15 336637.037 � 5804.054 ops/s
PropBenchmark.benchmark_Properties thrpt 15 612128.919 � 8872.088 ops/s