Package com.google.common.jimfs
Class AttributeProvider
java.lang.Object
com.google.common.jimfs.AttributeProvider
Abstract provider for handling a specific file attribute view.
- Author:
- Colin Decker
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.collect.ImmutableSet
<String> attributes
(File file) Returns the set of attributes supported by this view that are present in the given file.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
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 Object
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> inherits()
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
name()
Returns the view name that's used to get attributes from this provider.readAttributes
(File file) Reads this provider's attributes from the given file as an attributes object.abstract void
Sets the value of the given attribute in the given file object.boolean
Returns whether or not this provider supports the given attribute directly.protected static IllegalArgumentException
unsettable
(String view, String attribute) Throws an illegal argument exception indicating that the given attribute cannot be set.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.abstract Class
<? extends FileAttributeView> viewType()
Returns the type of the view interface that this provider supports.
-
Constructor Details
-
AttributeProvider
public AttributeProvider()
-
-
Method Details
-
name
Returns the view name that's used to get attributes from this provider. -
inherits
Returns the names of other providers that this provider inherits attributes from. -
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
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
Returns the set of attributes that are always available from this provider. -
supports
Returns whether or not this provider supports the given attribute directly. -
attributes
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
Returns the value of the given attribute in the given file or null if the attribute is not supported by this provider. -
set
Sets the value of the given attribute in the given file object. Thecreate
parameter indicates whether or not the value is being set upon creation of a new file via a user-providedFileAttribute
.- Throws:
IllegalArgumentException
- if the given attribute is one supported by this provider but it is not allowed to be set by the userUnsupportedOperationException
- if the given attribute is one supported by this provider and is allowed to be set by the user, but not on file creation andcreate
is true
-
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
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
Throws an illegal argument exception indicating that the given attribute cannot be set. -
checkNotCreate
Checks that the attribute is not being set by the user on file creation, throwing an unsupported operation exception if it is. -
checkType
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.
-