mirror of
https://github.com/lightbend/config.git
synced 2025-03-22 15:20:26 +08:00
Address some more PR feedback
Make the javadoc string for the ConfigDocument interface more explicit about what it does with the value string when setting a value. Add support for parsing a reader into a ConfigDocument.
This commit is contained in:
parent
28a096f157
commit
c3a2e07c6a
@ -24,7 +24,9 @@ public interface ConfigDocument {
|
|||||||
* at the final occurrence of the path. If the path does not exist, it will be added.
|
* at the final occurrence of the path. If the path does not exist, it will be added.
|
||||||
*
|
*
|
||||||
* @param path the path at which to set the desired value
|
* @param path the path at which to set the desired value
|
||||||
* @param newValue the value to set at the desired path
|
* @param newValue the value to set at the desired path, represented as a string. This
|
||||||
|
* string will be parsed into a ConfigNode, and the text will be inserted
|
||||||
|
* as-is into the document, with leading and trailing whitespace removed.
|
||||||
* @return a copy of the ConfigDocument with the desired value at the desired path
|
* @return a copy of the ConfigDocument with the desired value at the desired path
|
||||||
*/
|
*/
|
||||||
ConfigDocument setValue(String path, String newValue);
|
ConfigDocument setValue(String path, String newValue);
|
||||||
|
@ -4,6 +4,7 @@ import com.typesafe.config.impl.ConfigImpl;
|
|||||||
import com.typesafe.config.impl.Parseable;
|
import com.typesafe.config.impl.Parseable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.Reader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory for automatically creating a ConfigDocument from a given input. Currently
|
* Factory for automatically creating a ConfigDocument from a given input. Currently
|
||||||
@ -11,6 +12,34 @@ import java.io.File;
|
|||||||
*/
|
*/
|
||||||
public final class ConfigDocumentFactory {
|
public final class ConfigDocumentFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a Reader into a ConfigDocument instance.
|
||||||
|
*
|
||||||
|
* @param reader
|
||||||
|
* the reader to parse
|
||||||
|
* @param options
|
||||||
|
* parse options to control how the reader is interpreted
|
||||||
|
* @return the parsed configuration
|
||||||
|
* @throws ConfigException on IO or parse errors
|
||||||
|
*/
|
||||||
|
public static ConfigDocument parseReader(Reader reader, ConfigParseOptions options) {
|
||||||
|
return Parseable.newReader(reader, options).parseConfigDocument();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a reader into a Config instance as with
|
||||||
|
* {@link #parseReader(Reader,ConfigParseOptions)} but always uses the
|
||||||
|
* default parse options.
|
||||||
|
*
|
||||||
|
* @param reader
|
||||||
|
* the reader to parse
|
||||||
|
* @return the parsed configuration
|
||||||
|
* @throws ConfigException on IO or parse errors
|
||||||
|
*/
|
||||||
|
public static ConfigDocument parseReader(Reader reader) {
|
||||||
|
return parseReader(reader, ConfigParseOptions.defaults());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a file into a ConfigDocument instance.
|
* Parses a file into a ConfigDocument instance.
|
||||||
*
|
*
|
||||||
|
@ -198,4 +198,11 @@ class ConfigDocumentTest extends TestUtils {
|
|||||||
val fileText = sb.toString()
|
val fileText = sb.toString()
|
||||||
assertEquals(fileText, configDocument.render())
|
assertEquals(fileText, configDocument.render())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
def configDocumentReaderParse {
|
||||||
|
val configDocument = ConfigDocumentFactory.parseReader(new FileReader(resourceFile("/test03.conf")))
|
||||||
|
val configDocumentFile = ConfigDocumentFactory.parseFile(resourceFile("/test03.conf"))
|
||||||
|
assertEquals(configDocumentFile.render(), configDocument.render())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user