public class ZConfig extends Object
Lets applications load, work with, and save configuration files. This is a minimal implementation of the ZeroMQ Property Language, which is a simple structured text format for configuration files.
Here is an example ZPL stream and corresponding config structure:
context iothreads = 1 verbose = 1 # Ask for a trace main type = zqueue # ZMQ_DEVICE type frontend option hwm = 1000 swap = 25000000 # 25MB bind = 'inproc://addr1' bind = 'ipc://addr2' backend bind = inproc://addr3root Down = child | Across = next v context-->main | | | v | type=queue-->frontend-->backend | | | | | v | | bind=inproc://addr3 | v | option-->bind=inproc://addr1-->bind=ipc://addr2 | | | v | hwm=1000-->swap=25000000 v iothreads=1-->verbose=false
It can put and get values and save and load them to disk:
ZConfig conf = new ZConfig("root", null);
conf.put("/curve/public-key","abcdef");
String val = conf.get("/curve/public-key","fallback-defaultkey");
conf.save("test.cert");
ZConfig loaded = ZConfig.load("test.cert");
| Modifier and Type | Class and Description |
|---|---|
static class |
ZConfig.ReadException |
| Modifier and Type | Method and Description |
|---|---|
void |
addComment(String comment)
add comment
|
ZConfig |
getChild(String name) |
String |
getName() |
String |
getValue(String path) |
String |
getValue(String path,
String defaultValue) |
Map<String,String> |
getValues() |
static ZConfig |
load(String filename) |
boolean |
pathExists(String path)
check if a value-path exists
|
ZConfig |
putValue(String path,
String value) |
void |
putValues(ZConfig src) |
File |
save(String filename)
Saves the configuration to a file.
|
void |
save(Writer writer) |
public String getName()
public boolean pathExists(String path)
path - public void addComment(String comment)
comment - public ZConfig putValue(String path, String value)
path - value - set value of config itempublic void putValues(ZConfig src)
public File save(String filename) throws IOException
This method will overwrite contents of existing file
filename - the path of the file to save the configuration into, or "-" to dump it to standard outputIOException - if unable to save the file.public void save(Writer writer) throws IOException
IOExceptionpublic static ZConfig load(String filename) throws IOException
IOExceptionCopyright © 2020. All rights reserved.