Package net.solarnetwork.common.s3.sdk
Class SdkS3Client
- All Implemented Interfaces:
Comparable<String>,S3Client,net.solarnetwork.domain.Identity<String>,net.solarnetwork.service.LocalizedServiceInfoProvider,net.solarnetwork.settings.SettingsChangeObserver,net.solarnetwork.settings.SettingSpecifierProvider
public class SdkS3Client
extends net.solarnetwork.settings.support.BaseSettingsSpecifierLocalizedServiceInfoProvider<String>
implements S3Client, net.solarnetwork.settings.SettingsChangeObserver
S3Client using the AWS SDK.- Version:
- 1.3
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default value for themaximumKeysPerRequestproperty.static final StringThe default value for theregionNameproperty. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigurationChanged(Map<String, Object> properties) deleteObjects(Iterable<String> keys) Delete a set of keys from S3.<P> S3ObjectgetObject(String key, net.solarnetwork.service.ProgressListener<P> progressListener, P progressContext) Get a S3 object.getObjectAsString(String key) Get the contents of a S3 object as a string.getObjectURL(String key) Get a URL for a S3 object.List<net.solarnetwork.settings.SettingSpecifier> booleanTest if the client is fully configured.listObjects(String prefix) List all available objects matching a prefix.putObject(String key, InputStream in, S3ObjectMetadata objectMetadata, net.solarnetwork.service.ProgressListener<P> progressListener, P progressContext) Put an object onto S3.voidsetAccessSecret(String accessSecret) Set the AWS access token secret to use.voidsetAccessToken(String accessToken) Set the AWS access token to use.voidsetBucketName(String bucketName) Set the bucket name to connect to.voidsetCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider credentialsProvider) Set the credentials provider to authenticate with.voidsetMaximumKeysPerRequest(int maximumKeysPerRequest) Set the maximum number of S3 object keys to request in one request.voidsetRegionName(String regionName) Set the AWS region to use.toString()Methods inherited from class net.solarnetwork.settings.support.BaseSettingsSpecifierLocalizedServiceInfoProvider
getLocalizedServiceInfo, getSettingUid, populateInfoMessages, resolveInfoMessagesMethods inherited from class net.solarnetwork.service.support.BaseLocalizedServiceInfoProvider
getMessageSource, setMessageSourceMethods inherited from class net.solarnetwork.domain.BasicIdentity
clone, compareTo, equals, getId, hashCodeMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.solarnetwork.domain.Identity
hasIdMethods inherited from interface net.solarnetwork.settings.SettingSpecifierProvider
getMessageSource, getSettingUid, templateSettingSpecifiers
-
Field Details
-
DEFAULT_REGION_NAME
The default value for theregionNameproperty. -
DEFAULT_MAXIMUM_KEYS_PER_REQUEST
public static final int DEFAULT_MAXIMUM_KEYS_PER_REQUESTThe default value for themaximumKeysPerRequestproperty.- See Also:
-
-
Constructor Details
-
SdkS3Client
public SdkS3Client()Default constructor. -
SdkS3Client
Constructor.- Parameters:
id- the settings UID to use
-
-
Method Details
-
configurationChanged
- Specified by:
configurationChangedin interfacenet.solarnetwork.settings.SettingsChangeObserver
-
toString
-
isConfigured
public boolean isConfigured()Description copied from interface:S3ClientTest if the client is fully configured.- Specified by:
isConfiguredin interfaceS3Client- Returns:
- true if the client is configured
-
listObjects
Description copied from interface:S3ClientList all available objects matching a prefix.- Specified by:
listObjectsin interfaceS3Client- Parameters:
prefix- the prefix to match- Returns:
- the matching objects, never null
- Throws:
IOException- if an IO error occurs
-
getObjectAsString
Description copied from interface:S3ClientGet the contents of a S3 object as a string.The S3 object is assumed to use the
UTF-8character set.- Specified by:
getObjectAsStringin interfaceS3Client- Parameters:
key- the key of the object to get- Returns:
- the string, or null if not found
- Throws:
IOException- if an IO error occurs
-
getObject
public <P> S3Object getObject(String key, net.solarnetwork.service.ProgressListener<P> progressListener, P progressContext) throws IOException Description copied from interface:S3ClientGet a S3 object.Note that the returned object's data may not be fetched from S3 until the
InputStreamreturned byInputStreamSource.getInputStream()is read. That means theprogressListenermight not have any progress callbacks until that time as well.- Specified by:
getObjectin interfaceS3Client- Type Parameters:
P- the progress context type- Parameters:
key- the key of the object to getprogressListener- an optional progress listenerprogressContext- an optional progress context- Returns:
- the object, or null if not found
- Throws:
IOException- if an IO error occurs
-
getObjectURL
Description copied from interface:S3ClientGet a URL for a S3 object.- Specified by:
getObjectURLin interfaceS3Client- Parameters:
key- the key- Returns:
- the URL
-
putObject
public <P> S3ObjectReference putObject(String key, InputStream in, S3ObjectMetadata objectMetadata, net.solarnetwork.service.ProgressListener<P> progressListener, P progressContext) throws IOException Description copied from interface:S3ClientPut an object onto S3.- Specified by:
putObjectin interfaceS3Client- Type Parameters:
P- the progress context type- Parameters:
key- the key of the object to putin- the object contentsobjectMetadata- the object metadataprogressListener- an optional progress listenerprogressContext- an optional progress context- Returns:
- a reference to the put object
- Throws:
IOException- if an IO error occurs
-
deleteObjects
Description copied from interface:S3ClientDelete a set of keys from S3.- Specified by:
deleteObjectsin interfaceS3Client- Parameters:
keys- the keys to delete- Returns:
- the keys that were deleted
- Throws:
IOException- if an IO error occurs
-
getDisplayName
- Specified by:
getDisplayNamein interfacenet.solarnetwork.settings.SettingSpecifierProvider
-
getSettingSpecifiers
- Specified by:
getSettingSpecifiersin interfacenet.solarnetwork.settings.SettingSpecifierProvider
-
setBucketName
Set the bucket name to connect to.- Parameters:
bucketName- the bucketName to set
-
setRegionName
Set the AWS region to use.- Parameters:
regionName- the region name to set; defaults to us-west-2
-
setMaximumKeysPerRequest
public void setMaximumKeysPerRequest(int maximumKeysPerRequest) Set the maximum number of S3 object keys to request in one request.- Parameters:
maximumKeysPerRequest- the maximum to set
-
setCredentialsProvider
public void setCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider credentialsProvider) Set the credentials provider to authenticate with.If this is configured, it takes precedence over any configured
accessToken/accessSecret.- Parameters:
credentialsProvider- the provider to set
-
setAccessToken
Set the AWS access token to use.- Parameters:
accessToken- the access token to set
-
setAccessSecret
Set the AWS access token secret to use.- Parameters:
accessSecret- the access secret to set
-