Class FilePersistenceStrategy
- java.lang.Object
-
- com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
-
- com.thoughtworks.xstream.persistence.FilePersistenceStrategy
-
- All Implemented Interfaces:
PersistenceStrategy
public class FilePersistenceStrategy extends AbstractFilePersistenceStrategy
PersistenceStrategy to assign keys with single value to objects persisted in files. The default naming strategy is based on the key's type and itsSingleValueConverter. It escapes all characters that are normally illegal in the most common file systems. Such a character is escaped with percent escaping as it is done by URL encoding. The XStream used to marshal the values is also requested for the key's SingleValueConverter. AConversionExceptionis thrown if no such converter is registered.- Since:
- 1.3.1
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
AbstractFilePersistenceStrategy.ValidFilenameFilter, AbstractFilePersistenceStrategy.XmlMapEntriesIterator
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringillegalChars
-
Constructor Summary
Constructors Constructor Description FilePersistenceStrategy(java.io.File baseDirectory)Create a new FilePersistenceStrategy.FilePersistenceStrategy(java.io.File baseDirectory, XStream xstream)Create a new FilePersistenceStrategy with a provided XStream instance.FilePersistenceStrategy(java.io.File baseDirectory, XStream xstream, java.lang.String encoding, java.lang.String illegalChars)Create a new FilePersistenceStrategy with a provided XStream instance and the characters to encode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Stringescape(java.lang.String key)protected java.lang.ObjectextractKey(java.lang.String name)Given a filename, the unescape method returns the key which originated it.protected java.lang.StringgetName(java.lang.Object key)Given a key, the escape method returns the filename which shall be used.protected booleanisValid(java.io.File dir, java.lang.String name)protected java.lang.Stringunescape(java.lang.String name)-
Methods inherited from class com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
containsKey, get, getConverterLookup, getMapper, iterator, put, remove, size
-
-
-
-
Constructor Detail
-
FilePersistenceStrategy
public FilePersistenceStrategy(java.io.File baseDirectory)
Create a new FilePersistenceStrategy. Use a standard XStream instance with aDomDriver.- Parameters:
baseDirectory- the directory for the serialized values- Since:
- 1.3.1
-
FilePersistenceStrategy
public FilePersistenceStrategy(java.io.File baseDirectory, XStream xstream)Create a new FilePersistenceStrategy with a provided XStream instance.- Parameters:
baseDirectory- the directory for the serialized valuesxstream- the XStream instance to use for (de)serialization- Since:
- 1.3.1
-
FilePersistenceStrategy
public FilePersistenceStrategy(java.io.File baseDirectory, XStream xstream, java.lang.String encoding, java.lang.String illegalChars)Create a new FilePersistenceStrategy with a provided XStream instance and the characters to encode.- Parameters:
baseDirectory- the directory for the serialized valuesxstream- the XStream instance to use for (de)serializationencoding- encoding used to write the filesillegalChars- illegal characters for file names (should always include '%' as long as you do not overwrite the (un)escape methods)- Since:
- 1.3.1
-
-
Method Detail
-
isValid
protected boolean isValid(java.io.File dir, java.lang.String name)- Overrides:
isValidin classAbstractFilePersistenceStrategy
-
extractKey
protected java.lang.Object extractKey(java.lang.String name)
Given a filename, the unescape method returns the key which originated it.- Specified by:
extractKeyin classAbstractFilePersistenceStrategy- Parameters:
name- the filename- Returns:
- the original key
-
unescape
protected java.lang.String unescape(java.lang.String name)
-
getName
protected java.lang.String getName(java.lang.Object key)
Given a key, the escape method returns the filename which shall be used.- Specified by:
getNamein classAbstractFilePersistenceStrategy- Parameters:
key- the key- Returns:
- the desired and escaped filename
-
escape
protected java.lang.String escape(java.lang.String key)
-
-