Package org.apache.solr.common.util

## Class EnvUtils

- java.lang.Object
- - org.apache.solr.common.util.EnvUtils

    public class EnvUtils
    extends Object

This class is a unified provider of environment variables and system properties. It exposes a mutable copy of the environment variables. It also converts 'SOLR_FOO' variables to system properties 'solr.foo' and provide various convenience accessors for them.

### Constructor Summary

Constructors
`EnvUtils()`

### Method Summary

All Methods Static Methods Concrete Methods
`protected static String` `envNameToSyspropName​(String envName)`
`static String` `getEnv​(String key)` Get a single environment variable as string
`static String` `getEnv​(String key, String defaultValue)` Get a single environment variable as string, or default
`static boolean` `getEnvAsBool​(String key)` Get an env var as boolean
`static boolean` `getEnvAsBool​(String key, boolean defaultValue)` Get an env var as boolean, or default value
`static List<String>` `getEnvAsList​(String key)` Get comma separated strings from env as List
`static List<String>` `getEnvAsList​(String key, List<String> defaultValue)` Get comma separated strings from env as List
`static long` `getEnvAsLong​(String key)` Get an environment variable as long
`static long` `getEnvAsLong​(String key, long defaultValue)` Get an environment variable as long, or default value
`static SortedMap<String,​String>` `getEnvs()` Get Solr's mutable copy of all environment variables.
`static SortedMap<String,​String>` `getProperties()` Get all Solr system properties as a sorted map
`static String` `getProperty​(String key)` Get a property as string
`static String` `getProperty​(String key, String defaultValue)` Get a property as string with a fallback value.
`static Boolean` `getPropertyAsBool​(String key)` Get property as boolean
`static Boolean` `getPropertyAsBool​(String key, Boolean defaultValue)` Get property as boolean, or default value
`static List<String>` `getPropertyAsList​(String key)` Get comma separated strings from sysprop as List
`static List<String>` `getPropertyAsList​(String key, List<String> defaultValue)` Get comma separated strings from sysprop as List, or default value
`static Long` `getPropertyAsLong​(String key)` Get property as integer
`static Long` `getPropertyAsLong​(String key, Long defaultValue)` Get property as long, or default value
`static void` `setEnv​(String key, String value)` Set an environment variable
`static void` `setEnvs​(Map<String,​String> env)` Set all environment variables
`static void` `setProperty​(String key, String value)` Set a system property.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### EnvUtils

    public EnvUtils()

### Method Detail

#### getEnvs

    public static SortedMap<String,​String> getEnvs()

Get Solr's mutable copy of all environment variables.

Returns:
  sorted map of environment variables

#### getEnv

    public static String getEnv​(String key)

Get a single environment variable as string

#### getEnv

    public static String getEnv​(String key,
                                String defaultValue)

Get a single environment variable as string, or default

#### getEnvAsLong

    public static long getEnvAsLong​(String key)

Get an environment variable as long

#### getEnvAsLong

    public static long getEnvAsLong​(String key,
                                    long defaultValue)

Get an environment variable as long, or default value

#### getEnvAsBool

    public static boolean getEnvAsBool​(String key)

Get an env var as boolean

#### getEnvAsBool

    public static boolean getEnvAsBool​(String key,
                                       boolean defaultValue)

Get an env var as boolean, or default value

#### getEnvAsList

    public static List<String> getEnvAsList​(String key)

Get comma separated strings from env as List

#### getEnvAsList

    public static List<String> getEnvAsList​(String key,
                                            List<String> defaultValue)

Get comma separated strings from env as List

#### setEnv

    public static void setEnv​(String key,
                              String value)

Set an environment variable

#### setEnvs

    public static void setEnvs​(Map<String,​String> env)

Set all environment variables

#### getProperties

    public static SortedMap<String,​String> getProperties()

Get all Solr system properties as a sorted map

#### getProperty

    public static String getProperty​(String key)

Get a property as string

#### getProperty

    public static String getProperty​(String key,
                                     String defaultValue)

Get a property as string with a fallback value. All other getProperty* methods use this.

Parameters:
  `key` - property key, which treats 'camelCase' the same as 'camel.case'
  `defaultValue` - fallback value if property is not found

#### getPropertyAsLong

    public static Long getPropertyAsLong​(String key)

Get property as integer

#### getPropertyAsLong

    public static Long getPropertyAsLong​(String key,
                                         Long defaultValue)

Get property as long, or default value

#### getPropertyAsBool

    public static Boolean getPropertyAsBool​(String key)

Get property as boolean

#### getPropertyAsBool

    public static Boolean getPropertyAsBool​(String key,
                                            Boolean defaultValue)

Get property as boolean, or default value

#### getPropertyAsList

    public static List<String> getPropertyAsList​(String key)

Get comma separated strings from sysprop as List

Returns:
  list of strings, or null if not found

#### getPropertyAsList

    public static List<String> getPropertyAsList​(String key,
                                                 List<String> defaultValue)

Get comma separated strings from sysprop as List, or default value

Returns:
  list of strings, or provided default if not found

#### setProperty

    public static void setProperty​(String key,
                                   String value)

Set a system property. Shim to `System.setProperty(String, String)`

#### envNameToSyspropName

    protected static String envNameToSyspropName​(String envName)