本文整理汇总了Java中com.amazonaws.util.StringUtils类的典型用法代码示例。如果您正苦于以下问题:Java StringUtils类的具体用法?Java StringUtils怎么用?Java StringUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringUtils类属于com.amazonaws.util包,在下文中一共展示了StringUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getS3Client
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
public static AmazonS3 getS3Client(final String region, final String roleArn) {
final Regions awsRegion = StringUtils.isNullOrEmpty(region) ? Regions.US_EAST_1 : Regions.fromName(region);
if (StringUtils.isNullOrEmpty(roleArn)) {
return AmazonS3ClientBuilder.standard().withRegion(awsRegion).build();
} else {
final AssumeRoleRequest assumeRole = new AssumeRoleRequest().withRoleArn(roleArn).withRoleSessionName("io-klerch-mp3-converter");
final AWSSecurityTokenService sts = AWSSecurityTokenServiceClientBuilder.standard().withRegion(awsRegion).build();
final Credentials credentials = sts.assumeRole(assumeRole).getCredentials();
final BasicSessionCredentials sessionCredentials = new BasicSessionCredentials(
credentials.getAccessKeyId(),
credentials.getSecretAccessKey(),
credentials.getSessionToken());
return AmazonS3ClientBuilder.standard().withRegion(awsRegion).withCredentials(new AWSStaticCredentialsProvider(sessionCredentials)).build();
}
}
示例2: isUploadFile
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
private boolean isUploadFile(Iterator<S3ObjectSummary> iter, String path, String hash) {
while (iter.hasNext()) {
S3ObjectSummary fileS3 = iter.next();
// Filename should look like this:
// a/b
if (!fileS3.getKey().equals(path)) {
// If this is another file, then continue!
continue;
}
// Remove the file from the S3 list as it does not need to be processed further
iter.remove();
// Upload if the hashes differ
return StringUtils.isNullOrEmpty(hash) || !fileS3.getETag().equals(hash);
}
return true;
}
示例3: getCanonicalizedHeaderString
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
protected String getCanonicalizedHeaderString(SignableRequest<?> request) {
final List<String> sortedHeaders = new ArrayList<String>(request.getHeaders()
.keySet());
Collections.sort(sortedHeaders, String.CASE_INSENSITIVE_ORDER);
final Map<String, String> requestHeaders = request.getHeaders();
StringBuilder buffer = new StringBuilder();
for (String header : sortedHeaders) {
if (shouldExcludeHeaderFromSigning(header)) {
continue;
}
String key = StringUtils.lowerCase(header);
String value = requestHeaders.get(header);
StringUtils.appendCompactedString(buffer, key);
buffer.append(":");
if (value != null) {
StringUtils.appendCompactedString(buffer, value);
}
buffer.append("\n");
}
return buffer.toString();
}
示例4: getSignedHeadersString
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
protected String getSignedHeadersString(SignableRequest<?> request) {
final List<String> sortedHeaders = new ArrayList<String>(request
.getHeaders().keySet());
Collections.sort(sortedHeaders, String.CASE_INSENSITIVE_ORDER);
StringBuilder buffer = new StringBuilder();
for (String header : sortedHeaders) {
if (shouldExcludeHeaderFromSigning(header)) {
continue;
}
if (buffer.length() > 0)
buffer.append(";");
buffer.append(StringUtils.lowerCase(header));
}
return buffer.toString();
}
示例5: putObject
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
@Override
public PutObjectResult putObject(String bucketName, String key, String content)
throws AmazonServiceException, SdkClientException {
rejectNull(bucketName, "Bucket name must be provided");
rejectNull(key, "Object key must be provided");
rejectNull(content, "String content must be provided");
byte[] contentBytes = content.getBytes(StringUtils.UTF8);
InputStream is = new ByteArrayInputStream(contentBytes);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("text/plain");
metadata.setContentLength(contentBytes.length);
return putObject(new PutObjectRequest(bucketName, key, is, metadata));
}
示例6: handle
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
@Override
public AmazonWebServiceResponse<HeadBucketResult> handle(HttpResponse response)
throws Exception {
final AmazonWebServiceResponse<HeadBucketResult> awsResponse = new AmazonWebServiceResponse<HeadBucketResult>();
final HeadBucketResult result = new HeadBucketResult();
result.setBucketRegion(response.getHeaders().get(Headers.S3_BUCKET_REGION));
if (!StringUtils.isNullOrEmpty(response.getHeaders().get(Headers.IBM_SSE_KP_ENABLED))){
result.setIBMSSEKPEnabled(Boolean.parseBoolean(response.getHeaders().get(Headers.IBM_SSE_KP_ENABLED)));
}
if (!StringUtils.isNullOrEmpty(response.getHeaders().get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN))){
result.setIBMSSEKPCrk(response.getHeaders().get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN));
}
awsResponse.setResult(result);
return awsResponse;
}
示例7: from
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
private static String from(InputStream is) throws IOException {
if (is == null)
return "";
StringBuilder sb = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, StringUtils.UTF8));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} finally {
is.close();
}
return sb.toString();
}
示例8: convertStreamToString
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
/**
* Converts the contents of an input stream to a String
*/
private static String convertStreamToString(InputStream inputStream)
throws IOException {
if (inputStream == null) {
return "";
} else {
StringBuilder stringBuilder = new StringBuilder();
String line;
try {
BufferedReader reader =
new BufferedReader(new InputStreamReader(inputStream,
StringUtils.UTF8));
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
} finally {
inputStream.close();
}
return stringBuilder.toString();
}
}
示例9: handle
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
/**
* @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse)
*/
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
AmazonWebServiceResponse<T> awsResponse = parseResponseMetadata(response);
responseHeaders = response.getHeaders();
if (responseUnmarshaller != null) {
log.trace("Beginning to parse service response XML");
T result = responseUnmarshaller.unmarshall(response.getContent());
log.trace("Done parsing service response XML");
awsResponse.setResult(result);
if (result instanceof ObjectListing) {
if (!StringUtils.isNullOrEmpty(responseHeaders.get(Headers.IBM_SSE_KP_ENABLED))){
((ObjectListing) result).setIBMSSEKPEnabled(Boolean.parseBoolean(responseHeaders.get(Headers.IBM_SSE_KP_ENABLED)));
}
if (!StringUtils.isNullOrEmpty(responseHeaders.get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN))) {
((ObjectListing) result).setIBMSSEKPCrk(responseHeaders.get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN));
}
}
}
return awsResponse;
}
示例10: getMimetype
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
/**
* Determines the mimetype of a file by looking up the file's extension in
* an internal listing to find the corresponding mime type. If the file has
* no extension, or the extension is not available in the listing contained
* in this class, the default mimetype <code>application/octet-stream</code>
* is returned.
* <p>
* A file extension is one or more characters that occur after the last
* period (.) in the file's name. If a file has no extension, Guesses the
* mimetype of file data based on the file's extension.
*
* @param fileName
* The name of the file whose extension may match a known
* mimetype.
*
* @return The file's mimetype based on its extension, or a default value of
* <code>application/octet-stream</code> if a mime type value cannot
* be found.
*/
public String getMimetype(String fileName) {
int lastPeriodIndex = fileName.lastIndexOf(".");
if (lastPeriodIndex > 0 && lastPeriodIndex + 1 < fileName.length()) {
String ext = StringUtils.lowerCase(fileName.substring(lastPeriodIndex + 1));
if (extensionToMimetypeMap.keySet().contains(ext)) {
String mimetype = (String) extensionToMimetypeMap.get(ext);
if (log.isDebugEnabled()) {
log.debug("Recognised extension '" + ext + "', mimetype is: '" + mimetype + "'");
}
return mimetype;
} else {
if (log.isDebugEnabled()) {
log.debug("Extension '" + ext + "' is unrecognized in mime type listing"
+ ", using default mime type: '" + MIMETYPE_OCTET_STREAM + "'");
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("File name has no extension, mime type cannot be recognised for: " + fileName);
}
}
return MIMETYPE_OCTET_STREAM;
}
示例11: getCredentials
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
@Override
public AWSCredentials getCredentials() {
// if profile is specified, use that
final String profile = configuration.get(AWSConstants.PROFILE);
if(!StringUtils.isNullOrEmpty(profile)) {
return new ProfileCredentialsProvider(profile).getCredentials();
}
// then try access key and secret
final String accessKeyId = configuration.get(AWSConstants.ACCESS_KEY_ID);
final String secretAccessKey = configuration.get(AWSConstants.SECRET_ACCESS_KEY);
if(!StringUtils.isNullOrEmpty(accessKeyId) && !StringUtils.isNullOrEmpty(secretAccessKey)) {
return new BasicAWSCredentials(accessKeyId, secretAccessKey);
}
// fall back to default
return new DefaultAWSCredentialsProviderChain().getCredentials();
}
示例12: getCredentials
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
@Override
public AWSCredentials getCredentials() {
String accessKey = null;
if (config.hasPath(GobblinAWSConfigurationKeys.SERVICE_ACCESS_KEY)) {
accessKey = config.getString(GobblinAWSConfigurationKeys.SERVICE_ACCESS_KEY);
}
String secretKey = null;
if (config.hasPath(GobblinAWSConfigurationKeys.SERVICE_SECRET_KEY)) {
secretKey = PasswordManager.getInstance(ConfigUtils.configToState(config))
.readPassword(config.getString(GobblinAWSConfigurationKeys.SERVICE_SECRET_KEY));
}
accessKey = StringUtils.trim(accessKey);
secretKey = StringUtils.trim(secretKey);
if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) {
throw new AmazonClientException(String.format("Unable to load AWS credentials from config (%s and %s)",
GobblinAWSConfigurationKeys.SERVICE_ACCESS_KEY, GobblinAWSConfigurationKeys.SERVICE_SECRET_KEY));
}
return new BasicAWSCredentials(accessKey, secretKey);
}
示例13: mapShortCode
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
@Override
public boolean mapShortCode(String code, String paramString) throws IOException {
if(!enabled) {
throw new IllegalStateException("Shortlink feature disabled");
}
try {
// does object exist?
client.getObjectMetadata(bucket, OBJECT_PREFIX + code);
} catch (AmazonS3Exception e) {
if (e.getStatusCode() != 404) {
log.warn(e);
return false;
}
}
byte[] paramStringBytes = paramString.getBytes(StringUtils.UTF8);
InputStream is = new ByteArrayInputStream(paramStringBytes);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType("text/plain");
metadata.setContentLength(paramStringBytes.length);
client.putObject(new PutObjectRequest(bucket, OBJECT_PREFIX + code, is, metadata));
return true;
}
示例14: start
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
@Override
public void start() {
if (RegionUtils.getRegion(region) == null) {
addError(format("Region not set or invalid for appender '%s'", getName()));
return;
}
if (StringUtils.isNullOrEmpty(logGroup)) {
addError(format("Log group name not set for appender '%s'", getName()));
return;
}
if (StringUtils.isNullOrEmpty(logStream)) {
addError(format("Log stream name not set for appender '%s'", getName()));
return;
}
setConverter(new StringPayloadConverter(getCharset(), isBinary()));
super.start();
}
示例15: computeServiceName
import com.amazonaws.util.StringUtils; //导入依赖的package包/类
/**
* Returns the service name of this AWS http client by first looking it up from the SDK internal
* configuration, and if not found, derive it from the class name of the immediate subclass of
* {@link AmazonWebServiceClient}. No configuration is necessary if the simple class name of the
* http client follows the convention of <code>(Amazon|AWS).*(JavaClient|Client)</code>.
*/
private String computeServiceName() {
final String httpClientName = getHttpClientName();
String service = ServiceNameFactory.getServiceName(httpClientName);
if (service != null) {
return service; // only if it is so explicitly configured
}
// Otherwise, make use of convention over configuration
int j = httpClientName.indexOf("JavaClient");
if (j == -1) {
j = httpClientName.indexOf("Client");
if (j == -1) {
throw new IllegalStateException(
"Unrecognized suffix for the AWS http client class name " + httpClientName);
}
}
int i = httpClientName.indexOf(AMAZON);
int len;
if (i == -1) {
i = httpClientName.indexOf(AWS);
if (i == -1) {
throw new IllegalStateException(
"Unrecognized prefix for the AWS http client class name " + httpClientName);
}
len = AWS.length();
} else {
len = AMAZON.length();
}
if (i >= j) {
throw new IllegalStateException(
"Unrecognized AWS http client class name " + httpClientName);
}
String serviceName = httpClientName.substring(i + len, j);
return StringUtils.lowerCase(serviceName);
}