Class AttributeProvider

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      com.google.common.collect.ImmutableSet<java.lang.String> attributes​(File file)
      Returns the set of attributes supported by this view that are present in the given file.
      @Nullable java.lang.Class<? extends java.nio.file.attribute.BasicFileAttributes> attributesType()
      Returns the type of file attributes object this provider supports, or null if it doesn't support reading its attributes as an object.
      protected static void checkNotCreate​(java.lang.String view, java.lang.String attribute, boolean create)
      Checks that the attribute is not being set by the user on file creation, throwing an unsupported operation exception if it is.
      protected static <T> T checkType​(java.lang.String view, java.lang.String attribute, java.lang.Object value, java.lang.Class<T> type)
      Checks that the given value is of the given type, returning the value if so and throwing an exception if not.
      com.google.common.collect.ImmutableMap<java.lang.String,​?> defaultValues​(java.util.Map<java.lang.String,​?> userDefaults)
      Returns a map containing the default attribute values for this provider.
      abstract com.google.common.collect.ImmutableSet<java.lang.String> fixedAttributes()
      Returns the set of attributes that are always available from this provider.
      abstract @Nullable java.lang.Object get​(File file, java.lang.String attribute)
      Returns the value of the given attribute in the given file or null if the attribute is not supported by this provider.
      com.google.common.collect.ImmutableSet<java.lang.String> inherits()
      Returns the names of other providers that this provider inherits attributes from.
      protected static java.lang.IllegalArgumentException invalidType​(java.lang.String view, java.lang.String attribute, java.lang.Object value, java.lang.Class<?>... expectedTypes)
      Throws an illegal argument exception indicating that the given value is not one of the expected types for the given attribute.
      abstract java.lang.String name()
      Returns the view name that's used to get attributes from this provider.
      java.nio.file.attribute.BasicFileAttributes readAttributes​(File file)
      Reads this provider's attributes from the given file as an attributes object.
      abstract void set​(File file, java.lang.String view, java.lang.String attribute, java.lang.Object value, boolean create)
      Sets the value of the given attribute in the given file object.
      boolean supports​(java.lang.String attribute)
      Returns whether or not this provider supports the given attribute directly.
      protected static java.lang.RuntimeException unsettable​(java.lang.String view, java.lang.String attribute, boolean create)
      Throws a runtime exception indicating that the given attribute cannot be set.
      abstract java.nio.file.attribute.FileAttributeView view​(FileLookup lookup, com.google.common.collect.ImmutableMap<java.lang.String,​java.nio.file.attribute.FileAttributeView> inheritedViews)
      Returns a view of the file located by the given lookup callback.
      abstract java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> viewType()
      Returns the type of the view interface that this provider supports.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AttributeProvider

        public AttributeProvider()
    • Method Detail

      • name

        public abstract java.lang.String name()
        Returns the view name that's used to get attributes from this provider.
      • inherits

        public com.google.common.collect.ImmutableSet<java.lang.String> inherits()
        Returns the names of other providers that this provider inherits attributes from.
      • viewType

        public abstract java.lang.Class<? extends java.nio.file.attribute.FileAttributeView> viewType()
        Returns the type of the view interface that this provider supports.
      • view

        public abstract java.nio.file.attribute.FileAttributeView view​(FileLookup lookup,
                                                                       com.google.common.collect.ImmutableMap<java.lang.String,​java.nio.file.attribute.FileAttributeView> inheritedViews)
        Returns a view of the file located by the given lookup callback. The given map contains the views inherited by this view.
      • defaultValues

        public com.google.common.collect.ImmutableMap<java.lang.String,​?> defaultValues​(java.util.Map<java.lang.String,​?> userDefaults)
        Returns a map containing the default attribute values for this provider. The keys of the map are attribute identifier strings (in "view:attribute" form) and the value for each is the default value that should be set for that attribute when creating a new file.

        The given map should be in the same format and contains user-provided default values. If the user provided any default values for attributes handled by this provider, those values should be checked to ensure they are of the correct type. Additionally, if any changes to a user-provided attribute are necessary (for example, creating an immutable defensive copy), that should be done. The resulting values should be included in the result map along with default values for any attributes the user did not provide a value for.

      • fixedAttributes

        public abstract com.google.common.collect.ImmutableSet<java.lang.String> fixedAttributes()
        Returns the set of attributes that are always available from this provider.
      • supports

        public boolean supports​(java.lang.String attribute)
        Returns whether or not this provider supports the given attribute directly.
      • attributes

        public com.google.common.collect.ImmutableSet<java.lang.String> attributes​(File file)
        Returns the set of attributes supported by this view that are present in the given file. For most providers, this will be a fixed set of attributes.
      • get

        public abstract @Nullable java.lang.Object get​(File file,
                                                       java.lang.String attribute)
        Returns the value of the given attribute in the given file or null if the attribute is not supported by this provider.
      • set

        public abstract void set​(File file,
                                 java.lang.String view,
                                 java.lang.String attribute,
                                 java.lang.Object value,
                                 boolean create)
        Sets the value of the given attribute in the given file object. The create parameter indicates whether or not the value is being set upon creation of a new file via a user-provided FileAttribute.
        Throws:
        java.lang.IllegalArgumentException - if the given attribute is one supported by this provider but it is not allowed to be set by the user
        java.lang.UnsupportedOperationException - if the given attribute is one supported by this provider and is allowed to be set by the user, but not on file creation and create is true
      • attributesType

        public @Nullable java.lang.Class<? extends java.nio.file.attribute.BasicFileAttributes> attributesType()
        Returns the type of file attributes object this provider supports, or null if it doesn't support reading its attributes as an object.
      • readAttributes

        public java.nio.file.attribute.BasicFileAttributes readAttributes​(File file)
        Reads this provider's attributes from the given file as an attributes object.
        Throws:
        java.lang.UnsupportedOperationException - if this provider does not support reading an attributes object
      • unsettable

        protected static java.lang.RuntimeException unsettable​(java.lang.String view,
                                                               java.lang.String attribute,
                                                               boolean create)
        Throws a runtime exception indicating that the given attribute cannot be set.
      • checkNotCreate

        protected static void checkNotCreate​(java.lang.String view,
                                             java.lang.String attribute,
                                             boolean create)
        Checks that the attribute is not being set by the user on file creation, throwing an unsupported operation exception if it is.
      • checkType

        protected static <T> T checkType​(java.lang.String view,
                                         java.lang.String attribute,
                                         java.lang.Object value,
                                         java.lang.Class<T> type)
        Checks that the given value is of the given type, returning the value if so and throwing an exception if not.
      • invalidType

        protected static java.lang.IllegalArgumentException invalidType​(java.lang.String view,
                                                                        java.lang.String attribute,
                                                                        java.lang.Object value,
                                                                        java.lang.Class<?>... expectedTypes)
        Throws an illegal argument exception indicating that the given value is not one of the expected types for the given attribute.