Top Description Inners Fields Constructors Methods
com.oracle.bmc

public final Class ConfigFileReader

extends Object
Class Inheritance
Imports
org.slf4j.Logger, jakarta.annotation.Nonnull, .Nullable, .Nonnull, .Nullable, java.io.BufferedReader, .File, .FileInputStream, .IOException, .InputStream, .InputStreamReader, java.nio.charset.Charset, .StandardCharsets, java.util.HashMap, .Map, com.oracle.bmc.util.internal.StringUtils

Simple implementation to read OCI configuration files.

Note, config files MUST contain a "DEFAULT" profile, else validation will fail. Additional profiles are optional.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static class
ConfigFileReader.ConfigFile

ConfigFile represents a simple lookup mechanism for a OCI config file.

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_FILE_PATH

Default location of the config file.

private static final String
public static final String
FALLBACK_DEFAULT_FILE_PATH

The fallback default location of the config file.

private static final Logger
public static final String
OCI_CONFIG_FILE_PATH_ENV_VAR_NAME

Environment variable name for the config file location

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ConfigFileReader.ConfigFile

Returns:

A new ConfigFile instance.
parse
(String
The path to the config file.
configurationFilePath
)

Create a new instance using a file at a given location.

public static ConfigFileReader.ConfigFile

Returns:

A new ConfigFile instance.
parse
(String
The path to the config file.
configurationFilePath
,
String
The profile name to load, or null if you want to load the "DEFAULT" profile.
profile
)

Create a new instance using a file at a given location.

public static ConfigFileReader.ConfigFile

Returns:

A new ConfigFile instance.
parse
(InputStream
The path to the config file.
configurationStream
,
String
The profile name to load, or null if you want to load the "DEFAULT" profile.
profile
)

Create a new instance using an UTF-8 input stream.

public static ConfigFileReader.ConfigFile

Returns:

A new ConfigFile instance.
parse
(InputStream
The path to the config file.
configurationStream
,
String
The profile name to load, or null if you want to load the "DEFAULT" profile.
profile
,
Charset
The charset used when parsing the input stream
charset
)

Create a new instance using an input stream.

public static ConfigFileReader.ConfigFile

Returns:

A new ConfigFile instance.
parseDefault
()

Creates a new ConfigFile instance using the configuration at the default location, using the default profile.

public static ConfigFileReader.ConfigFile

Returns:

A new ConfigFile instance.
parseDefault
(String
The profile name to load, or null if you want to load the "DEFAULT" profile.
profile
)

Creates a new ConfigFile instance using the configuration at the default location, using the given profile.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_FILE_PATHback to summary
public static final String DEFAULT_FILE_PATH

Default location of the config file.

DEFAULT_PROFILE_NAMEback to summary
private static final String DEFAULT_PROFILE_NAME
FALLBACK_DEFAULT_FILE_PATHback to summary
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.

LOGback to summary
private static final Logger LOG
OCI_CONFIG_FILE_PATH_ENV_VAR_NAMEback to summary
public static final String OCI_CONFIG_FILE_PATH_ENV_VAR_NAME

Environment variable name for the config file location

Constructor Detail

ConfigFileReaderback to summary
private ConfigFileReader()

Method Detail

parseback to summary
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:String

The path to the config file.

Returns:ConfigFileReader.ConfigFile

A new ConfigFile instance.

Exceptions
IOException:
if the file could not be read.
parseback to summary
public static ConfigFileReader.ConfigFile parse(String configurationFilePath, String profile) throws IOException

Create a new instance using a file at a given location.

Parameters
configurationFilePath:String

The path to the config file.

profile:String

The profile name to load, or null if you want to load the "DEFAULT" profile.

Returns:ConfigFileReader.ConfigFile

A new ConfigFile instance.

Exceptions
IOException:
if the file could not be read.
parseback to summary
public static ConfigFileReader.ConfigFile parse(InputStream configurationStream, String profile) throws IOException

Create a new instance using an UTF-8 input stream.

Parameters
configurationStream:InputStream

The path to the config file.

profile:String

The profile name to load, or null if you want to load the "DEFAULT" profile.

Returns:ConfigFileReader.ConfigFile

A new ConfigFile instance.

Exceptions
IOException:
if the file could not be read.
parseback to summary
public static ConfigFileReader.ConfigFile parse(InputStream configurationStream, String profile, Charset charset) throws IOException

Create a new instance using an input stream.

Parameters
configurationStream:InputStream

The path to the config file.

profile:String

The profile name to load, or null if you want to load the "DEFAULT" profile.

charset:Charset

The charset used when parsing the input stream

Returns:ConfigFileReader.ConfigFile

A new ConfigFile instance.

Exceptions
IOException:
if the file could not be read.
parseDefaultback to summary
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:ConfigFileReader.ConfigFile

A new ConfigFile instance.

Exceptions
IOException:
if the file could not be read.
parseDefaultback to summary
public static ConfigFileReader.ConfigFile parseDefault(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:String

The profile name to load, or null if you want to load the "DEFAULT" profile.

Returns:ConfigFileReader.ConfigFile

A new ConfigFile instance.

Exceptions
IOException:
if the file could not be read.
com.oracle.bmc back to summary

private final Class ConfigFileReader.ConfigAccumulator

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final Map<String, Map<String, String>>
private String
private boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
accept(String line)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configurationsByProfileback to summary
pack-priv final Map<String, Map<String, String>> configurationsByProfile
currentProfileback to summary
private String currentProfile
foundDefaultProfileback to summary
private boolean foundDefaultProfile

Constructor Detail

ConfigAccumulatorback to summary
private ConfigAccumulator()

Method Detail

acceptback to summary
private void accept(String line)
com.oracle.bmc back to summary

public final Class ConfigFileReader.ConfigFile

extends Object
Class Inheritance

ConfigFile represents a simple lookup mechanism for a OCI config file.

Field Summary

Modifier and TypeField and Description
private final ConfigFileReader.ConfigAccumulator
private final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The value, or null if it didn't exist.
get
(String
The key to look up.
key
)

Gets the value associated with a given key.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

accumulatorback to summary
private final ConfigFileReader.ConfigAccumulator accumulator
profileback to summary
private final String profile

Constructor Detail

ConfigFileback to summary
private ConfigFile(ConfigFileReader.ConfigAccumulator accumulator, String profile)
Annotations
@java.beans.ConstructorProperties

Method Detail

getback to summary
public String get(String key)

Gets the value associated with a given key. The value returned will be the one for the selected profile (if available), else the value in the DEFAULT profile (if specified), else null.

Parameters
key:String

The key to look up.

Returns:String

The value, or null if it didn't exist.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override