Class SdkS3Client

java.lang.Object
net.solarnetwork.domain.BasicIdentity<String>
net.solarnetwork.service.support.BaseLocalizedServiceInfoProvider<String>
net.solarnetwork.settings.support.BaseSettingsSpecifierLocalizedServiceInfoProvider<String>
net.solarnetwork.common.s3.sdk.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 Details

    • DEFAULT_REGION_NAME

      public static final String DEFAULT_REGION_NAME
      The default value for the regionName property.
    • DEFAULT_MAXIMUM_KEYS_PER_REQUEST

      public static final int DEFAULT_MAXIMUM_KEYS_PER_REQUEST
      The default value for the maximumKeysPerRequest property.
      See Also:
  • Constructor Details

    • SdkS3Client

      public SdkS3Client()
      Default constructor.
    • SdkS3Client

      public SdkS3Client(String id)
      Constructor.
      Parameters:
      id - the settings UID to use
  • Method Details

    • configurationChanged

      public void configurationChanged(Map<String,Object> properties)
      Specified by:
      configurationChanged in interface net.solarnetwork.settings.SettingsChangeObserver
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isConfigured

      public boolean isConfigured()
      Description copied from interface: S3Client
      Test if the client is fully configured.
      Specified by:
      isConfigured in interface S3Client
      Returns:
      true if the client is configured
    • listObjects

      public Set<S3ObjectReference> listObjects(String prefix) throws IOException
      Description copied from interface: S3Client
      List all available objects matching a prefix.
      Specified by:
      listObjects in interface S3Client
      Parameters:
      prefix - the prefix to match
      Returns:
      the matching objects, never null
      Throws:
      IOException - if an IO error occurs
    • getObjectAsString

      public String getObjectAsString(String key) throws IOException
      Description copied from interface: S3Client
      Get the contents of a S3 object as a string.

      The S3 object is assumed to use the UTF-8 character set.

      Specified by:
      getObjectAsString in interface S3Client
      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: S3Client
      Get a S3 object.

      Note that the returned object's data may not be fetched from S3 until the InputStream returned by InputStreamSource.getInputStream() is read. That means the progressListener might not have any progress callbacks until that time as well.

      Specified by:
      getObject in interface S3Client
      Type Parameters:
      P - the progress context type
      Parameters:
      key - the key of the object to get
      progressListener - an optional progress listener
      progressContext - an optional progress context
      Returns:
      the object, or null if not found
      Throws:
      IOException - if an IO error occurs
    • getObjectURL

      public URL getObjectURL(String key)
      Description copied from interface: S3Client
      Get a URL for a S3 object.
      Specified by:
      getObjectURL in interface S3Client
      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: S3Client
      Put an object onto S3.
      Specified by:
      putObject in interface S3Client
      Type Parameters:
      P - the progress context type
      Parameters:
      key - the key of the object to put
      in - the object contents
      objectMetadata - the object metadata
      progressListener - an optional progress listener
      progressContext - an optional progress context
      Returns:
      a reference to the put object
      Throws:
      IOException - if an IO error occurs
    • deleteObjects

      public Set<String> deleteObjects(Iterable<String> keys) throws IOException
      Description copied from interface: S3Client
      Delete a set of keys from S3.
      Specified by:
      deleteObjects in interface S3Client
      Parameters:
      keys - the keys to delete
      Returns:
      the keys that were deleted
      Throws:
      IOException - if an IO error occurs
    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in interface net.solarnetwork.settings.SettingSpecifierProvider
    • getSettingSpecifiers

      public List<net.solarnetwork.settings.SettingSpecifier> getSettingSpecifiers()
      Specified by:
      getSettingSpecifiers in interface net.solarnetwork.settings.SettingSpecifierProvider
    • setBucketName

      public void setBucketName(String bucketName)
      Set the bucket name to connect to.
      Parameters:
      bucketName - the bucketName to set
    • setRegionName

      public void setRegionName(String regionName)
      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

      public void setAccessToken(String accessToken)
      Set the AWS access token to use.
      Parameters:
      accessToken - the access token to set
    • setAccessSecret

      public void setAccessSecret(String accessSecret)
      Set the AWS access token secret to use.
      Parameters:
      accessSecret - the access secret to set