当前位置: 首页>>代码示例>>Java>>正文


Java FilePersistenceStrategy类代码示例

本文整理汇总了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());
}
 
开发者ID:sunlin901203,项目名称:example-java,代码行数:26,代码来源:XStreamExample.java

示例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;
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:9,代码来源:PersistenceTest.java

示例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);
}
 
开发者ID:x-stream,项目名称:xstream,代码行数:7,代码来源:PersistenceTest.java


注:本文中的com.thoughtworks.xstream.persistence.FilePersistenceStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。