001package com.typesafe.config.parser; 002 003import com.typesafe.config.ConfigParseOptions; 004 005import com.typesafe.config.impl.Parseable; 006 007import java.io.File; 008import java.io.Reader; 009 010/** 011 * Factory for creating {@link 012 * com.typesafe.config.parser.ConfigDocument} instances. 013 */ 014public final class ConfigDocumentFactory { 015 016 /** 017 * Parses a Reader into a ConfigDocument instance. 018 * 019 * @param reader 020 * the reader to parse 021 * @param options 022 * parse options to control how the reader is interpreted 023 * @return the parsed configuration 024 * @throws com.typesafe.config.ConfigException on IO or parse errors 025 */ 026 public static ConfigDocument parseReader(Reader reader, ConfigParseOptions options) { 027 return Parseable.newReader(reader, options).parseConfigDocument(); 028 } 029 030 /** 031 * Parses a reader into a Config instance as with 032 * {@link #parseReader(Reader,ConfigParseOptions)} but always uses the 033 * default parse options. 034 * 035 * @param reader 036 * the reader to parse 037 * @return the parsed configuration 038 * @throws com.typesafe.config.ConfigException on IO or parse errors 039 */ 040 public static ConfigDocument parseReader(Reader reader) { 041 return parseReader(reader, ConfigParseOptions.defaults()); 042 } 043 044 /** 045 * Parses a file into a ConfigDocument instance. 046 * 047 * @param file 048 * the file to parse 049 * @param options 050 * parse options to control how the file is interpreted 051 * @return the parsed configuration 052 * @throws com.typesafe.config.ConfigException on IO or parse errors 053 */ 054 public static ConfigDocument parseFile(File file, ConfigParseOptions options) { 055 return Parseable.newFile(file, options).parseConfigDocument(); 056 } 057 058 /** 059 * Parses a file into a ConfigDocument instance as with 060 * {@link #parseFile(File,ConfigParseOptions)} but always uses the 061 * default parse options. 062 * 063 * @param file 064 * the file to parse 065 * @return the parsed configuration 066 * @throws com.typesafe.config.ConfigException on IO or parse errors 067 */ 068 public static ConfigDocument parseFile(File file) { 069 return parseFile(file, ConfigParseOptions.defaults()); 070 } 071 072 /** 073 * Parses a string which should be valid HOCON or JSON. 074 * 075 * @param s string to parse 076 * @param options parse options 077 * @return the parsed configuration 078 */ 079 public static ConfigDocument parseString(String s, ConfigParseOptions options) { 080 return Parseable.newString(s, options).parseConfigDocument(); 081 } 082 083 /** 084 * Parses a string (which should be valid HOCON or JSON). Uses the 085 * default parse options. 086 * 087 * @param s string to parse 088 * @return the parsed configuration 089 */ 090 public static ConfigDocument parseString(String s) { 091 return parseString(s, ConfigParseOptions.defaults()); 092 } 093}