本文整理汇总了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));
}
示例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));
}
示例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));
}
示例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();
}
示例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());
}
示例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());
}