Class OCIConfigFileReader


  • public class OCIConfigFileReader
    extends Object
    Cloud service only.

    An instance that reads an Oracle Cloud Infrastructure (OCI) configuration file. Note, an OCI configuration file MUST contain a "DEFAULT" profile, additional profiles are optional.

    An OCI configuration file allows use of custom key-value pairs, which can be loaded and referenced using this class. For example, the frequently used compartment OCID can be put in a configuration file.

     In the configuration file, add one custom parameter "custom_compartment_id"
     [DEFAULT]
     ...
     custom_compartment_id=ocid1.compartment.oc1..aaa...
    
     Then it can be retrieved using this class:
     OCIConfigFile config = OCIConfigFileReader.parse("~/.oci/config");
     String compartmentId = config.get("custom_compartment_id");
     

    • Method Detail

      • parse

        public static OCIConfigFileReader.OCIConfigFile parse​(String configFilePath,
                                                              String profile)
                                                       throws IOException
        Create a new instance using a file at a given location.
        Parameters:
        configFilePath - 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 OCIConfigFile instance.
        Throws:
        IOException - if the file could not be read.
      • parse

        public static OCIConfigFileReader.OCIConfigFile parse​(InputStream configStream,
                                                              String profile)
                                                       throws IOException
        Create a new instance using an UTF-8 input stream.
        Parameters:
        configStream - 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 OCIConfigFile instance.
        Throws:
        IOException - if the file could not be read.
      • parse

        public static OCIConfigFileReader.OCIConfigFile parse​(InputStream configStream,
                                                              String profile,
                                                              Charset charset)
                                                       throws IOException
        Create a new instance using an input stream.
        Parameters:
        configStream - 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 OCIConfigFile instance.
        Throws:
        IOException - if the file could not be read.