org.biffle.cliff.pearl
Class PropSet

java.lang.Object
  |
  +--org.biffle.cliff.pearl.PropSet

public class PropSet
extends java.lang.Object

Encapsulates the 'properties files' used by Pearl devices for both device settings and file metadata. This version is immutable. The PropSet provides accessor methods for the properties in the set. It makes no attempt at determining the type of a given key, and instead provides accessors for the four types of properties (numeric, string, string list, and byte array). PropSets are typically stored in a textual representation. The format is simple: it consists of a series of newline-terminated lines, each of which contains a key, an equals sign ('='), and a value. The value can be numeric (such as '12' or '0x4A'), textual (such as 'Hello, World!'), binary (such as '\x00abc\x1Bef'), or a list of string tokens (such as ';bob;alice;jim;'). Though I've set the examples here in quotes for clarity, the quotes do not appear in the file. As noted in the binary example, any bytes that might interfere with text processing are escaped as '\xDD', where DD is the hex value of the byte. Primarily, bytes between 0x00 and 0x1B seem to be escaped.


Constructor Summary
PropSet(java.lang.String set)
          Creates a PropSet from its textual representation.
 
Method Summary
 boolean containsProperty(java.lang.String key)
          Checks if the PropSet contains a given property.
 byte[] getBytes(java.lang.String key)
          Returns the value of a property as a list of bytes.
 long getLong(java.lang.String key)
          Returns the value of a property as a long.
 java.lang.String getString(java.lang.String key)
          Returns the value of a property as a String.
 java.lang.String[] getStringList(java.lang.String key)
          Returns the value of a property as a list of Strings.
 java.util.Set keySet()
          Returns the property names as a Set.
 void setString(java.lang.String key, java.lang.String value)
           
 java.lang.String toString()
          Converts the PropSet to a textual representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PropSet

public PropSet(java.lang.String set)
Creates a PropSet from its textual representation.

Method Detail

keySet

public java.util.Set keySet()
Returns the property names as a Set.


containsProperty

public boolean containsProperty(java.lang.String key)
Checks if the PropSet contains a given property.


getLong

public long getLong(java.lang.String key)
Returns the value of a property as a long. If the content of the property cannot be parsed as a number, this method does not throw an exception -- it simply returns zero. Longs are parsed according to the rules set forth in Long.parseLong.


getString

public java.lang.String getString(java.lang.String key)
Returns the value of a property as a String. If the property doesn't exist, returns null.


getStringList

public java.lang.String[] getStringList(java.lang.String key)
Returns the value of a property as a list of Strings. If the content is not actually a string list or the property is not defined, this method returns null.


getBytes

public byte[] getBytes(java.lang.String key)
Returns the value of a property as a list of bytes. If the property is not defined, this method returns null.


setString

public void setString(java.lang.String key,
                      java.lang.String value)

toString

public java.lang.String toString()
Converts the PropSet to a textual representation. This representation preserves all data, and can be fed back into the constructor at a later date to exactly reproduce this object.

Overrides:
toString in class java.lang.Object