public class PropertyFile extends Object
Modifier and Type | Class | Description |
---|---|---|
protected class |
PropertyFile.BlankLine |
|
protected class |
PropertyFile.Comment |
|
protected class |
PropertyFile.Entry |
|
protected class |
PropertyFile.NameValuePair |
Modifier and Type | Field | Description |
---|---|---|
protected boolean |
caseSensitive |
|
protected boolean |
dirty |
|
protected List<PropertyFile.Entry> |
entries |
|
protected File |
f |
|
protected boolean |
forceNameValueDelimiterWhitespace |
|
protected boolean |
readOnly |
|
protected Map<String,PropertyFile.NameValuePair> |
vars |
Constructor | Description |
---|---|
PropertyFile() |
|
PropertyFile(File fileName) |
|
PropertyFile(File fileName,
boolean caseSensitive) |
|
PropertyFile(InputStream is) |
|
PropertyFile(InputStream is,
boolean caseSensitive) |
|
PropertyFile(Reader r) |
|
PropertyFile(Reader r,
boolean caseSensitive) |
|
PropertyFile(URL url) |
|
PropertyFile(Map<String,String> map) |
|
PropertyFile(Properties p) |
|
PropertyFile(Properties p,
boolean caseSensitive) |
Modifier and Type | Method | Description |
---|---|---|
protected void |
_clear() |
|
protected boolean |
_contains(String name) |
|
protected String |
_get(String name,
String defaultValue) |
|
protected String |
_get_core(String name,
String defaultValue) |
|
protected void |
_rm(String name) |
|
protected String |
_set(String name,
String value) |
|
void |
clear() |
|
boolean |
containsKey(String name) |
|
static PropertyFile |
find() |
|
static PropertyFile |
find(ClassLoader classloader,
String... fileNames) |
Find a property file
|
static PropertyFile |
find(String fileName) |
|
static PropertyFile[] |
findAll(ClassLoader loader,
String name) |
Find all property files by the name
name by searching the specified classloader |
static PropertyFile[] |
findAll(String name) |
Find all property files by the name
name by searching the classloader that owns PropertyFile |
static PropertyFile |
fromString(String contents) |
|
static PropertyFile |
fromString(String contents,
String filename) |
|
String |
get(String name) |
|
boolean |
get(String name,
boolean defaultValue) |
|
int |
get(String name,
int defaultValue) |
|
long |
get(String name,
long defaultValue) |
|
String |
get(String name,
String defaultValue) |
|
byte[] |
getBase64(String name) |
Get a value which is Base64 encoded
|
byte[] |
getBase64(String name,
byte[] defaultValue) |
Get a value which is Base64 encoded and has a default value
|
boolean |
getBoolean(String name,
boolean defaultValue) |
|
boolean |
getCaseSensitive() |
|
Class<?> |
getClass(String name,
Class<?> defaultValue) |
|
File |
getFile() |
|
boolean |
getForceNameValueDelimiterWhitespace() |
|
byte[] |
getHex(String name) |
Get a value which has been encoded in hexidecimal; The encoding may optionally include : delimiters, but no other non-hex
characters are permitted
|
int |
getInteger(String name,
int defaultValue) |
|
InetAddress |
getIP(String name,
InetAddress defaultValue) |
|
int |
getLineCount() |
|
long |
getLong(String name,
long defaultValue) |
|
URI |
getURI(String name,
String defaultValue) |
|
int |
getVariableCount() |
|
protected void |
hook_added(String name,
String newValue) |
|
protected void |
hook_changed(String name,
String oldValue,
String newValue) |
|
protected void |
hook_cleared() |
|
protected void |
hook_loaded() |
|
protected void |
hook_merge_begin() |
|
protected void |
hook_merge_complete() |
|
protected void |
hook_removed(String name) |
|
protected void |
hook_saved() |
|
Iterator<String> |
keyIterator() |
|
Set<String> |
keySet() |
|
void |
load() |
|
void |
load(File file) |
|
void |
load(InputStream is) |
|
void |
load(Reader r) |
|
void |
load(Map<String,String> map) |
|
void |
load(Properties p) |
|
void |
makeReadOnly() |
Make this PropertyFile object read-only
|
void |
merge(PropertyFile other) |
Merges another PropertyFile into this PropertyFile, overwriting any conflicting properties with the value from
other |
void |
merge(PropertyFile other,
IMergeConflictResolver conflictResolver) |
Merges another PropertyFile into this PropertyFile, using an optional merge conflict resolver
If no merge conflict resolver is specified then the default will be that the properties from other will
overwrite the local properties |
void |
merge(Properties other) |
Merges another PropertyFile into this PropertyFile, overwriting any conflicting properties with the value from
other |
void |
merge(Properties other,
IMergeConflictResolver conflictResolver) |
Merges another PropertyFile into this PropertyFile, using an optional merge conflict resolver
If no merge conflict resolver is specified then the default will be that the properties from other will
overwrite the local properties |
static PropertyFile |
openResource(ClassLoader classloader,
URL resource,
String fileName) |
|
static PropertyFile |
readOnly(File filename) |
Creates a read-only version of a property file
Fails if the file does not exist. |
static PropertyFile |
readOnlyUnion(PropertyFile... files) |
Construct a new read-only PropertyFile which merges the contents of a number of other PropertyFile objects
Null PropertyFiles are ignored. |
static PropertyFile |
readOnlyUnion(File... filenames) |
Creates a read-only union of a number of property files
If any property file is null or the file it points to does not exist then it is ignored |
void |
remove(String name) |
|
void |
save() |
|
void |
save(File f,
String comment) |
|
void |
save(OutputStream os) |
|
void |
save(String comment) |
|
void |
save(String comment,
OutputStream os) |
|
void |
save(String comment,
Writer w) |
|
String |
set(String name,
int value) |
|
String |
set(String name,
long value) |
|
String |
set(String name,
String value) |
|
String |
setBase64(String name,
byte[] value) |
|
void |
setFile(File file) |
|
void |
setForceNameValueDelimiterWhitespace(boolean value) |
|
String |
setHex(String name,
byte[] value) |
|
Map<String,String> |
toMap() |
Converts the name/value pairs stored in this PropertyFile to a Map of key/value pairs
|
Properties |
toProperties() |
Converts the name/value pairs stored in this PropertyFile to the Java Properties propertyfile type
|
protected File f
protected boolean readOnly
protected boolean caseSensitive
protected boolean forceNameValueDelimiterWhitespace
protected List<PropertyFile.Entry> entries
protected Map<String,PropertyFile.NameValuePair> vars
protected boolean dirty
public PropertyFile(File fileName) throws IOException
IOException
public PropertyFile(File fileName, boolean caseSensitive) throws IOException
IOException
public PropertyFile()
public PropertyFile(URL url) throws IOException
IOException
public PropertyFile(InputStream is, boolean caseSensitive) throws IOException
IOException
public PropertyFile(Reader r) throws IOException
IOException
public PropertyFile(Reader r, boolean caseSensitive) throws IOException
IOException
public PropertyFile(InputStream is) throws IOException
IOException
public PropertyFile(Properties p)
public PropertyFile(Properties p, boolean caseSensitive)
public static PropertyFile find()
public static PropertyFile find(String fileName)
public static PropertyFile find(ClassLoader classloader, String... fileNames)
classloader
- fileName
- public static PropertyFile fromString(String contents)
public static PropertyFile fromString(String contents, String filename)
public static PropertyFile openResource(ClassLoader classloader, URL resource, String fileName)
public static PropertyFile[] findAll(String name)
name
by searching the classloader that owns PropertyFilename
- public static PropertyFile[] findAll(ClassLoader loader, String name)
name
by searching the specified classloaderloader
- name
- public Properties toProperties()
public Map<String,String> toMap()
public boolean getCaseSensitive()
public File getFile()
public void setFile(File file)
public void setForceNameValueDelimiterWhitespace(boolean value)
public boolean getForceNameValueDelimiterWhitespace()
public void load() throws IOException
IOException
public void load(Properties p)
public void load(File file) throws IOException
IOException
public void load(InputStream is) throws IOException
IOException
public void save() throws IOException
IOException
public void save(File f, String comment) throws IOException
IOException
public void save(OutputStream os) throws IOException
IOException
public void save(String comment) throws IOException
IOException
public void save(String comment, OutputStream os) throws IOException
IOException
public void merge(PropertyFile other)
other
other
- the other property filepublic void merge(PropertyFile other, IMergeConflictResolver conflictResolver)
other
will
overwrite the local propertiesother
- the other property fileconflictResolver
- public void merge(Properties other)
other
other
- public void merge(Properties other, IMergeConflictResolver conflictResolver)
other
will
overwrite the local propertiesother
- the other property fileconflictResolver
- public void makeReadOnly()
public boolean containsKey(String name)
public InetAddress getIP(String name, InetAddress defaultValue)
public int get(String name, int defaultValue)
public long get(String name, long defaultValue)
public boolean get(String name, boolean defaultValue)
public int getInteger(String name, int defaultValue)
public boolean getBoolean(String name, boolean defaultValue)
public long getLong(String name, long defaultValue)
public byte[] getBase64(String name)
name
- public byte[] getBase64(String name, byte[] defaultValue)
name
- defaultValue
- public byte[] getHex(String name)
name
- public void remove(String name)
public void clear()
public int getLineCount()
public int getVariableCount()
protected void hook_removed(String name)
protected void hook_cleared()
protected void hook_merge_begin()
protected void hook_merge_complete()
protected void hook_loaded()
protected void hook_saved()
public void load(Reader r) throws IOException
IOException
public void save(String comment, Writer w) throws IOException
IOException
protected void _clear()
protected boolean _contains(String name)
protected void _rm(String name)
public static PropertyFile readOnlyUnion(File... filenames) throws IOException
filenames
- IOException
- if an unexpected error occurs while loading a filepublic static PropertyFile readOnlyUnion(PropertyFile... files)
files
- public static PropertyFile readOnly(File filename) throws IOException
filename
- the filename to loadIOException
- if the file cannot be loadedCopyright © 2018. All rights reserved.