things.data.impl
Class ThingsPropertyTrunkIO

java.lang.Object
  extended by things.data.impl.ThingsPropertyTrunkIO
All Implemented Interfaces:
ThingsPropertyTrunk

public class ThingsPropertyTrunkIO
extends java.lang.Object
implements ThingsPropertyTrunk

An IO implementation for a property trunk.

The id is the file path, which is the usual contract for a ThingsPropertyTrunk. However, you can also init() it yourself and use your own id. It uses readers through the Accessor, so it can come from any source and it should handle any character encoding. (NOTE: When using UTF-8 from a file, sometimes you have to deal with the marker yourself. Just try it and see what happens.)

THE RULES

Each property is a name/value pair, separated by a equal sign.
Comment lines start with a # and are ignored.
Lines can be continued with a backslash character '&'
Every line will be trimmed of whitespace, but intra-token whitespace will be preserved.
ThingsPropertyReaderToolkit determines any other encoding. It is assumed to be the default character set.

For values (right fo the first = sign) there are additional rules:
Escape with ?.
Separate multivalues with ,.
The , may be escaped with ?.
The = indicates equality. It may be escaped with the ?.

The value rules are inherited by ThingsPropertyReaderToolkit.decodeString.

Version:
1.0

Version History

EPG - Initial - 28 NOV 04
 
Author:
Erich P. Gatejen

Nested Class Summary
 
Nested classes/interfaces inherited from interface things.data.ThingsPropertyTrunk
ThingsPropertyTrunk.Mode
 
Constructor Summary
ThingsPropertyTrunkIO()
          Constructor.
 
Method Summary
 void endRead()
          End a read transfer.
 void endWrite()
          End a wrote transfer.
 ThingsPropertyTrunk.Mode getMode()
          Get the current Mode.
 void init(java.lang.String id, Accessor accessItem)
          Sets the ID.
 NV readNext()
          Read the next property.
 void startRead()
          Start a read.
 void startWrite()
          Start a write transfer.
 void writeNext(NVImmutable item)
          Write the next property
 void writeNext(java.lang.String name, java.lang.String value)
          Write the next property
 void writeNextMultivalue(java.lang.String name, java.lang.String... values)
          Write the next property that is a multivalue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThingsPropertyTrunkIO

public ThingsPropertyTrunkIO()
Constructor.

Method Detail

init

public void init(java.lang.String id,
                 Accessor accessItem)
          throws ThingsException
Sets the ID. It's really up to the implementation as to what the ID means. It may be ignored and all will be transfered.

Specified by:
init in interface ThingsPropertyTrunk
Parameters:
id - An id
accessItem - A way to read and write the data.
Throws:
ThingsException

getMode

public ThingsPropertyTrunk.Mode getMode()
Get the current Mode.

Specified by:
getMode in interface ThingsPropertyTrunk
Returns:
the Mode.

startRead

public void startRead()
               throws ThingsException
Start a read.

Specified by:
startRead in interface ThingsPropertyTrunk
Throws:
ThingsException

endRead

public void endRead()
             throws ThingsException
End a read transfer. If a read hasn't started, nothing bad will happen.

Specified by:
endRead in interface ThingsPropertyTrunk
Throws:
ThingsException

startWrite

public void startWrite()
                throws ThingsException
Start a write transfer.

Specified by:
startWrite in interface ThingsPropertyTrunk
Throws:
ThingsException

endWrite

public void endWrite()
              throws ThingsException
End a wrote transfer. If a write hasn't started, nothing bad will happen. It should flush and close the destination.

Specified by:
endWrite in interface ThingsPropertyTrunk
Throws:
ThingsException

writeNext

public void writeNext(java.lang.String name,
                      java.lang.String value)
               throws ThingsException
Write the next property

Specified by:
writeNext in interface ThingsPropertyTrunk
Parameters:
name - The property name as a string
value - The property value as a string
Throws:
ThingsException

writeNext

public void writeNext(NVImmutable item)
               throws ThingsException
Write the next property

Specified by:
writeNext in interface ThingsPropertyTrunk
Parameters:
item - the next property as an NVImmutable.
Throws:
ThingsException
See Also:
NVImmutable

writeNextMultivalue

public void writeNextMultivalue(java.lang.String name,
                                java.lang.String... values)
                         throws ThingsException
Write the next property that is a multivalue.

Specified by:
writeNextMultivalue in interface ThingsPropertyTrunk
Parameters:
name - The property name as a string
values - The property values
Throws:
ThingsException

readNext

public NV readNext()
            throws ThingsException
Read the next property. It will return null if there are none left.

Specified by:
readNext in interface ThingsPropertyTrunk
Returns:
NV
Throws:
ThingsException


Things.