| 28 | } |
| 29 | |
| 30 | public static Config from(Path path) { |
| 31 | Require.nonNull("Path to read from", path); |
| 32 | |
| 33 | if (!Files.exists(path)) { |
| 34 | throw new ConfigException("Path to read from does not exist: " + path); |
| 35 | } |
| 36 | |
| 37 | String fileName = path.getFileName().toString(); |
| 38 | if (fileName.endsWith(".tml") || fileName.endsWith(".toml")) { |
| 39 | return TomlConfig.from(path); |
| 40 | } |
| 41 | |
| 42 | if (fileName.endsWith(".json")) { |
| 43 | return JsonConfig.from(path); |
| 44 | } |
| 45 | |
| 46 | throw new ConfigException( |
| 47 | "Unable to determine file type. The file extension must be one of '.toml' or '.json' " |
| 48 | + path); |
| 49 | } |
| 50 | } |