jimm.twice.util
Class Persistence

java.lang.Object
  extended byjimm.twice.util.Persistence

public class Persistence
extends java.lang.Object

This class is used to implement persistence. It uses the file system, creating a file for every key. The contents of the file are lines of text data. Within each line, values are separated by the SEPARATOR string. A few important simplifying assumptions:

This persistence mechanism is outside of the hierarchy of ICE classes because this particular persistence mechanism is very simplistic and should be replaced with something more robust (like a database) in real implementations.

Author:
Jim Menard, jimm@io.com

Field Summary
protected  java.lang.String dirPath
           
protected static java.lang.String SEPARATOR
           
 
Constructor Summary
Persistence(java.lang.String storageDirPath)
           
 
Method Summary
 java.io.BufferedReader getBufferedReader(java.lang.String key)
          Returns a collection containing lists of strings.
 java.io.FileInputStream getFileInputStream(java.lang.String key)
           
 java.io.FileOutputStream getFileOutputStream(java.lang.String key)
           
 java.io.PrintWriter getPrintWriter(java.lang.String key)
          Stores the lists contained within the values collection as lines within a file.
 boolean hasKey(java.lang.String key)
          Returns true if a permanent storage file already exists for the specified key.
 java.util.Set keySet()
          Returns a set containing all of the keys.
protected  java.lang.String makeSafe(java.lang.String key)
          Key values are mutated when used as file names.
 void remove(java.lang.String key)
          Removes the permanent storage associated with the specified key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR

protected static final java.lang.String SEPARATOR
See Also:
Constant Field Values

dirPath

protected java.lang.String dirPath
Constructor Detail

Persistence

public Persistence(java.lang.String storageDirPath)
Method Detail

hasKey

public boolean hasKey(java.lang.String key)
Returns true if a permanent storage file already exists for the specified key.


remove

public void remove(java.lang.String key)
Removes the permanent storage associated with the specified key. No harm done if there is no storage already.


keySet

public java.util.Set keySet()
Returns a set containing all of the keys. Returns an empty set if there are none.


getBufferedReader

public java.io.BufferedReader getBufferedReader(java.lang.String key)
Returns a collection containing lists of strings. Returns null if there is no file corresponding to the specified key.


getFileInputStream

public java.io.FileInputStream getFileInputStream(java.lang.String key)

getPrintWriter

public java.io.PrintWriter getPrintWriter(java.lang.String key)
Stores the lists contained within the values collection as lines within a file.


getFileOutputStream

public java.io.FileOutputStream getFileOutputStream(java.lang.String key)

makeSafe

protected java.lang.String makeSafe(java.lang.String key)
Key values are mutated when used as file names. Ever character that does not match [-_\.a-zA-Z0-9] is turned into an underscore.