Class S3PathMatchingResourcePatternResolver

java.lang.Object
io.awspring.cloud.s3.S3PathMatchingResourcePatternResolver
All Implemented Interfaces:
ResourceLoader, ResourcePatternResolver

public class S3PathMatchingResourcePatternResolver extends Object implements ResourcePatternResolver
A ResourcePatternResolver implementation which allows an ant-style path matching when loading S3 resources. Ant wildcards (*, ** and ?) are allowed in both, bucket name and object name.

WARNING: Be aware that when you are using wildcards in the bucket name it can take a very long time to parse all files. Moreover this implementation does not return truncated results. This means that when handling huge buckets it could lead to serious performance problems. For more information look at the findResourcesInBucketWithKeyPattern method.

Since:
1.0
Author:
Alain Sahli, Agim Emruli, Tobias Soloschenko
  • Constructor Details

    • S3PathMatchingResourcePatternResolver

      public S3PathMatchingResourcePatternResolver(software.amazon.awssdk.services.s3.S3Client s3Client, ResourcePatternResolver resourcePatternResolverDelegate)
      Creates a S3PathMatchingResourcePatternResolver with the given S3Client, ResourcePatternResolver. For the S3 Resource a InMemoryBufferingS3OutputStreamProvider is used in case the resource should be modified and for the pattern matching a AntPathMatcher is used.
      Parameters:
      s3Client - the s3Client of the Amazon SDK
      resourcePatternResolverDelegate - the resourcePatternResolverDelegate which is used if the given scheme is not S3. In this case all processing is delegated to this implementation.
    • S3PathMatchingResourcePatternResolver

      public S3PathMatchingResourcePatternResolver(software.amazon.awssdk.services.s3.S3Client s3Client, ResourcePatternResolver resourcePatternResolverDelegate, S3OutputStreamProvider s3OutputStreamProvider)
      Parameters:
      s3Client - the s3Client of the Amazon SDK
      resourcePatternResolverDelegate - the resourcePatternResolverDelegate which is used if the given scheme is not S3. In this case all processing is delegated to this implementation.
      s3OutputStreamProvider - The s3OutputStreamProvider used if the resource is going to be written
    • S3PathMatchingResourcePatternResolver

      public S3PathMatchingResourcePatternResolver(software.amazon.awssdk.services.s3.S3Client s3Client, ResourcePatternResolver resourcePatternResolverDelegate, S3OutputStreamProvider s3OutputStreamProvider, PathMatcher pathMatcher, List<String> wildCardSeparators)
      Parameters:
      s3Client - the s3Client of the Amazon SDK
      resourcePatternResolverDelegate - the resourcePatternResolverDelegate which is used if the given scheme is not S3. In this case all processing is delegated to this implementation.
      s3OutputStreamProvider - The s3OutputStreamProvider used if the resource is going to be written
      pathMatcher - used to resolve resources and bucket names
      wildCardSeparators - the wildcard separators to determine the prefix. You can also use Collections.emptyList(), but this will cause performance and request impacts.
  • Method Details

    • getResources

      public Resource[] getResources(String locationPattern) throws IOException
      Gets all resources based on the given location pattern. If the location pattern is not using the s3 scheme the operation is delegated to resourcePatternResolverDelegate.
      Specified by:
      getResources in interface ResourcePatternResolver
      Parameters:
      locationPattern - the location pattern to get all resources from
      Returns:
      an array with all resources
      Throws:
      IOException - if something went wrong during the resource resolving
    • getResource

      public Resource getResource(String location)
      Gets a single resource. Note: This method does not accept any kind of patterns.
      Specified by:
      getResource in interface ResourceLoader
      Parameters:
      location - the location which points to a resource
      Returns:
      the resource
    • getClassLoader

      public ClassLoader getClassLoader()
      Gets the classloader. Delegates to ResourceLoader.getClassLoader().
      Specified by:
      getClassLoader in interface ResourceLoader
      Returns:
      the classloader
    • createS3Resource

      protected S3Resource createS3Resource(String location)
      Creates a S3 resource based on the given location.
      Parameters:
      location - the location to create the S3 resource from
      Returns:
      the created S3 resource