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


Java AtomicFiles类代码示例

本文整理汇总了Java中ninja.leaping.configurate.loader.AtomicFiles的典型用法代码示例。如果您正苦于以下问题:Java AtomicFiles类的具体用法?Java AtomicFiles怎么用?Java AtomicFiles使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AtomicFiles类属于ninja.leaping.configurate.loader包,在下文中一共展示了AtomicFiles类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSimpleLoading

import ninja.leaping.configurate.loader.AtomicFiles; //导入依赖的package包/类
@Test
public void testSimpleLoading() throws IOException {
    URL url = getClass().getResource("/example.json");
    final Path tempFile = folder.newFile().toPath();
    ConfigurationLoader loader = JSONConfigurationLoader.builder()
            .setSource(() -> new BufferedReader(new InputStreamReader(url.openStream(), UTF_8)))
                    .setSink(AtomicFiles.createAtomicWriterFactory(tempFile, UTF_8)).build();
    ConfigurationNode node = loader.load(ConfigurationOptions.defaults().setMapFactory(MapFactories.sortedNatural()));
    assertEquals("unicorn", node.getNode("test", "op-level").getValue());
    assertEquals("dragon", node.getNode("other", "op-level").getValue());
    assertEquals("dog park", node.getNode("other", "location").getValue());
    /*CommentedConfigurationNode commentNode = SimpleCommentedConfigurationNode.root();
    commentNode.getNode("childOne").setValue("a").setComment("Test comment");
    commentNode.getNode("childTwo", "something").setValue("b").setComment("Test comment 2");
    commentNode.getNode("childTwo", "another").setValue("b").setComment("Test comment 3");
    */
    loader.save(node);
    assertEquals(Resources.readLines(url, UTF_8), Files
            .readAllLines(tempFile, UTF_8));

}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:22,代码来源:JSONConfigurationLoaderTest.java

示例2: testSimpleLoading

import ninja.leaping.configurate.loader.AtomicFiles; //导入依赖的package包/类
@Test
public void testSimpleLoading() throws IOException {
    URL url = getClass().getResource("/example.conf");
    final Path saveTest = folder.newFile().toPath();

    HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
            .setSource(() -> new BufferedReader(new InputStreamReader(url.openStream(), UTF_8)))
            .setSink(AtomicFiles.createAtomicWriterFactory(saveTest, UTF_8)).build();
    CommentedConfigurationNode node = loader.load();
    assertEquals("unicorn", node.getNode("test", "op-level").getValue());
    assertEquals("dragon", node.getNode("other", "op-level").getValue());
    CommentedConfigurationNode testNode = node.getNode("test");
    assertEquals(" Test node", testNode.getComment().orElse(null));
    assertEquals("dog park", node.getNode("other", "location").getValue());
    loader.save(node);
    assertEquals(Resources.readLines(getClass().getResource("/roundtrip-test.conf"), UTF_8), Files
            .readAllLines(saveTest, UTF_8));
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:19,代码来源:HoconConfigurationLoaderTest.java

示例3: testSimpleLoading

import ninja.leaping.configurate.loader.AtomicFiles; //导入依赖的package包/类
@Test
public void testSimpleLoading() throws IOException {
    URL url = getClass().getResource("/example.json");
    final Path tempFile = folder.newFile().toPath();
    ConfigurationLoader<ConfigurationNode> loader = GsonConfigurationLoader.builder()
            .setSource(() -> new BufferedReader(new InputStreamReader(url.openStream())))
            .setSink(AtomicFiles.createAtomicWriterFactory(tempFile, UTF_8)).setLenient(true).build();
    ConfigurationNode node = loader.load(loader.getDefaultOptions().setMapFactory(MapFactories.sortedNatural()));
    assertEquals("unicorn", node.getNode("test", "op-level").getValue());
    assertEquals("dragon", node.getNode("other", "op-level").getValue());
    assertEquals("dog park", node.getNode("other", "location").getValue());
    assertTrue(node.getNode("int-val").getValue() instanceof Integer);
    assertTrue(node.getNode("double-val").getValue() instanceof Double);
    loader.save(node);
    assertEquals(Resources.readLines(url, UTF_8), Files.readAllLines(tempFile, UTF_8));
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:17,代码来源:GsonConfigurationLoaderTest.java

示例4: setPath

import ninja.leaping.configurate.loader.AtomicFiles; //导入依赖的package包/类
/**
 * A Path can be set to be used as a data source and sink.
 *
 * @param path the path to be used as the data source and sink.
 * @return this builder.
 */
@NotNull
public T setPath(@NotNull Path path) {
    this.source = () -> Files.newBufferedReader(path, UTF_8);
    this.sink = AtomicFiles.createAtomicWriterFactory(path, UTF_8);
    return self();
}
 
开发者ID:dumptruckman,项目名称:dtmlibs,代码行数:13,代码来源:AbstractDataSource.java

示例5: testThatConfigurationOptionsFunctionWorksAsExpected

import ninja.leaping.configurate.loader.AtomicFiles; //导入依赖的package包/类
/**
 * Test that changing the ConfigurationOptions via the function argument between loads works.
 *
 * @throws Exception I hope not!
 */
@Test
public void testThatConfigurationOptionsFunctionWorksAsExpected() throws Exception {
    URL url = getClass().getResource("/test.json");
    final Path tempFile = folder.newFile().toPath();
    ConfigurationLoader<ConfigurationNode> loader = GsonConfigurationLoader.builder()
            .setSource(() -> new BufferedReader(new InputStreamReader(url.openStream())))
            .setSink(AtomicFiles.createAtomicWriterFactory(tempFile, UTF_8)).setLenient(true).build();

    // Create the SimpleConfig
    SerialiserTransformer st = new SerialiserTransformer();
    SimpleConfig simpleConfig = new SimpleConfig(loader, () -> loader.createEmptyNode(st.apply(loader.getDefaultOptions())), st);

    Field field = AbstractAdaptableConfig.class.getDeclaredField("node");
    field.setAccessible(true);

    // The transformer shouldn't add any serialisers.
    simpleConfig.load();
    Assert.assertNull(((ConfigurationNode)field.get(simpleConfig)).getOptions().getSerializers().get(TypeToken.of(Dummy.class)));

    st.set = true;

    // The transformer shouldn't have added any serialisers yet.
    Assert.assertNull(((ConfigurationNode)field.get(simpleConfig)).getOptions().getSerializers().get(TypeToken.of(Dummy.class)));

    // It will on next load.
    simpleConfig.load();
    Assert.assertEquals(DummySerialiser.class, ((ConfigurationNode)field.get(simpleConfig)).getOptions().getSerializers().get(TypeToken.of(Dummy.class)).getClass());
}
 
开发者ID:NucleusPowered,项目名称:QuickStartModuleLoader,代码行数:34,代码来源:ConfigFileTests.java

示例6: testLoadingFileWithEmptyObject

import ninja.leaping.configurate.loader.AtomicFiles; //导入依赖的package包/类
@Test
public void testLoadingFileWithEmptyObject() throws IOException {
    URL url = getClass().getResource("/emptyObject.json");
    final Path tempFile = folder.newFile().toPath();
    ConfigurationLoader<ConfigurationNode> loader = GsonConfigurationLoader.builder()
            .setSource(() -> new BufferedReader(new InputStreamReader(url.openStream())))
            .setSink(AtomicFiles.createAtomicWriterFactory(tempFile, UTF_8)).setLenient(true).build();

    ConfigurationNode node = loader.load(loader.getDefaultOptions().setMapFactory(MapFactories.sortedNatural()));
    assertNull(node.getValue());
    assertFalse(node.hasMapChildren());
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:13,代码来源:GsonConfigurationLoaderTest.java


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