Package io.awspring.cloud.s3
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
-
Field Summary
Fields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
-
Constructor Summary
ConstructorsConstructorDescriptionS3PathMatchingResourcePatternResolver
(software.amazon.awssdk.services.s3.S3Client s3Client, ResourcePatternResolver resourcePatternResolverDelegate) S3PathMatchingResourcePatternResolver
(software.amazon.awssdk.services.s3.S3Client s3Client, ResourcePatternResolver resourcePatternResolverDelegate, S3OutputStreamProvider s3OutputStreamProvider) Creates aS3PathMatchingResourcePatternResolver
with the givenS3Client
,ResourcePatternResolver
andS3OutputStreamProvider
.S3PathMatchingResourcePatternResolver
(software.amazon.awssdk.services.s3.S3Client s3Client, ResourcePatternResolver resourcePatternResolverDelegate, S3OutputStreamProvider s3OutputStreamProvider, PathMatcher pathMatcher, List<String> wildCardSeparators) -
Method Summary
Modifier and TypeMethodDescriptionprotected S3Resource
createS3Resource
(String location) Creates a S3 resource based on the given location.Gets the classloader.getResource
(String location) Gets a single resource.Resource[]
getResources
(String locationPattern) Gets all resources based on the given location pattern.
-
Constructor Details
-
S3PathMatchingResourcePatternResolver
public S3PathMatchingResourcePatternResolver(software.amazon.awssdk.services.s3.S3Client s3Client, ResourcePatternResolver resourcePatternResolverDelegate) Creates aS3PathMatchingResourcePatternResolver
with the givenS3Client
,ResourcePatternResolver
. For the S3 Resource aInMemoryBufferingS3OutputStreamProvider
is used in case the resource should be modified and for the pattern matching aAntPathMatcher
is used.- Parameters:
s3Client
- the s3Client of the Amazon SDKresourcePatternResolverDelegate
- 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) Creates aS3PathMatchingResourcePatternResolver
with the givenS3Client
,ResourcePatternResolver
andS3OutputStreamProvider
.- Parameters:
s3Client
- the s3Client of the Amazon SDKresourcePatternResolverDelegate
- 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 SDKresourcePatternResolverDelegate
- 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 writtenpathMatcher
- used to resolve resources and bucket nameswildCardSeparators
- the wildcard separators to determine the prefix. You can also use Collections.emptyList(), but this will cause performance and request impacts.
-
-
Method Details
-
getResources
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 interfaceResourcePatternResolver
- 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
Gets a single resource. Note: This method does not accept any kind of patterns.- Specified by:
getResource
in interfaceResourceLoader
- Parameters:
location
- the location which points to a resource- Returns:
- the resource
-
getClassLoader
Gets the classloader. Delegates toResourceLoader.getClassLoader()
.- Specified by:
getClassLoader
in interfaceResourceLoader
- Returns:
- the classloader
-
createS3Resource
Creates a S3 resource based on the given location.- Parameters:
location
- the location to create the S3 resource from- Returns:
- the created S3 resource
-