Class FilePersistenceStrategy
java.lang.Object
com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
com.thoughtworks.xstream.persistence.FilePersistenceStrategy
- All Implemented Interfaces:
PersistenceStrategy
PersistenceStrategy to assign keys with single value to objects persisted in files. The default naming strategy is
based on the key's type and its
SingleValueConverter
. 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. A
ConversionException
is 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 -
Constructor Summary
ConstructorsConstructorDescriptionFilePersistenceStrategy
(File baseDirectory) Create a new FilePersistenceStrategy.FilePersistenceStrategy
(File baseDirectory, XStream xstream) Create a new FilePersistenceStrategy with a provided XStream instance.FilePersistenceStrategy
(File baseDirectory, XStream xstream, String encoding, String illegalChars) Create a new FilePersistenceStrategy with a provided XStream instance and the characters to encode. -
Method Summary
Methods inherited from class com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy
containsKey, get, getConverterLookup, getMapper, iterator, put, remove, size
-
Field Details
-
illegalChars
-
-
Constructor Details
-
FilePersistenceStrategy
Create a new FilePersistenceStrategy. Use a standard XStream instance with aDomDriver
.- Parameters:
baseDirectory
- the directory for the serialized values- Since:
- 1.3.1
-
FilePersistenceStrategy
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(File baseDirectory, XStream xstream, String encoding, 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 Details
-
isValid
- Overrides:
isValid
in classAbstractFilePersistenceStrategy
-
extractKey
Given a filename, the unescape method returns the key which originated it.- Specified by:
extractKey
in classAbstractFilePersistenceStrategy
- Parameters:
name
- the filename- Returns:
- the original key
-
unescape
-
getName
Given a key, the escape method returns the filename which shall be used.- Specified by:
getName
in classAbstractFilePersistenceStrategy
- Parameters:
key
- the key- Returns:
- the desired and escaped filename
-
escape
-