Top Description Fields Constructors Methods
com.thoughtworks.xstream.persistence

public Class FilePersistenceStrategy

extends AbstractFilePersistenceStrategy
Class Inheritance
Imports
java.io.File, com.thoughtworks.xstream.XStream, com.thoughtworks.xstream.converters.ConversionException, .Converter, .SingleValueConverter, com.thoughtworks.xstream.io.xml.DomDriver

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.
Authors
Jörg Schaible, Guilherme Silveira
Since
1.3.1

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public
FilePersistenceStrategy(final File
the directory for the serialized values
baseDirectory
)

Create a new FilePersistenceStrategy.

public
FilePersistenceStrategy(final File
the directory for the serialized values
baseDirectory
,
final XStream
the XStream instance to use for (de)serialization
xstream
)

Create a new FilePersistenceStrategy with a provided XStream instance.

public
FilePersistenceStrategy(final File
the directory for the serialized values
baseDirectory
,
final XStream
the XStream instance to use for (de)serialization
xstream
,
final String
encoding used to write the files
encoding
,
final String
illegal characters for file names (should always include '%' as long as you do not overwrite the (un)escape methods)
illegalChars
)

Create a new FilePersistenceStrategy with a provided XStream instance and the characters to encode.

Method Summary

Modifier and TypeMethod and Description
protected String
escape(final String key)

protected Object

Returns:

the original key
extractKey
(final String
the filename
name
)

Implements abstract com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy.extractKey.

Given a filename, the unescape method returns the key which originated it.
protected String

Returns:

the desired and escaped filename
getName
(final Object
the key
key
)

Implements abstract com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy.getName.

Given a key, the escape method returns the filename which shall be used.
protected boolean
protected String
Inherited from com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy:
containsKeygetgetConverterLookupgetMapperiteratorputremovesize

Field Detail

illegalCharsback to summary
private final String illegalChars

Constructor Detail

FilePersistenceStrategyback to summary
public FilePersistenceStrategy(final File baseDirectory)

Create a new FilePersistenceStrategy. Use a standard XStream instance with a DomDriver.

Parameters
baseDirectory:File

the directory for the serialized values

Since
1.3.1
FilePersistenceStrategyback to summary
public FilePersistenceStrategy(final File baseDirectory, final XStream xstream)

Create a new FilePersistenceStrategy with a provided XStream instance.

Parameters
baseDirectory:File

the directory for the serialized values

xstream:XStream

the XStream instance to use for (de)serialization

Since
1.3.1
FilePersistenceStrategyback to summary
public FilePersistenceStrategy(final File baseDirectory, final XStream xstream, final String encoding, final String illegalChars)

Create a new FilePersistenceStrategy with a provided XStream instance and the characters to encode.

Parameters
baseDirectory:File

the directory for the serialized values

xstream:XStream

the XStream instance to use for (de)serialization

encoding:String

encoding used to write the files

illegalChars:String

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

escapeback to summary
protected String escape(final String key)
extractKeyback to summary
protected Object extractKey(final String name)

Implements abstract com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy.extractKey.

Given a filename, the unescape method returns the key which originated it.

Parameters
name:String

the filename

Returns:Object

the original key

getNameback to summary
protected String getName(final Object key)

Implements abstract com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy.getName.

Given a key, the escape method returns the filename which shall be used.

Parameters
key:Object

the key

Returns:String

the desired and escaped filename

isValidback to summary
protected boolean isValid(final File dir, final String name)

Overrides com.thoughtworks.xstream.persistence.AbstractFilePersistenceStrategy.isValid.

unescapeback to summary
protected String unescape(String name)