Class FileAttributes


  • public class FileAttributes
    extends java.lang.Object
    A collection of FileAttribute values that describe a file.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static FileAttributes EMPTY
      Read-only empty instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(FileAttributeType attributeType, java.lang.Object attributeValue)
      Adds a typed file attribute value.
      void add​(FileAttributeType attributeType, java.lang.String displayName, java.lang.Object attributeValue)
      Adds a typed file attribute value.
      void add​(java.lang.String name, java.lang.Object attributeValue)
      Adds a custom named file attribute.
      FileAttributes clone()  
      boolean contains​(FileAttributeType attributeType)
      Returns true if the specified attribute is present.
      <T> T get​(FileAttributeType attributeType, java.lang.Class<T> valueClass, T defaultValue)
      Gets the value of the specified attribute.
      java.util.List<FileAttribute<?>> getAttributes()
      Return a list of all the attributes added to this instance.
      static FileAttributes of​(FileAttribute<?>... attribs)
      Creates a FileAttributes instance containing the specified attribute values.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

    • Constructor Detail

      • FileAttributes

        public FileAttributes()
        Creates a new / empty FileAttributes instance.
    • Method Detail

      • clone

        public FileAttributes clone()
        Overrides:
        clone in class java.lang.Object
      • add

        public void add​(java.lang.String name,
                        java.lang.Object attributeValue)
        Adds a custom named file attribute.

        The value class should have a reasonable toString() that converts the value to something that is presentable to the user.

        Parameters:
        name - name of the attribute
        attributeValue - value of the attribute
      • add

        public void add​(FileAttributeType attributeType,
                        java.lang.String displayName,
                        java.lang.Object attributeValue)
        Adds a typed file attribute value.

        The value class needs to match FileAttributeType.getValueType().

        Parameters:
        attributeType - FileAttributeType type of this value
        displayName - string used to label the value when displayed to the user
        attributeValue - value of attribute
        Throws:
        java.lang.IllegalArgumentException - if attributeValue does not match attributeType's FileAttributeType.getValueType().
      • get

        public <T> T get​(FileAttributeType attributeType,
                         java.lang.Class<T> valueClass,
                         T defaultValue)
        Gets the value of the specified attribute.
        Type Parameters:
        T - expected class of the attribute value
        Parameters:
        attributeType - FileAttributeType enum type of attribute to search for
        valueClass - java class of the value
        defaultValue - value to return if attribute is not present
        Returns:
        value of requested attribute, or defaultValue if not present
      • getAttributes

        public java.util.List<FileAttribute<?>> getAttributes()
        Return a list of all the attributes added to this instance.
        Returns:
        list of FileAttribute
      • contains

        public boolean contains​(FileAttributeType attributeType)
        Returns true if the specified attribute is present.
        Parameters:
        attributeType - attribute to query
        Returns:
        boolean true if present