Class 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.

    • Field Detail

      • 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​(@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.