Example usage for com.amazonaws.util StringUtils trim

List of usage examples for com.amazonaws.util StringUtils trim

Introduction

In this page you can find the example usage for com.amazonaws.util StringUtils trim.

Prototype

public static String trim(String value) 

Source Link

Document

A null-safe trim method.

Usage

From source file:com.er.sylvite.CustomEnvironmentVariableCredentialsProvider.java

License:Open Source License

@Override
public AWSCredentials getCredentials() {

    String prefix = System.getProperty(PREFIX_ENV_VAR, DEFAULT_PREFIX);

    String accessKeyEnvVar = prefix + "_" + ACCESS_KEY_ENV_VAR;
    String secretKeyEnvVar = prefix + "_" + SECRET_KEY_ENV_VAR;

    String accessKey = System.getenv(accessKeyEnvVar);
    String secretKey = System.getenv(secretKeyEnvVar);

    accessKey = StringUtils.trim(accessKey);
    secretKey = StringUtils.trim(secretKey);

    if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) {

        throw new AmazonClientException("Unable to load AWS credentials from environment variables " + "("
                + accessKeyEnvVar + " and " + secretKeyEnvVar + ")");
    }//from  w ww  . ja  v a2  s.co  m

    return new BasicAWSCredentials(accessKey, secretKey);
}