Class S3BasicFileAttributes

  • All Implemented Interfaces:
    java.nio.file.attribute.BasicFileAttributes

    public class S3BasicFileAttributes
    extends java.lang.Object
    implements java.nio.file.attribute.BasicFileAttributes
    Representation of BasicFileAttributes for an S3 object
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected S3BasicFileAttributes​(S3Path path)
      Constructor for the attributes of a path
      protected S3BasicFileAttributes​(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 a Map representation of this object
      protected java.util.Map<java.lang.String,​java.lang.Object> asMap​(java.util.function.Predicate<java.lang.String> attributeFilter)
      Construct a Map representation of this object with properties filtered
      java.nio.file.attribute.FileTime creationTime()
      Returns the creation time.
      java.lang.Object fileKey()
      Returns the S3 etag for the object
      boolean isDirectory()
      Tells whether the file is a directory.
      boolean isOther()
      Tells whether the file is something other than a regular file, directory, or symbolic link.
      boolean isRegularFile()
      Tells whether the file is a regular file with opaque content.
      boolean isSymbolicLink()
      Tells whether the file is a symbolic link.
      java.nio.file.attribute.FileTime lastAccessTime()
      Returns the time of last access.
      java.nio.file.attribute.FileTime lastModifiedTime()
      Returns the time of last modification.
      long size()
      Returns the size of the file (in bytes).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 of
        client - 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:
        lastModifiedTime in interface java.nio.file.attribute.BasicFileAttributes
        Returns:
        a FileTime representing the time the file was last modified.
        Throws:
        java.lang.RuntimeException - if the S3Clients RetryConditions configuration 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:
        lastAccessTime in interface java.nio.file.attribute.BasicFileAttributes
        Returns:
        a FileTime representing 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:
        creationTime in interface java.nio.file.attribute.BasicFileAttributes
        Returns:
        a FileTime representing the time the file was created
      • isRegularFile

        public boolean isRegularFile()
        Tells whether the file is a regular file with opaque content.
        Specified by:
        isRegularFile in interface java.nio.file.attribute.BasicFileAttributes
        Returns:
        true if the file is a regular file with opaque content
      • isDirectory

        public boolean isDirectory()
        Tells whether the file is a directory.
        Specified by:
        isDirectory in interface java.nio.file.attribute.BasicFileAttributes
        Returns:
        true if the file is a directory
      • isSymbolicLink

        public boolean isSymbolicLink()
        Tells whether the file is a symbolic link.
        Specified by:
        isSymbolicLink in interface java.nio.file.attribute.BasicFileAttributes
        Returns:
        false always 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:
        isOther in interface java.nio.file.attribute.BasicFileAttributes
        Returns:
        false always
      • size

        public long size()
                  throws java.lang.RuntimeException
        Returns 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 not regular files is implementation specific and therefore unspecified.
        Specified by:
        size in interface java.nio.file.attribute.BasicFileAttributes
        Returns:
        the file size, in bytes
        Throws:
        java.lang.RuntimeException - if the S3Clients RetryConditions configuration was not able to handle the exception.
      • fileKey

        public java.lang.Object fileKey()
        Returns the S3 etag for the object
        Specified by:
        fileKey in interface java.nio.file.attribute.BasicFileAttributes
        Returns:
        the etag for an object, or null for a "directory"
        Throws:
        java.lang.RuntimeException - if the S3Clients RetryConditions configuration 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 a Map representation 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 a Map representation 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