Package com.oracle.bmc
Class ConfigFileReader
- java.lang.Object
-
- com.oracle.bmc.ConfigFileReader
-
public final class ConfigFileReader extends Object
Simple implementation to read OCI configuration files.Note, config files MUST contain a "DEFAULT" profile, else validation will fail. Additional profiles are optional.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConfigFileReader.ConfigFile
ConfigFile represents a simple lookup mechanism for a OCI config file.
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_FILE_PATH
Default location of the config file.static String
FALLBACK_DEFAULT_FILE_PATH
The fallback default location of the config file.static String
OCI_CONFIG_FILE_PATH_ENV_VAR_NAME
Environment variable name for the config file location
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ConfigFileReader.ConfigFile
parse(InputStream configurationStream, String profile)
Create a new instance using an UTF-8 input stream.static ConfigFileReader.ConfigFile
parse(InputStream configurationStream, String profile, Charset charset)
Create a new instance using an input stream.static ConfigFileReader.ConfigFile
parse(String configurationFilePath)
Create a new instance using a file at a given location.static ConfigFileReader.ConfigFile
parse(String configurationFilePath, String profile)
Create a new instance using a file at a given location.static ConfigFileReader.ConfigFile
parseDefault()
Creates a new ConfigFile instance using the configuration at the default location, using the default profile.static ConfigFileReader.ConfigFile
parseDefault(String profile)
Creates a new ConfigFile instance using the configuration at the default location, using the given profile.
-
-
-
Field Detail
-
DEFAULT_FILE_PATH
public static final String DEFAULT_FILE_PATH
Default location of the config file.- See Also:
- Constant Field Values
-
FALLBACK_DEFAULT_FILE_PATH
public static final String FALLBACK_DEFAULT_FILE_PATH
The fallback default location of the config file.If and only if the
DEFAULT_FILE_PATH
does not exist, this fallback default location will be used.- See Also:
- Constant Field Values
-
OCI_CONFIG_FILE_PATH_ENV_VAR_NAME
public static final String OCI_CONFIG_FILE_PATH_ENV_VAR_NAME
Environment variable name for the config file location- See Also:
- Constant Field Values
-
-
Method Detail
-
parseDefault
public static ConfigFileReader.ConfigFile parseDefault() throws IOException
Creates a new ConfigFile instance using the configuration at the default location, using the default profile.See
DEFAULT_FILE_PATH
.- Returns:
- A new ConfigFile instance.
- Throws:
IOException
- if the file could not be read.
-
parseDefault
public static ConfigFileReader.ConfigFile parseDefault(@Nullable String profile) throws IOException
Creates a new ConfigFile instance using the configuration at the default location, using the given profile.See
DEFAULT_FILE_PATH
.- Parameters:
profile
- The profile name to load, or null if you want to load the “DEFAULT” profile.- Returns:
- A new ConfigFile instance.
- Throws:
IOException
- if the file could not be read.
-
parse
public static ConfigFileReader.ConfigFile parse(String configurationFilePath) throws IOException
Create a new instance using a file at a given location.This method is the same as calling
parse(String, String)
with "DEFAULT" as the profile.- Parameters:
configurationFilePath
- The path to the config file.- Returns:
- A new ConfigFile instance.
- Throws:
IOException
- if the file could not be read.
-
parse
public static ConfigFileReader.ConfigFile parse(String configurationFilePath, @Nullable String profile) throws IOException
Create a new instance using a file at a given location.- Parameters:
configurationFilePath
- The path to the config file.profile
- The profile name to load, or null if you want to load the “DEFAULT” profile.- Returns:
- A new ConfigFile instance.
- Throws:
IOException
- if the file could not be read.
-
parse
public static ConfigFileReader.ConfigFile parse(InputStream configurationStream, @Nullable String profile) throws IOException
Create a new instance using an UTF-8 input stream.- Parameters:
configurationStream
- The path to the config file.profile
- The profile name to load, or null if you want to load the “DEFAULT” profile.- Returns:
- A new ConfigFile instance.
- Throws:
IOException
- if the file could not be read.
-
parse
public static ConfigFileReader.ConfigFile parse(InputStream configurationStream, @Nullable String profile, @Nonnull Charset charset) throws IOException
Create a new instance using an input stream.- Parameters:
configurationStream
- The path to the config file.profile
- The profile name to load, or null if you want to load the “DEFAULT” profile.charset
- The charset used when parsing the input stream- Returns:
- A new ConfigFile instance.
- Throws:
IOException
- if the file could not be read.
-
-