Package totalcross.util
Class Properties
- java.lang.Object
-
- totalcross.util.Properties
-
- Direct Known Subclasses:
MailSession,Options
public class Properties extends java.lang.ObjectUsed to store properties pairs (key,value). A hashtable is used to store them. Currently, the key must be a String and the value must be a Value The properties can be saved and loaded to/from a DataStream. Here's a sample:Properties props = new Properties(); File file; //*************************************** // load properties that already exists //*************************************** if (existe_arquivo(arquivo)) { file = new File(arquivo, File.READ_WRITE); props.load(new DataStream(file)); file.close(); } //*************************************** props.put(propriedade,new Properties.Str(valor)); file = new File(arquivo, File.CREATE); props.save(new DataStream(file)); file.close();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classProperties.BooleanImplements a value of type booleanstatic classProperties.DoubleImplements a value of type doublestatic classProperties.IntImplements a value of type intstatic classProperties.LongImplements a value of type longstatic classProperties.StrImplements a value of type Stringstatic classProperties.ValueRepresents a generic value that can be stored here.
-
Field Summary
Fields Modifier and Type Field Description static intMAX_PROPSAvoids that the load method gets into an infinite loop if the file is empty or corrupted.
-
Constructor Summary
Constructors Constructor Description Properties()Properties(java.lang.String[] keys, Properties.Value[] values)Stores the given keys/values pairs in a new Properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears this propertyjava.lang.StringBufferdumpKeysValues(java.lang.StringBuffer sb, java.lang.String keyvalueSeparator, java.lang.String lineSeparator)Dumps the keys and values into the given StringBuffer.Properties.Valueget(java.lang.String key)Get the value given the key from the hashtable that stores the properties.VectorgetKeys()Returns a Vector with the current keysvoidload(DataStream ds)Load all properties from the given DataStream.voidload(DataStream ds, boolean cleanBeforeLoad)Load properties from the given DataStream.voidput(java.lang.String key, Properties.Value v)Put the given key/value pair in the hashtable that stores the properties.voidremove(java.lang.String key)Remove a value from the propertyvoidsave(DataStream ds)Save all properties in the given DataStreamintsize()Returns the number of properties
-
-
-
Constructor Detail
-
Properties
public Properties()
-
Properties
public Properties(java.lang.String[] keys, Properties.Value[] values)Stores the given keys/values pairs in a new Properties.
-
-
Method Detail
-
put
public void put(java.lang.String key, Properties.Value v)Put the given key/value pair in the hashtable that stores the properties.
-
get
public Properties.Value get(java.lang.String key)
Get the value given the key from the hashtable that stores the properties.
-
size
public int size()
Returns the number of properties
-
getKeys
public Vector getKeys()
Returns a Vector with the current keys
-
clear
public void clear()
Clears this property
-
remove
public void remove(java.lang.String key)
Remove a value from the property
-
save
public void save(DataStream ds) throws IOException
Save all properties in the given DataStream- Throws:
IOException
-
load
public void load(DataStream ds) throws IOException
Load all properties from the given DataStream. Before calling this method, be sure that there's something to be read (ie, that the file is not empty), otherwise it may run in an infinite loop and will freeze your device.- Throws:
IOException
-
load
public void load(DataStream ds, boolean cleanBeforeLoad) throws IOException
Load properties from the given DataStream. If cleanBeforeLoad is true, the contents of this object will be cleared before reading from the DataStream.- Parameters:
ds-cleanBeforeLoad-- Throws:
IOException
-
dumpKeysValues
public java.lang.StringBuffer dumpKeysValues(java.lang.StringBuffer sb, java.lang.String keyvalueSeparator, java.lang.String lineSeparator)Dumps the keys and values into the given StringBuffer. The values are dumped as Strings, exactly like the Hashtable implementation.- Parameters:
sb- The StringBuffer where the data will be dumped tokeyvalueSeparator- The separator between the key and the value (E.G.: ": ")lineSeparator- The separator placed after each key+value pair (E.G.: "\r\n"). The last separator is cut from the StringBuffer.- Returns:
- the received StringBuffer sb
- Since:
- TotalCross 1.25
-
-