/** * Return an empty node of the most appropriate type for this loader, using the default options. * * @return The appropriate node type */ default NodeType createEmptyNode() { return createEmptyNode(getDefaultOptions()); }
/** * Create a new configuration node populated with the appropriate data. * * @return The newly constructed node * @throws java.io.IOException if any sort of error occurs with reading or parsing the configuration */ default NodeType load() throws IOException { return load(getDefaultOptions()); }
/** * Return an empty node of the most appropriate type for this loader, using the default options. * * @return The appropriate node type */ @NonNull default NodeType createEmptyNode() { return createEmptyNode(getDefaultOptions()); }
/** * Return an empty node of the most appropriate type for this loader, using the default options. * * @return The appropriate node type */ @NonNull default NodeType createEmptyNode() { return createEmptyNode(getDefaultOptions()); }
/** * Attempts to load a {@link ConfigurationNode} using this loader, from the defined source. * * <p>The resultant node represents the root of the configuration being loaded.</p> * * <p>The {@link #getDefaultOptions() default options} will be used to construct the resultant * configuration nodes.</p> * * @return The newly constructed node * @throws IOException if any sort of error occurs with reading or parsing the configuration */ @NonNull default NodeType load() throws IOException { return load(getDefaultOptions()); }
/** * Attempts to load a {@link ConfigurationNode} using this loader, from the defined source. * * <p>The resultant node represents the root of the configuration being loaded.</p> * * <p>The {@link #getDefaultOptions() default options} will be used to construct the resultant * configuration nodes.</p> * * @return The newly constructed node * @throws IOException if any sort of error occurs with reading or parsing the configuration */ @NonNull default NodeType load() throws IOException { return load(getDefaultOptions()); }
@Test public void testLoadingFileWithEmptyObject(@TempDirectory.TempDir Path tempDir) throws IOException { URL url = getClass().getResource("/emptyObject.json"); final Path tempFile = tempDir.resolve("text4.txt"); 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()); }
@Test public void testSimpleLoading(@TempDirectory.TempDir Path tempDir) throws IOException { URL url = getClass().getResource("/example.json"); final Path tempFile = tempDir.resolve("text1.txt"); 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)); }