Package software.amazon.nio.spi.s3
Class S3BasicFileAttributes
- java.lang.Object
-
- software.amazon.nio.spi.s3.S3BasicFileAttributes
-
- All Implemented Interfaces:
java.nio.file.attribute.BasicFileAttributes
public class S3BasicFileAttributes extends java.lang.Object implements java.nio.file.attribute.BasicFileAttributesRepresentation ofBasicFileAttributesfor an S3 object
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedS3BasicFileAttributes(S3Path path)Constructor for the attributes of a pathprotectedS3BasicFileAttributes(S3Path path, software.amazon.awssdk.services.s3.S3AsyncClient client)Constructor for the attributes of a path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Map<java.lang.String,java.lang.Object>asMap()Construct aMaprepresentation of this objectprotected java.util.Map<java.lang.String,java.lang.Object>asMap(java.util.function.Predicate<java.lang.String> attributeFilter)Construct aMaprepresentation of this object with properties filteredjava.nio.file.attribute.FileTimecreationTime()Returns the creation time.java.lang.ObjectfileKey()Returns the S3 etag for the objectbooleanisDirectory()Tells whether the file is a directory.booleanisOther()Tells whether the file is something other than a regular file, directory, or symbolic link.booleanisRegularFile()Tells whether the file is a regular file with opaque content.booleanisSymbolicLink()Tells whether the file is a symbolic link.java.nio.file.attribute.FileTimelastAccessTime()Returns the time of last access.java.nio.file.attribute.FileTimelastModifiedTime()Returns the time of last modification.longsize()Returns the size of the file (in bytes).
-
-
-
Constructor Detail
-
S3BasicFileAttributes
protected S3BasicFileAttributes(S3Path path)
Constructor for the attributes of a path- Parameters:
path- the path to represent the attributes of
-
S3BasicFileAttributes
protected S3BasicFileAttributes(S3Path path, software.amazon.awssdk.services.s3.S3AsyncClient client)
Constructor for the attributes of a path. A client is provided to perform any necessary S3 operations. This method is suitable for Mocking by providing a Mocked client.- Parameters:
path- the path to represent the attributes ofclient- the client to use for any S3 operations
-
-
Method Detail
-
lastModifiedTime
public java.nio.file.attribute.FileTime lastModifiedTime()
Returns the time of last modification.S3 "directories" do not support a time stamp to indicate the time of last modification therefore this method returns a default value representing the epoch (1970-01-01T00:00:00Z) as a proxy
- Specified by:
lastModifiedTimein interfacejava.nio.file.attribute.BasicFileAttributes- Returns:
- a
FileTimerepresenting the time the file was last modified. - Throws:
java.lang.RuntimeException- if the S3ClientsRetryConditionsconfiguration was not able to handle the exception.
-
lastAccessTime
public java.nio.file.attribute.FileTime lastAccessTime()
Returns the time of last access.Without enabling S3 server access logging, CloudTrail or similar it is not possible to obtain the access time of an object, therefore the current implementation will return the @{code lastModifiedTime}
- Specified by:
lastAccessTimein interfacejava.nio.file.attribute.BasicFileAttributes- Returns:
- a
FileTimerepresenting the time of last access
-
creationTime
public java.nio.file.attribute.FileTime creationTime()
Returns the creation time. The creation time is the time that the file was created.Any modification of an S3 object results in a new Object so this time will be the same as
lastModifiedTime. A future implementation could consider times for versioned objects.- Specified by:
creationTimein interfacejava.nio.file.attribute.BasicFileAttributes- Returns:
- a
FileTimerepresenting the time the file was created
-
isRegularFile
public boolean isRegularFile()
Tells whether the file is a regular file with opaque content.- Specified by:
isRegularFilein interfacejava.nio.file.attribute.BasicFileAttributes- Returns:
trueif the file is a regular file with opaque content
-
isDirectory
public boolean isDirectory()
Tells whether the file is a directory.- Specified by:
isDirectoryin interfacejava.nio.file.attribute.BasicFileAttributes- Returns:
trueif the file is a directory
-
isSymbolicLink
public boolean isSymbolicLink()
Tells whether the file is a symbolic link.- Specified by:
isSymbolicLinkin interfacejava.nio.file.attribute.BasicFileAttributes- Returns:
falsealways as S3 has no links
-
isOther
public boolean isOther()
Tells whether the file is something other than a regular file, directory, or symbolic link. There are only objects in S3 and inferred directories- Specified by:
isOtherin interfacejava.nio.file.attribute.BasicFileAttributes- Returns:
falsealways
-
size
public long size() throws java.lang.RuntimeExceptionReturns the size of the file (in bytes). The size may differ from the actual size on the file system due to compression, support for sparse files, or other reasons. The size of files that are notregularfiles is implementation specific and therefore unspecified.- Specified by:
sizein interfacejava.nio.file.attribute.BasicFileAttributes- Returns:
- the file size, in bytes
- Throws:
java.lang.RuntimeException- if the S3ClientsRetryConditionsconfiguration was not able to handle the exception.
-
fileKey
public java.lang.Object fileKey()
Returns the S3 etag for the object- Specified by:
fileKeyin interfacejava.nio.file.attribute.BasicFileAttributes- Returns:
- the etag for an object, or
nullfor a "directory" - Throws:
java.lang.RuntimeException- if the S3ClientsRetryConditionsconfiguration was not able to handle the exception.- See Also:
Files.walkFileTree(java.nio.file.Path, java.util.Set<java.nio.file.FileVisitOption>, int, java.nio.file.FileVisitor<? super java.nio.file.Path>)
-
asMap
protected java.util.Map<java.lang.String,java.lang.Object> asMap()
Construct aMaprepresentation of this object- Returns:
- a map
-
asMap
protected java.util.Map<java.lang.String,java.lang.Object> asMap(java.util.function.Predicate<java.lang.String> attributeFilter)
Construct aMaprepresentation of this object with properties filtered- Parameters:
attributeFilter- a filter to include properties in the resulting Map- Returns:
- a map filtered to only contain keys that pass the attributeFilter
-
-