-
- All Implemented Interfaces:
public interface ObjectContainerRepresents a segment of an S3 store that may contain objects. This could either be a bucket or a 'directory'.
All paths for all methods defined in this type are treated as relative to the root of the container. In the case of a bucket, all paths are absolute paths to the bucket root. In the case of a 'directory', all paths are relative to the directory prefix. The exception to this is paths starting with a leading '
/' character which will be treated as absolute paths in all cases.This interface does not define any methods for managing object tags. To work with object tags use one of the object access methods contained in this type, such as withObject or get which will give access to an S3Object instance without opening a stream over that object's contents.
Example:
container.withObject("my/object") { tags.put("something", "something else") } container["my/object"].tags.put("something", "something else")TODO: Handle delete markers TODO: Version IDs TODO: Governance Mode
-
-
Method Summary
Modifier and Type Method Description abstract <R extends Any> RwithObject(String path, Function1<S3Object, R> action)Executes the given action on the target object. abstract Booleancontains(String path)Tests whether this object container contains an object at the given path. abstract Booleancontains(String path, Function1<ObjectExistsParams, Unit> action)Tests whether this object container contains an object at the configured target path. abstract Booleancontains(String path, ObjectExistsParams params)Tests whether this object container contains an object at the configured target path. abstract UIntcountAll(String pathPrefix)Returns a count of all the objects in this object container, optionally filtered by a given path prefix. abstract UIntcountAll(Function1<String, Boolean> filter)Returns a count of all the objects in this object container, filtered by the given predicate function. abstract UIntcountSubDirs(String parent)Returns a count of first level subdirectories directly under the given parent directory name. abstract S3Objectget(String path)abstract S3Objectget(String path, Function1<ObjectGetParams, Unit> action)abstract S3Objectget(String path, ObjectGetParams params)abstract StreamObjectopen(String path)Fetches the object at the target path and returns a handle on it which can be used to stream out the target object's contents. abstract StreamObjectopen(String path, Function1<ObjectOpenParams, Unit> action)Fetches the configured target object and returns a handle on it which can be used to stream out the target object's contents. abstract StreamObjectopen(String path, ObjectOpenParams params)Fetches the configured target object and returns a handle on it which can be used to stream out the target object's contents. abstract FileObjectdownload(String path, File localFile)Fetches the object at the target path and downloads it into the specified local file. abstract FileObjectdownload(String path, Function1<ObjectDownloadParams, Unit> action)Fetches the object at the configured path and downloads it into the target local file. abstract FileObjectdownload(String path, ObjectDownloadParams params)Fetches the object at the configured path and downloads it into the target local file. abstract ObjectMetastat(String path)Fetches metadata for the object at the target path. abstract ObjectMetastat(String path, Function1<ObjectStatParams, Unit> action)Fetches metadata for the object at the target path. abstract ObjectMetastat(String path, ObjectStatParams params)Fetches metadata for the object at the target path. abstract ObjectListlistAll()Fetches a list of all the objects in this container. abstract ObjectListlistAll(Function1<ObjectListAllParams, Unit> action)Fetches a list of all the objects in this container. abstract ObjectListlistAll(ObjectListAllParams params)Fetches a list of all the objects in this container. abstract ObjectListlist(String prefix)abstract ObjectListlist(Function1<ObjectListParams, Unit> action)abstract ObjectListlist(ObjectListParams params)abstract SubPathListinglistSubPaths(String prefix, String delimiter)abstract SubPathListinglistSubPaths(Function1<SubPathListParams, Unit> action)abstract SubPathListinglistSubPaths(SubPathListParams params)abstract S3Objecttouch(String path)Creates an empty object at the specified path if one does not already exist. abstract S3Objecttouch(String path, Function1<ObjectTouchParams, Unit> action)Creates an empty object at the specified path if one does not already exist. abstract S3Objecttouch(String path, ObjectTouchParams params)Creates an empty object at the specified path if one does not already exist. S3Objectset(String path, InputStream stream)Creates or overwrites an object at the specified path with its contents uploaded from the given stream. S3Objectset(String path, File file)Uploads the specified file to this container at the given path, overwriting any object presently at that path. abstract S3Objectput(String path, InputStream stream)Creates or overwrites an object at the specified path with its contents uploaded from the given stream. abstract S3Objectput(String path, Function1<StreamingObjectPutParams, Unit> action)Creates or overwrites an object at the configured path with its contents uploaded from the configured stream. abstract S3Objectput(String path, StreamingObjectPutParams params)Creates or overwrites an object at the configured path with its contents uploaded from the configured stream. abstract S3Objectupload(String path, File file)Uploads the specified file to this container at the given path, overwriting any object presently at that path. abstract S3Objectupload(String path, Function1<FileUploadParams, Unit> action)Uploads the configured file to this container at the configured path, overwriting any object presently at that path. abstract S3Objectupload(String path, FileUploadParams params)Uploads the configured file to this container at the configured path, overwriting any object presently at that path. abstract Unitdelete(String path)Deletes the object at the target path from this container. abstract Unitdelete(String path, Function1<DeleteParams, Unit> action)Deletes the object at the target path from this container. abstract Unitdelete(String path, DeleteParams params)Deletes the object at the target path from this container. abstract UnitdeleteAll(String paths)Deletes all the given target objects from this container. abstract UnitdeleteAll(Iterable<String> paths)Deletes all the given target objects from this container. abstract UnitdeleteAll(Function1<MultiObjectDeleteParams, Unit> action)Deletes all the given target objects from this container. abstract UnitdeleteAll(MultiObjectDeleteParams params)Deletes all the given target objects from this container. abstract Unitrmdir(String path)Recursively removes all contents in the target directory. abstract Unitrmdir(String path, Function1<DirectoryDeleteParams, Unit> action)Recursively removes all contents in the target directory. abstract Unitrmdir(String path, DirectoryDeleteParams params)Recursively removes all contents in the target directory. -
-
Method Detail
-
withObject
abstract <R extends Any> R withObject(String path, Function1<S3Object, R> action)
Executes the given action on the target object.
- Parameters:
path- Path/key to the target object.action- Action that will be called on the S3Object handle on the target object.
-
contains
abstract Boolean contains(String path)
Tests whether this object container contains an object at the given path.
- Parameters:
path- Path to the object to test for.
-
contains
abstract Boolean contains(String path, Function1<ObjectExistsParams, Unit> action)
Tests whether this object container contains an object at the configured target path.
- Parameters:
action- Action used to configure the backing S3 operation.
-
contains
abstract Boolean contains(String path, ObjectExistsParams params)
Tests whether this object container contains an object at the configured target path.
- Parameters:
params- Parameters for the backing S3 operation.
-
countAll
abstract UInt countAll(String pathPrefix)
Returns a count of all the objects in this object container, optionally filtered by a given path prefix.
If no path prefix is provided, all paths in this object container will be counted regardless of nested directory depth.
If a path prefix is provided, only paths in this object container whose path name begins with pathPrefix will be counted.
- Parameters:
pathPrefix- Optional filtering prefix.
-
countAll
abstract UInt countAll(Function1<String, Boolean> filter)
Returns a count of all the objects in this object container, filtered by the given predicate function.
The given predicate function will be given each path individually, only those paths on which the predicate returns
truewill be counted.- Parameters:
filter- Predicate that will be used to determine which paths to count and which not to.
-
countSubDirs
abstract UInt countSubDirs(String parent)
Returns a count of first level subdirectories directly under the given parent directory name.
Examples
For these examples our object container is a bucket named "my-bucket".
Given contents of "my-bucket":
/foo/bar.txt /bazz.txt /fizz/buzz/flamingo.txt /fizz/buzz/grapes.pngIf we run the command:
container.countSubDirs()The result will be
2, as at the root of the container the direct subdirectories aremy-bucket/foo/andmy-bucket/fizz/.If we run the command:
container.countSubDirs("foo")The result will be
0as the pathmy-bucket/foo/contains no direct subdirectories.If we run the command:
container.countSubDirs("fizz")The result will be
1as the pathmy-bucket/fizz/contains the direct subdirectory./buzz/- Parameters:
parent- Name of the parent directory under which the subdirectories will be listed.
-
get
abstract S3Object get(String path, Function1<ObjectGetParams, Unit> action)
-
get
abstract S3Object get(String path, ObjectGetParams params)
-
open
abstract StreamObject open(String path)
Fetches the object at the target path and returns a handle on it which can be used to stream out the target object's contents.
If the target path does not exist, or is a directory,
nullwill be returned.- Parameters:
path- Path to the target object.
-
open
abstract StreamObject open(String path, Function1<ObjectOpenParams, Unit> action)
Fetches the configured target object and returns a handle on it which can be used to stream out the target object's contents.
If the target path does not exist, or is a directory,
nullwill be returned.- Parameters:
action- Action used to configure the backing S3 operation.
-
open
abstract StreamObject open(String path, ObjectOpenParams params)
Fetches the configured target object and returns a handle on it which can be used to stream out the target object's contents.
If the target path does not exist, or is a directory,
nullwill be returned.- Parameters:
params- Parameters for the backing S3 operation.
-
download
abstract FileObject download(String path, File localFile)
Fetches the object at the target path and downloads it into the specified local file.
- Parameters:
path- Path to the target object to download.localFile- Target local file into which the object's content will be downloaded.
-
download
abstract FileObject download(String path, Function1<ObjectDownloadParams, Unit> action)
Fetches the object at the configured path and downloads it into the target local file.
- Parameters:
action- Action used to configure the backing S3 operation.
-
download
abstract FileObject download(String path, ObjectDownloadParams params)
Fetches the object at the configured path and downloads it into the target local file.
- Parameters:
params- Parameters for the backing S3 operation.
-
stat
abstract ObjectMeta stat(String path)
Fetches metadata for the object at the target path.
If the target object does not exist,
nullwill be returned.- Parameters:
path- Path to the target object whose metadata should be returned.
-
stat
abstract ObjectMeta stat(String path, Function1<ObjectStatParams, Unit> action)
Fetches metadata for the object at the target path.
If the target object does not exist,
nullwill be returned.- Parameters:
path- Path to the target object whose metadata should be returned.action- Action used to configure the backing S3 operation.
-
stat
abstract ObjectMeta stat(String path, ObjectStatParams params)
Fetches metadata for the object at the target path.
If the target object does not exist,
nullwill be returned.- Parameters:
path- Path to the target object whose metadata should be returned.params- Parameters for the backing S3 operation.
-
listAll
abstract ObjectList listAll()
Fetches a list of all the objects in this container.
-
listAll
abstract ObjectList listAll(Function1<ObjectListAllParams, Unit> action)
Fetches a list of all the objects in this container.
- Parameters:
action- Action used to configure the backing S3 operation.
-
listAll
abstract ObjectList listAll(ObjectListAllParams params)
Fetches a list of all the objects in this container.
- Parameters:
params- Parameters for the backing S3 operation.
-
list
abstract ObjectList list(String prefix)
-
list
abstract ObjectList list(Function1<ObjectListParams, Unit> action)
-
list
abstract ObjectList list(ObjectListParams params)
-
listSubPaths
abstract SubPathListing listSubPaths(String prefix, String delimiter)
-
listSubPaths
abstract SubPathListing listSubPaths(Function1<SubPathListParams, Unit> action)
-
listSubPaths
abstract SubPathListing listSubPaths(SubPathListParams params)
-
touch
abstract S3Object touch(String path)
Creates an empty object at the specified path if one does not already exist.
Unlike the other object put methods, if an object already exists at the given path it will not be overwritten, in that case this method will do nothing.
- Parameters:
path- Path/key for the empty object to create.
-
touch
abstract S3Object touch(String path, Function1<ObjectTouchParams, Unit> action)
Creates an empty object at the specified path if one does not already exist.
Unlike the other object put methods, if an object already exists at the given path it will not be overwritten, in that case this method will do nothing.
- Parameters:
action- Action used to configure the backing S3 operation.
-
touch
abstract S3Object touch(String path, ObjectTouchParams params)
Creates an empty object at the specified path if one does not already exist.
Unlike the other object put methods, if an object already exists at the given path it will not be overwritten, in that case this method will do nothing.
- Parameters:
params- Parameters for the backing S3 operation.
-
set
S3Object set(String path, InputStream stream)
Creates or overwrites an object at the specified path with its contents uploaded from the given stream.
This method is a Kotlin syntax extra that is an alias for put.
- Parameters:
path- Path to the new object to create.stream- Stream whose contents will be written to the object in the store at the given path.
-
set
S3Object set(String path, File file)
Uploads the specified file to this container at the given path, overwriting any object presently at that path.
This method is a Kotlin syntax extra that is an alias for upload.
- Parameters:
path- Path to the object to create/overwrite in this container.file- Local file to upload.
-
put
abstract S3Object put(String path, InputStream stream)
Creates or overwrites an object at the specified path with its contents uploaded from the given stream.
- Parameters:
path- Path to the new object to create.stream- Stream whose contents will be written to the object in the store at the given path.
-
put
abstract S3Object put(String path, Function1<StreamingObjectPutParams, Unit> action)
Creates or overwrites an object at the configured path with its contents uploaded from the configured stream.
- Parameters:
action- Action used to configure the backing S3 operation.
-
put
abstract S3Object put(String path, StreamingObjectPutParams params)
Creates or overwrites an object at the configured path with its contents uploaded from the configured stream.
- Parameters:
params- Parameters for the backing S3 operation.
-
upload
abstract S3Object upload(String path, File file)
Uploads the specified file to this container at the given path, overwriting any object presently at that path.
- Parameters:
path- Path to the object to create/overwrite in this container.file- Local file to upload.
-
upload
abstract S3Object upload(String path, Function1<FileUploadParams, Unit> action)
Uploads the configured file to this container at the configured path, overwriting any object presently at that path.
- Parameters:
action- Action used to configure the backing S3 operation.
-
upload
abstract S3Object upload(String path, FileUploadParams params)
Uploads the configured file to this container at the configured path, overwriting any object presently at that path.
- Parameters:
params- Parameters for the backing S3 operation.
-
delete
abstract Unit delete(String path)
Deletes the object at the target path from this container.
- Parameters:
path- Path to the target object to delete.
-
delete
abstract Unit delete(String path, Function1<DeleteParams, Unit> action)
Deletes the object at the target path from this container.
- Parameters:
action- Action used to configure the backing S3 operation.
-
delete
abstract Unit delete(String path, DeleteParams params)
Deletes the object at the target path from this container.
- Parameters:
params- Parameters for the backing S3 operation.
-
deleteAll
abstract Unit deleteAll(String paths)
Deletes all the given target objects from this container.
If the target paths set is empty, this method does nothing.
- Parameters:
paths- Target paths to delete.
-
deleteAll
abstract Unit deleteAll(Iterable<String> paths)
Deletes all the given target objects from this container.
If the target paths set is empty, this method does nothing.
- Parameters:
paths- Target paths to delete.
-
deleteAll
abstract Unit deleteAll(Function1<MultiObjectDeleteParams, Unit> action)
Deletes all the given target objects from this container.
If the target paths set is empty, this method does nothing.
- Parameters:
action- Action used to configure the backing S3 operation.
-
deleteAll
abstract Unit deleteAll(MultiObjectDeleteParams params)
Deletes all the given target objects from this container.
If the target paths set is empty, this method does nothing.
- Parameters:
params- Parameters for the backing S3 operation.
-
rmdir
abstract Unit rmdir(String path)
Recursively removes all contents in the target directory.
Example
Given the container state:
foo/bar/bazz.txt foo/bar/fizz.txt foo/buzz.txt food/world.pngThe operation:
container.rmdir("foo")Will result in the state:
food/world.png- Parameters:
path- Path to the target directory that will be removed.
-
rmdir
abstract Unit rmdir(String path, Function1<DirectoryDeleteParams, Unit> action)
Recursively removes all contents in the target directory.
Example
Given the container state:
foo/bar/bazz.txt foo/bar/fizz.txt foo/buzz.txt food/world.pngThe operation:
container.rmdir("foo")Will result in the state:
food/world.png- Parameters:
action- Action used to configure the backing S3 operation.
-
rmdir
abstract Unit rmdir(String path, DirectoryDeleteParams params)
Recursively removes all contents in the target directory.
Example
Given the container state:
foo/bar/bazz.txt foo/bar/fizz.txt foo/buzz.txt food/world.pngThe operation:
container.rmdir("foo")Will result in the state:
food/world.png- Parameters:
params- Parameters for the backing S3 operation.
-
-
-
-