public class Configuration
extends java.lang.Object
java.util.Properties
class but
without some of its limitations while keeping full compatibility. For instance this class
is capable of using different encodings, not only the ISO-8859-1 Unicode Escapes. A special
encoding can be specified by adding a special header comment called a directive.
You can use any of the standard JDK/JRE encodings like UTF-8, ISO 8859-1 pretty much as for
XML files. Due to compatibility of Configuration
and Properties
also the ISO-8859-1 Unicode Escapes are supported as well. In order to make a difference
from the Properties
class the managed items are called variables instead
of properties. Normally Properties
use the file suffix .properties
while the Configuration
class prefers .conf
. This makes clear
for a programmer which class to use for configuration/properties files. Whenever there is
a need for Properties
compatibility you should use .properties
as
file extension. If you need special features of Configuration
then you should
prefer .conf
. But keep in mind, that .conf
files may not be
compatible with Properties
since the features like the UTF-8 encoding are
not supported by Properties
. Files ending with .properties
should
always apply fully to the Properties
file format.
The default handlers are instantiated at JVM startup when the handler classes are installed.
All default handlers provide a getSharedInstance()
method to get these shared
instances which are also used by this class. If you need a specialized handler then simply
add it to the handler cache, perhaps you like to overwrite one of the default handlers as well.
Remember that null
objects can be stored without problems by adding the string
"null". If your program wants to store the string "null" this must be escaped somehow so
that the getter method does not return a null
object reference.
Modifier and Type | Field and Description |
---|---|
protected boolean |
clearBeforeRead
Clear existing variables before new data is read (default is
true )? |
protected java.lang.String |
comment
The header comment for written files, default is no comment.
|
protected java.lang.String |
compression
The currently used file compression algorithm, default is
COMPRESSION_UNCOMPRESSED . |
static java.lang.String |
COMPRESSION_DEFLATED
Configuration files shall be stored DEFLATED.
|
static java.lang.String |
COMPRESSION_GZIPPED
Configuration files shall be stored GZIPped.
|
static java.lang.String |
COMPRESSION_UNCOMPRESSED
Configuration files shall be stored with no compression.
|
protected java.lang.String |
encoding
Represents the current file encoding, default is
ENCODING_ISO_8859_1_UNICODE_ESCAPES . |
static java.lang.String |
ENCODING_ISO_8859_1_UNICODE_ESCAPES
By default config files are written using this encoding.
|
protected java.util.Hashtable<java.lang.String,TypeHandler> |
handlers
Container holding the object type handlers for
set /get . |
protected java.util.Hashtable<java.lang.String,java.lang.String> |
hash
Container holding all locally managed variable value pairs.
|
protected boolean |
sorting
Shall written files be sorted alphabetically by variable names?
|
Constructor and Description |
---|
Configuration()
Constructor which simple initialization functionality.
|
Configuration(boolean handlers)
Constructor that may not install the default type handlers.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Deletes all variable value pairs from the internal container.
|
boolean |
contains(java.lang.String variable)
Tests the existence of a specific variable in the
Hashtable . |
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.
|
protected void |
finalize()
Cares for proper cleanup after releasing the object.
|
boolean |
getBoolean(java.lang.String variable)
Gets the
boolean value of a variable. |
boolean |
getBoolean(java.lang.String variable,
boolean fallback)
Gets the
boolean value of a variable. |
byte |
getByte(java.lang.String variable)
Gets the
byte value of a variable. |
byte |
getByte(java.lang.String variable,
byte fallback)
Gets the
byte value of a variable. |
java.util.Hashtable<java.lang.String,java.lang.String> |
getCache()
Provides the currently managed variables (handle with care).
|
char |
getChar(java.lang.String variable)
Gets the
char value of a variable. |
char |
getChar(java.lang.String variable,
char fallback)
Gets the
char value of a variable. |
boolean |
getClearBeforeRead()
Provides the info if the cache is cleared before new data is read.
|
java.lang.String |
getComment()
Returns the compression algorithm for written files.
|
java.lang.String |
getCompression()
Returns the compression algorithm for written files.
|
double |
getDouble(java.lang.String variable)
Gets the
double value of a variable. |
double |
getDouble(java.lang.String variable,
double fallback)
Gets the
double value of a variable. |
java.lang.String |
getEncoding()
Returns the current encoding used for written files.
|
float |
getFloat(java.lang.String variable)
Gets the
float value of a variable. |
float |
getFloat(java.lang.String variable,
float fallback)
Gets the
float value of a variable. |
TypeHandler |
getHandler(java.lang.Class clazz)
Returns the installed handler for objects if such is installed.
|
TypeHandler |
getHandler(java.lang.String type)
Returns the installed handler for specific objects if such is installed.
|
java.util.Hashtable<java.lang.String,TypeHandler> |
getHandlers()
Provides the currently managed type handlers (handle with care).
|
int |
getInt(java.lang.String variable)
Gets the
int value of a variable. |
int |
getInt(java.lang.String variable,
int fallback)
Gets the
int value of a variable. |
long |
getLong(java.lang.String variable)
Gets the
long value of a variable. |
long |
getLong(java.lang.String variable,
long fallback)
Gets the
long value of a variable. |
java.lang.Object |
getObject(java.lang.String variable,
java.lang.Class clazz)
Convenience method calling
get(variable, clazz.getName()) . |
java.lang.Object |
getObject(java.lang.String variable,
java.lang.Class clazz,
java.lang.Object fallback)
Convenience method calling
get(variable, clazz.getName(), fallback) . |
java.lang.Object |
getObject(java.lang.String variable,
java.lang.String type)
Gets the value of a variable in the desired object type (no primitives).
|
java.lang.Object |
getObject(java.lang.String variable,
java.lang.String type,
java.lang.Object fallback)
Gets the value of a variable in the desired object type (no primitives).
|
short |
getShort(java.lang.String variable)
Gets the
short value of a variable. |
short |
getShort(java.lang.String variable,
short fallback)
Gets the
short value of a variable. |
java.lang.Class[] |
getSupportedClassTypes()
Provides the classes (types) of the supported handlers.
|
java.lang.String[] |
getSupportedTypes()
Provides the class names (types) of the supported handlers.
|
protected java.lang.String |
getVariable(java.lang.String variable)
Gets the desired variable as
String representation from the internal cache. |
java.util.Enumeration<java.lang.String> |
getVariables()
Provides the currently managed variable names.
|
boolean |
isEmpty()
Provides the info if the variables container is currently empty.
|
boolean |
isOrdered()
Provides the info if this configuration keeps the values in the order they were added.
|
boolean |
isSecure()
Provides the info if this configuration stored its values PGP encrypted.
|
boolean |
isSorting()
Returns the compression algorithm for written files.
|
boolean |
isTypeSupported(java.lang.Class clazz)
Checks whether the given variable type is supported by the configuration.
|
boolean |
isTypeSupported(java.lang.String type)
Checks whether the given variable type is supported by the configuration.
|
void |
read(java.io.File file)
Reads the variable value pairs from the specified file.
|
void |
read(org.apache.commons.vfs2.FileObject file)
Reads the variable value pairs from the specified VFS file.
|
void |
read(java.io.InputStream istream)
Reads the variable value pairs from the specified stream.
|
void |
read(java.lang.String filename)
Reads the variable value pairs from the specified file.
|
static java.lang.String |
readConvertProperties(java.lang.String theString) |
void |
readXML(java.io.File file)
Reads the variable value pairs from the specified XML file.
|
void |
readXML(org.apache.commons.vfs2.FileObject file)
Reads the variable value pairs from the specified VFS XML file.
|
void |
readXML(java.io.InputStream istream)
Reads the variable value pairs from the specified XML stream.
|
void |
readXML(java.lang.String filename)
Reads the variable value pairs from the specified XML file.
|
boolean |
remove(java.lang.String variable)
Removes a variable from the cache.
|
boolean |
removeAllHandlers()
Removes all installed handlers from the internal container.
|
boolean |
removeHandler(java.lang.Class clazz)
Removes the specified handler from the internal container if it exists.
|
boolean |
removeHandler(java.lang.String type)
Removes the specified handler from the internal container if it exists.
|
int |
removeStartsWith(java.lang.String prefix)
Removes all variables with a certain prefix from the cache.
|
boolean |
setBoolean(java.lang.String variable,
boolean value)
Sets the
boolean value of a variable. |
boolean |
setByte(java.lang.String variable,
byte value)
Sets the
byte value of a variable. |
boolean |
setChar(java.lang.String variable,
char value)
Sets the
char value of a variable. |
void |
setClearBeforeRead(boolean clear)
Clear existing variables before new data is read (default is
true )? |
void |
setComment(java.lang.String comment)
Sets the header comment for written files.
|
void |
setCompression(java.lang.String compression)
Sets the compression algorithm for written files.
|
boolean |
setDouble(java.lang.String variable,
double value)
Sets the
double value of a variable. |
void |
setEncoding(java.lang.String encoding)
Sets the encoding for written files.
|
boolean |
setFloat(java.lang.String variable,
float value)
Sets the
float value of a variable. |
boolean |
setHandler(TypeHandler newhandler)
Sets a new handler for specific objects.
|
boolean |
setInt(java.lang.String variable,
int value)
Sets the
int value of a variable. |
boolean |
setLong(java.lang.String variable,
long value)
Sets the
long value of a variable. |
boolean |
setObject(java.lang.String variable,
java.lang.Object value)
Sets the variable value with a special handler if the variable type is supported.
|
void |
setOrdered(boolean enable)
Makes this configuration to store its values in the order they were added.
|
void |
setSecure(CryptoManager manager,
java.lang.String keyuserid)
Makes this configuration to store its values securely (PGP encrypted).
|
void |
setSecure(PassphraseProvider provider,
java.lang.String keyuserid)
Makes this configuration to store its values securely (AES encrypted).
|
boolean |
setShort(java.lang.String variable,
short value)
Sets the
short value of a variable. |
void |
setSorting(boolean sorting)
Shall written files be sorted alphabetically by variable name?
|
protected boolean |
setVariable(java.lang.String variable,
java.lang.String value)
Does the
String -based adding of variable value pairs to the internal container. |
int |
size()
Returns the number of currently managed variables.
|
void |
write(java.io.File file)
Saves the variable value pairs into the specified file.
|
void |
write(org.apache.commons.vfs2.FileObject file)
Saves the variable value pairs into the specified VFS file.
|
void |
write(java.io.OutputStream ostream)
Saves the variable value pairs with the specified byte based output stream.
|
void |
write(java.lang.String filename)
Saves the variable value pairs into the specified file.
|
void |
writeXML(java.io.File file)
Saves the variable value pairs into the specified XML file.
|
void |
writeXML(org.apache.commons.vfs2.FileObject file)
Saves the variable value pairs into the specified VFS XML file.
|
void |
writeXML(java.io.OutputStream ostream)
Saves the variable value pairs with the specified byte based XML output stream.
|
void |
writeXML(java.lang.String filename)
Saves the variable value pairs into the specified XML file.
|
public static final java.lang.String COMPRESSION_UNCOMPRESSED
public static final java.lang.String COMPRESSION_GZIPPED
public static final java.lang.String COMPRESSION_DEFLATED
public static final java.lang.String ENCODING_ISO_8859_1_UNICODE_ESCAPES
protected java.util.Hashtable<java.lang.String,java.lang.String> hash
protected java.util.Hashtable<java.lang.String,TypeHandler> handlers
set
/get
.protected java.lang.String compression
COMPRESSION_UNCOMPRESSED
.protected java.lang.String encoding
ENCODING_ISO_8859_1_UNICODE_ESCAPES
.protected java.lang.String comment
protected boolean sorting
protected boolean clearBeforeRead
true
)?public Configuration()
COMPRESSION_UNCOMPRESSED
as compression,
ENCODING_ISO_8859_1_UNICODE_ESCAPES
as encoding, empty comment for written
files, and sorting disabled. All default handlers are installed via shared instances.
public Configuration(boolean handlers)
handlers
- Add default type handlers?protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void clear()
removeAllHandlers()
method to clear the handlers cache.
protected boolean setVariable(java.lang.String variable, java.lang.String value)
String
-based adding of variable value pairs to the internal container.
If the passed variable does already exist, that value will be overwritten with the new one.
This method should only be called by sub-classes and handler instances. Any input data must
be converted into regular Unicode String
values. While the variable names
normally are String
objects, the values might need to be converted first.
For primitive types this is done by the Configuration
class itself or by
the installed handlers.
variable
- The variable namevalue
- The value of the variable also as String
protected java.lang.String getVariable(java.lang.String variable)
String
representation from the internal cache.
variable
- The variable nameString
, maybe null
public boolean setHandler(TypeHandler newhandler)
newhandler
- The new handler to be added (or be overwritten)public TypeHandler getHandler(java.lang.String type)
type
- The desired type of objectsnull
if no such handler is installedgetHandler(Class)
public TypeHandler getHandler(java.lang.Class clazz)
clazz
- The desired class type of objectsnull
if no such handler is installedgetHandler(String)
public boolean removeHandler(java.lang.String type)
type
- The type of the handler to be removedpublic boolean removeHandler(java.lang.Class clazz)
clazz
- The class type of the handler to be removedpublic boolean removeAllHandlers()
public void read(java.lang.String filename) throws java.io.IOException
Hashtable
may be read from a file.
Error is reported via IOException
. This is convenience method in addition to
read(InputStream)
in order to make programmer's life easier.
filename
- Name of the file to store data injava.io.IOException
- An I/O error occurredjava.lang.NullPointerException
- Given file name was null
java.io.FileNotFoundException
- Given file does not existpublic void read(java.io.File file) throws java.io.IOException
Hashtable
may be read from a file.
Error is reported via IOException
. This is convenience method in addition to
read(InputStream)
in order to make programmer's life easier.
file
- File to store data injava.io.IOException
- An I/O error occurredjava.lang.NullPointerException
- Given file name was null
java.io.FileNotFoundException
- Given file does not existpublic void read(org.apache.commons.vfs2.FileObject file) throws java.io.IOException
Hashtable
may be read from a file.
Error is reported via IOException
. This is convenience method in addition to
read(InputStream)
in order to make programmer's life easier.
file
- VFS file to store data injava.io.IOException
- An I/O error occurredjava.lang.NullPointerException
- Given file name was null
org.apache.commons.vfs2.FileSystemException
- Given file does not existpublic void read(java.io.InputStream istream) throws java.io.IOException
Hashtable
may be read from a stream.
Error is reported via IOException
. This is the low-level functionality
repsonsible for the reading. The optional compression is auto-detected by the routine and
then set for the configuration so writing the config later will use the same compression.
The same is the case for the encoding which is ISO 8859-1 with Unicode Escapes by default
in order to keep compatibility with the Properties
class. If a special header
entry for the encoding is found this is used for the deserialization of the configuration.
Also the encoding is set for the configuration so writing the config later will use the
same encoding.
istream
- The byte based stream to be read from, never closedjava.io.IOException
- An I/O error occurredjava.lang.NullPointerException
- Given file name was null
java.io.UnsupportedEncodingException
- Character encoding (charset) was not validpublic void readXML(java.lang.String filename) throws java.io.IOException
Hashtable
may be read from a file.
Error is reported via IOException
. This is convenience method in addition to
read(InputStream)
in order to make programmer's life easier.
filename
- Name of the XML file to import datajava.io.IOException
- An I/O error occurredjava.lang.NullPointerException
- Given file name was null
java.io.FileNotFoundException
- Given file does not existpublic void readXML(java.io.File file) throws java.io.IOException
Hashtable
may be read from a file.
Error is reported via IOException
. This is convenience method in addition to
read(InputStream)
in order to make programmer's life easier.
file
- XML file to import datajava.io.IOException
- An I/O error occurredjava.lang.NullPointerException
- Given file name was null
java.io.FileNotFoundException
- Given file does not existpublic void readXML(org.apache.commons.vfs2.FileObject file) throws java.io.IOException
Hashtable
may be read from a file.
Error is reported via IOException
. This is convenience method in addition to
read(InputStream)
in order to make programmer's life easier.
file
- VFS XML file to import datajava.io.IOException
- An I/O error occurredjava.lang.NullPointerException
- Given file name was null
org.apache.commons.vfs2.FileSystemException
- Given file does not existpublic void readXML(java.io.InputStream istream) throws java.io.IOException
Hashtable
may be read from a stream.
Error is reported via IOException
. This is the low-level functionality
repsonsible for the reading. The optional compression is auto-detected by the routine and
then set for the configuration so writing the config later will use the same compression.
The same is the case for the encoding which is UTF-8 Unicode encoding by default
in order to keep compatibility with the Properties
class. If a special header
entry for the encoding is found this is used for the deserialization of the configuration.
Also the encoding is set for the configuration so writing the config later will use the
same encoding.
istream
- The byte based XML stream to be read from, never closedjava.io.IOException
- An I/O error occurredjava.lang.NullPointerException
- Given stream was null
java.lang.IllegalArgumentException
- XML data errorpublic static java.lang.String readConvertProperties(java.lang.String theString)
public void write(java.lang.String filename) throws java.io.IOException
Hashtable
may be stored to a file.
Error is reported via IOException
. This is convenience method in addition to
write(OutputStream)
in order to make programmer's life easier.
We don't test here if the given file does exist because we then would have to let the user
choose if he/she wants to override it or not. For that we would have to integrate GUI
functionality and it's always better to separate this from other functionality. You can do
this testing before calling this method with help of File.exists()
.
filename
- Name of the file to store data injava.io.IOException
- An I/O error occurredpublic void write(java.io.File file) throws java.io.IOException
Hashtable
may be stored to a file.
Error is reported via IOException
. This is convenience method in addition to
write(OutputStream)
in order to make programmer's life easier.
We don't test here if the given file does exist because we then would have to let the user
choose if he/she wants to override it or not. For that we would have to integrate GUI
functionality and it's always better to separate this from other functionality. You can do
this testing before calling this method with help of File.exists()
.
file
- File to store data injava.io.IOException
- An I/O error occurredpublic void write(org.apache.commons.vfs2.FileObject file) throws java.io.IOException
Hashtable
may be stored to a file.
Error is reported via IOException
. This is convenience method in addition to
write(OutputStream)
in order to make programmer's life easier.
We don't test here if the given file does exist because we then would have to let the user
choose if he/she wants to override it or not. For that we would have to integrate GUI
functionality and it's always better to separate this from other functionality. You can do
this testing before calling this method with help of File.exists()
.
file
- VFS file to store data injava.io.IOException
- An I/O error occurredorg.apache.commons.vfs2.FileSystemException
- An VFS error occurredpublic void write(java.io.OutputStream ostream) throws java.io.IOException
Hashtable
may be stored to a file.
Error is reported via IOException
. The stream is not closed after the writing
is finished. The given output stream could be of any of the common types, but also keep
in mind that according to the current compression setting the stream will be filled already
with either GZIPPED or DEFLATED binary data. An additional compression stream is not
necessary in these cases. Use the setCompression()
method to adjust this
setting. The normal mode is to write UNCOMPRESSED to the stream. If the encoding is set
to ENCODING_ISO_8859_1_UNICODE_ESCAPES
and a variable value contains the new
line character then all appearances are replaced by the sequence '\n'. These sequences
are later restored automatically so that it is possible to deal with multi-line strings.
ostream
- Byte based output stream with a certain encodingjava.io.IOException
- An I/O error occurredpublic void writeXML(java.lang.String filename) throws java.io.IOException
Hashtable
may be stored to a file.
Error is reported via IOException
. This is convenience method in addition to
writeXML(OutputStream)
in order to make programmer's life easier.
We don't test here if the given file does exist because we then would have to let the user
choose if he/she wants to override it or not. For that we would have to integrate GUI
functionality and it's always better to separate this from other functionality. You can do
this testing before calling this method with help of File.exists()
.
filename
- Name of the XML file to store data injava.io.IOException
- An I/O error occurredpublic void writeXML(java.io.File file) throws java.io.IOException
Hashtable
may be stored to a file.
Error is reported via IOException
. This is convenience method in addition to
writeXML(OutputStream)
in order to make programmer's life easier.
We don't test here if the given file does exist because we then would have to let the user
choose if he/she wants to override it or not. For that we would have to integrate GUI
functionality and it's always better to separate this from other functionality. You can do
this testing before calling this method with help of File.exists()
.
file
- XML file to store data injava.io.IOException
- An I/O error occurredpublic void writeXML(org.apache.commons.vfs2.FileObject file) throws java.io.IOException
Hashtable
may be stored to a file.
Error is reported via IOException
. This is convenience method in addition to
writeXML(OutputStream)
in order to make programmer's life easier.
We don't test here if the given file does exist because we then would have to let the user
choose if he/she wants to override it or not. For that we would have to integrate GUI
functionality and it's always better to separate this from other functionality. You can do
this testing before calling this method with help of File.exists()
.
file
- VFS XML file to store data injava.io.IOException
- An I/O error occurredorg.apache.commons.vfs2.FileSystemException
- An VFS error occurredpublic void writeXML(java.io.OutputStream ostream) throws java.io.IOException
Hashtable
may be stored to a file.
Error is reported via IOException
. The stream is not closed after the writing
is finished. If the encoding is set to ENCODING_ISO_8859_1_UNICODE_ESCAPES
then UTF-8 is used as XML encoding in order to be fully compatible with the
Properties
class. The Unicode escapes make no sense for XML since we are
capable of writing line breaks and other special characters directly as element content.
Also we would have no chance to mark a file as being encoded with Unicode escapes since
this is no valid XML charset encoding. We would have to use "ISO-8859-1" instead but
then there would be no chance to distinguish between normal ISO 8859-1 and Unicode escaped
content since both use the same encoding identifier.
ostream
- Byte based XML output stream with a certain encodingjava.io.IOException
- An I/O error occurredpublic boolean setByte(java.lang.String variable, byte value)
byte
value of a variable.
If the variable already exists it will be overwritten.
variable
- Name of the variable to be storedvalue
- Variable valuepublic boolean setShort(java.lang.String variable, short value)
short
value of a variable.
If the variable already exists it will be overwritten.
variable
- Name of the variable to be storedvalue
- Variable valuepublic boolean setInt(java.lang.String variable, int value)
int
value of a variable.
If the variable already exists it will be overwritten.
variable
- Name of the variable to be storedvalue
- Variable valuepublic boolean setLong(java.lang.String variable, long value)
long
value of a variable.
If the variable already exists it will be overwritten.
variable
- Name of the variable to be storedvalue
- Variable valuepublic boolean setChar(java.lang.String variable, char value)
char
value of a variable.
If the variable already exists it will be overwritten.
variable
- Name of the variable to be storedvalue
- Variable valuepublic boolean setFloat(java.lang.String variable, float value)
float
value of a variable.
If the variable already exists it will be overwritten.
variable
- Name of the variable to be storedvalue
- Variable valuepublic boolean setDouble(java.lang.String variable, double value)
double
value of a variable.
If the variable already exists it will be overwritten.
variable
- Name of the variable to be storedvalue
- Variable valuepublic boolean setBoolean(java.lang.String variable, boolean value)
boolean
value of a variable.
If the variable already exists it will be overwritten.
variable
- Name of the variable to be storedvalue
- Variable valuepublic boolean setObject(java.lang.String variable, java.lang.Object value)
TypeHandler
interface and call this
method. You may also overwrite any of the default type handlers (e.g. for
java.lang.String
) if they do not fulfill your special needs. Simply set the
new handler, the installed one will be substituted automatically.
You may pass a null
value reference in order to have the variable be part of
the configuration anyway. If you do so the string null
will be written to the
configuration cache and then decoded as null
reference again if you call
the get()
method later. This behaviour seems to be more convenient for using
this class since there is no need for special exception handling while adding variables.
Remember that it's up to the handler to decide whether the variable should be store as
a single variable or if it's better to multiplex the variable into multiple variables.
In addition to that a variable value can be stored as binary embedded in some encoded
format like UUENCODE. Passwords could be stored in encrypted format like PGP as well.
variable
- Name of the variable to be storedvalue
- Variable valuejava.lang.IllegalArgumentException
- Error indicationTypeHandler
public boolean isTypeSupported(java.lang.String type)
type
- Variable type to be checkedjava.lang.NullPointerException
- Given type was null
isTypeSupported(Class)
public boolean isTypeSupported(java.lang.Class clazz)
clazz
- Variable type to be checkedjava.lang.NullPointerException
- Given class was null
isTypeSupported(String)
public java.lang.String[] getSupportedTypes()
getSupportedClassTypes()
public java.lang.Class[] getSupportedClassTypes()
getSupportedTypes()
public byte getByte(java.lang.String variable) throws java.lang.IllegalArgumentException
byte
value of a variable.
variable
- Name of the variablejava.lang.IllegalArgumentException
- Error indicationpublic byte getByte(java.lang.String variable, byte fallback)
byte
value of a variable.
variable
- Name of the variablefallback
- The default valuepublic short getShort(java.lang.String variable) throws java.lang.IllegalArgumentException
short
value of a variable.
variable
- Name of the variablejava.lang.IllegalArgumentException
- Error indicationpublic short getShort(java.lang.String variable, short fallback)
short
value of a variable.
variable
- Name of the variablefallback
- The default valuepublic int getInt(java.lang.String variable) throws java.lang.IllegalArgumentException
int
value of a variable.
variable
- Name of the variablejava.lang.IllegalArgumentException
- Error indicationpublic int getInt(java.lang.String variable, int fallback)
int
value of a variable.
variable
- Name of the variablefallback
- The default valuepublic long getLong(java.lang.String variable) throws java.lang.IllegalArgumentException
long
value of a variable.
variable
- Name of the variablejava.lang.IllegalArgumentException
- Error indicationpublic long getLong(java.lang.String variable, long fallback)
long
value of a variable.
variable
- Name of the variablefallback
- The default valuepublic char getChar(java.lang.String variable) throws java.lang.IllegalArgumentException
char
value of a variable.
variable
- Name of the variablejava.lang.IllegalArgumentException
- Error indicationpublic char getChar(java.lang.String variable, char fallback)
char
value of a variable.
variable
- Name of the variablefallback
- The default valuepublic float getFloat(java.lang.String variable) throws java.lang.IllegalArgumentException
float
value of a variable.
variable
- Name of the variablejava.lang.IllegalArgumentException
- Error indicationpublic float getFloat(java.lang.String variable, float fallback)
float
value of a variable.
variable
- Name of the variablefallback
- The default valuepublic double getDouble(java.lang.String variable) throws java.lang.IllegalArgumentException
double
value of a variable.
variable
- Name of the variablejava.lang.IllegalArgumentException
- Error indicationpublic double getDouble(java.lang.String variable, double fallback)
double
value of a variable.
variable
- Name of the variablefallback
- The default valuepublic boolean getBoolean(java.lang.String variable) throws java.lang.IllegalArgumentException
boolean
value of a variable.
variable
- Name of the variablejava.lang.IllegalArgumentException
- Error indicationpublic boolean getBoolean(java.lang.String variable, boolean fallback)
boolean
value of a variable.
variable
- Name of the variablefallback
- The default valuepublic java.lang.Object getObject(java.lang.String variable, java.lang.String type) throws java.lang.IllegalArgumentException
TypeHandler
interface and call this method. You may
also overwrite any of the default type handlers (e.g. for java.lang.String
)
if they do not fulfill your special needs. Simply set the new handler, the installed one
will be substituted automatically.
You may receive a null
value reference if either the variable does not exist
or the null
value was explicitely stored before. This behaviour seems to be
more convenient for using this class since there is no need for special exception handling
while adding variables.
Remember that it's up to the handler to decide whether the variable should be store as
a single variable or if it's better to multiplex the variable into multiple variables.
In addition to that a variable value can be stored as binary embedded in some encoded
format like UUENCODE. Passwords could be stored in encrypted format like PGP as well.
Remember that null
objects can be stored without problems by adding the string
"null". If your program wants to store the string "null" this must be escaped somehow so
that the getter method does not return a null
object reference.
variable
- Name of the desired variabletype
- Object type of the return valuejava.lang.IllegalArgumentException
- Error indicationgetObject(String, Class)
public java.lang.Object getObject(java.lang.String variable, java.lang.String type, java.lang.Object fallback)
variable
- Name of the variabletype
- Object type of the return valuefallback
- The default valuepublic java.lang.Object getObject(java.lang.String variable, java.lang.Class clazz) throws java.lang.IllegalArgumentException
get(variable, clazz.getName())
.
variable
- Name of the desired variableclazz
- Class type of the return valuejava.lang.IllegalArgumentException
- Error indicationgetObject(String, String)
public java.lang.Object getObject(java.lang.String variable, java.lang.Class clazz, java.lang.Object fallback)
get(variable, clazz.getName(), fallback)
.
variable
- Name of the variableclazz
- Class type of the return valuefallback
- The default valuepublic java.util.Enumeration<java.lang.String> getVariables()
public java.util.Hashtable<java.lang.String,java.lang.String> getCache()
public java.util.Hashtable<java.lang.String,TypeHandler> getHandlers()
public void setCompression(java.lang.String compression)
COMPRESSION_GZIPPED
or COMPRESSION_DEFLATED
.
compression
- Compression algorithm, COMPRESSION_UNCOMPRESSED
is defaultjava.lang.IllegalArgumentException
- The compression is not supportedpublic java.lang.String getCompression()
COMPRESSION_GZIPPED
or COMPRESSION_DEFLATED
.
COMPRESSION_UNCOMPRESSED
is defaultpublic void setEncoding(java.lang.String encoding) throws java.io.UnsupportedEncodingException
Properties
class (Unicode escapes like ?
). If you
wish to reset to this default mode simply set the null
reference then. If
you like the export files be in another encoding like UTF-8 or ISO-8859-1, then pass the
IANA charset name. The i18n
package provides support for getting all the
currently defined encodings (aka charsets).
Remember that only the default encoding Unicode escapes properly handles the full character
range 0-64K since some encodings like UTF-8 are not capable of encoding all available
characters. The surrogate block D800 - DFFF is not converted by UTF-8 and others but
only replaced by the '?' character (decimal 63). You will find a loss of information
when you use such encodings with invalid character data. To avoid this situation always
use the Unicode Escapes default encoding for both Properties and XML format.
encoding
- The file encoding, ENCODING_ISO_8859_1_UNICODE_ESCAPES
is defaultjava.io.UnsupportedEncodingException
- The given encoding is not supported by the JVMpublic java.lang.String getEncoding()
Properties
class (Unicode escapes like ?
). The
i18n
package provides support for getting all the currently defined encodings
(aka charsets).
Remember that only the default encoding Unicode escapes properly handles the full character
range 0-64K since some encodings like UTF-8 are not capable of encoding all available
characters. The surrogate block D800 - DFFF is not converted by UTF-8 and others but
only replaced by the '?' character (decimal 63). You will find a loss of information
when you use such encodings with invalid character data. To avoid this situation always
use the Unicode Escapes default encoding for both Properties and XML format.
ENCODING_ISO_8859_1_UNICODE_ESCAPES
is defaultpublic void setComment(java.lang.String comment)
comment
- Header comment for written files, null
is allowed (no comment)public java.lang.String getComment()
null
is allowed (no comment)public void setSorting(boolean sorting)
write()
methods.
sorting
- Enable/disable sorting for written filespublic boolean isSorting()
write()
methods.
public boolean contains(java.lang.String variable)
Hashtable
.
variable
- Name of the variable to be testedpublic boolean remove(java.lang.String variable)
variable
- Name of the variable to be removedpublic int removeStartsWith(java.lang.String prefix)
prefix
- The prefix of the variables to be removedpublic int size()
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- The reference object with which to comparetrue
if this object is the same as the obj argument; false
otherwisepublic boolean isEmpty()
public void setSecure(CryptoManager manager, java.lang.String keyuserid)
manager
- The manager responsible for encryption/decryption, null
disableskeyuserid
- The user ID of the encryption/decryption key, required if manager is setjava.lang.NullPointerException
- If a parameter is null
java.lang.IllegalStateException
- If the secure feature is already enabledpublic void setSecure(PassphraseProvider provider, java.lang.String keyuserid)
provider
- The provider for the AES key, null
disableskeyuserid
- The ID of the encryption/decryption key, required if manager is setjava.lang.NullPointerException
- If a parameter is null
java.lang.IllegalStateException
- If the secure feature is already enabledpublic boolean isSecure()
public void setOrdered(boolean enable)
enable
- Use the ordered cache?java.lang.NullPointerException
- If a parameter is null
java.lang.IllegalStateException
- If the secure feature is already enabledpublic boolean isOrdered()
public void setClearBeforeRead(boolean clear)
true
)?
clear
- Clear cache before new data is read?public boolean getClearBeforeRead()
Copyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.