Class AttributeProvider

java.lang.Object
com.google.common.jimfs.AttributeProvider
Direct Known Subclasses:
AclAttributeProvider, BasicAttributeProvider, DosAttributeProvider, OwnerAttributeProvider, PosixAttributeProvider, UnixAttributeProvider, UserDefinedAttributeProvider

public abstract class AttributeProvider extends Object
Abstract provider for handling a specific file attribute view.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.google.common.collect.ImmutableSet<String>
    Returns the set of attributes supported by this view that are present in the given file.
    @Nullable Class<? extends BasicFileAttributes>
    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(String view, 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(String view, String attribute, Object value, 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<String,?>
    defaultValues(Map<String,?> userDefaults)
    Returns a map containing the default attribute values for this provider.
    abstract com.google.common.collect.ImmutableSet<String>
    Returns the set of attributes that are always available from this provider.
    abstract @Nullable Object
    get(File file, 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<String>
    Returns the names of other providers that this provider inherits attributes from.
    protected static IllegalArgumentException
    invalidType(String view, String attribute, Object value, Class<?>... expectedTypes)
    Throws an illegal argument exception indicating that the given value is not one of the expected types for the given attribute.
    abstract String
    Returns the view name that's used to get attributes from this provider.
    Reads this provider's attributes from the given file as an attributes object.
    abstract void
    set(File file, String view, String attribute, Object value, boolean create)
    Sets the value of the given attribute in the given file object.
    boolean
    supports(String attribute)
    Returns whether or not this provider supports the given attribute directly.
    protected static RuntimeException
    unsettable(String view, String attribute, boolean create)
    Throws a runtime exception indicating that the given attribute cannot be set.
    view(FileLookup lookup, com.google.common.collect.ImmutableMap<String,FileAttributeView> inheritedViews)
    Returns a view of the file located by the given lookup callback.
    abstract Class<? extends FileAttributeView>
    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 Details

    • AttributeProvider

      public AttributeProvider()
  • Method Details

    • name

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

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

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

      public abstract FileAttributeView view(FileLookup lookup, com.google.common.collect.ImmutableMap<String,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<String,?> defaultValues(Map<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<String> fixedAttributes()
      Returns the set of attributes that are always available from this provider.
    • supports

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

      public com.google.common.collect.ImmutableSet<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 Object get(File file, 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, String view, String attribute, 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:
      IllegalArgumentException - if the given attribute is one supported by this provider but it is not allowed to be set by the user
      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 Class<? extends 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 BasicFileAttributes readAttributes(File file)
      Reads this provider's attributes from the given file as an attributes object.
      Throws:
      UnsupportedOperationException - if this provider does not support reading an attributes object
    • unsettable

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

      protected static void checkNotCreate(String view, 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(String view, String attribute, Object value, 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 IllegalArgumentException invalidType(String view, String attribute, Object value, Class<?>... expectedTypes)
      Throws an illegal argument exception indicating that the given value is not one of the expected types for the given attribute.