本文整理汇总了Java中com.thoughtworks.xstream.persistence.FilePersistenceStrategy类的典型用法代码示例。如果您正苦于以下问题:Java FilePersistenceStrategy类的具体用法?Java FilePersistenceStrategy怎么用?Java FilePersistenceStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FilePersistenceStrategy类属于com.thoughtworks.xstream.persistence包,在下文中一共展示了FilePersistenceStrategy类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: xStreamPersistenceUsage
import com.thoughtworks.xstream.persistence.FilePersistenceStrategy; //导入依赖的package包/类
/**
* xStream持久化api
*/
@Test
public void xStreamPersistenceUsage() {
// 1、创建需要持久化的对象
ArrayList<UserModel> users = new ArrayList<UserModel>();
users.add(user);
// 2、创建持久化策略
String path = System.getProperty("user.dir") + "/target/out/";
LoggerTool.info("path is {}", path);
File directory = new File(path);
if (!directory.exists()) {
boolean flag = directory.mkdirs();
LoggerTool.info("mk dirs result is {}", flag);
}
PersistenceStrategy persistenceStrategy = new FilePersistenceStrategy(directory);
// 3、持久化集合对象
@SuppressWarnings("unchecked")
List<UserModel> list = new XmlArrayList(persistenceStrategy);
list.addAll(users);
LoggerTool.info("list size is {}", list.size());
}
示例2: unmarshal
import com.thoughtworks.xstream.persistence.FilePersistenceStrategy; //导入依赖的package包/类
public Object unmarshal(HierarchicalStreamReader reader,
UnmarshallingContext context) {
final File directory = (File)context.convertAnother(null, File.class);
final XmlArrayList persistentList = new XmlArrayList(new FilePersistenceStrategy(directory, xstream));
final ArrayList list = new ArrayList(persistentList);
//persistentList.clear(); // remove files
return list;
}
示例3: marshal
import com.thoughtworks.xstream.persistence.FilePersistenceStrategy; //导入依赖的package包/类
public void marshal(Object source, HierarchicalStreamWriter writer,
MarshallingContext context) {
final XmlArrayList list = new XmlArrayList(new FilePersistenceStrategy(dir, xstream));
context.convertAnother(dir);
list.addAll((Collection)source);
}