Standard file system and entity functionality is extended by capabilities. The capabilities that a file system and its entities have is decided when the file system is created by adding CapabilityProvider:s to its builder. All file system implementations also have built-in capabilities, see Table 4.1, “File system implementations”.
When mixing some capabilities, the order in which the capability providers are added to the file system may be important. Restrictions are documented in each capability provider's API documentation.
Capabilities are used by first retrieving a capability object from a file system or from an entity. The capability is identified by a capability-specific FileSystemCapabilityType or EntityCapabilityType constant.
Below is an example of how the ECUnixAttributes entity capability can be used to get the creation time for an entity. Entity attributes are explained more in detail in Chapter 12, Entity attributes.
Example 10.1. Using Unix entity attributes to get an entity's creation time
// Use the Unix entity attributes capability to find out when the EFile f was // created // First get the capability object for the file ECUnixAttributes eua = f.getCapability(ECTUnixAttributes.TYPE); long timestamp = eua.getAttributes().getCreationTime();
Most capabilities have their own utility classes that can be used to make the client code shorter and more readable. The example below accomplishes just the same as the previous example, but with less code.
Example 10.2. Using Unix entity attributes utility class to get an entity's creation time
// Use the Unix entity attributes capability utility object to find out when the // EFile f was created long timestamp = ECUnixAttributesUtil.getCreationTime(f);
The name of an entity capability object shows for which entity types it is
used. If the name starts with FC
, the capability
is used for EFile:s. If it starts with DC
,
it is used for Directory:s. An entity capability name starting with
EC
is used for all entity types.
Table 10.1. Entity capabilities
Capability | Utility class | Description |
---|---|---|
DCSymbolicLink | none | SymbolicLink entity support. This is still experimental. |
ECFileResolvable | ECFileResolvableUtil | For entities that are backed by a File object, this capability gives access to that File. |
ECJarEntry | ECJarEntryUtil | For entities that have a JarEntry object, this capability gives access to that object. This is true for all entities in a Jar file system. See Chapter 14, Zip and Jar files. |
ECMetadata | ECMetadataUtil | Metadata support for entities. This capability give an entity one metadata container. See Chapter 11, Metadata support. |
ECNamedMetadata | ECNamedMetadataUtil | Metadata support for entities. This capability give an entity any number of metadata containers. See Chapter 11, Metadata support. |
ECNamedEntityAttributes | none | This capability is supported by entities that have several, named EntityAttributes objects. This is currently not implemented by any capability provider. |
ECNtfsAttributes | ECNtfsAttributesUtil | NtfsAttributes support for entities. See Chapter 12, Entity attributes. |
ECUnixAttributes | ECUnixAttributesUtil | UnixAttributes support for entities. See Chapter 12, Entity attributes. |
ECUriResolvable | ECUriResolvableUtil | For entities whose locations can be represented by a URI, this capability gives access to that URI. |
ECZipEntry | ECZipEntryUtil | For entities that have a ZipEntry object, this capability gives access to that object. This is true for all entities in a Zip or a Jar file system. See Chapter 14, Zip and Jar files. |
FCAppendable | none | This capability marks that a file can be appended to. It does not have any methods. |
FCFileBacked | FCFileBackedUtil | For files that are backed by a File object, this capability has methods for manipulating that File. |
FCRandomAccess | none | This capability marks that a file can be opened for random access. It does not have any methods. |
Table 10.2. File system capabilities
Capability | Utility class | Description |
---|---|---|
FSCAppendableFiles | none | This capability is supported by file systems whose files can be appended to. It does not have any methods. |
FSCCompression | none | This capability is supported by file systems that compress file data. It does not have any methods. |
FSCDirectoryMetadata | none | This capability is supported by file systems that support metadata for its directories. It does not have any methods. |
FSCFileResolvable | FSCFileResolvableUtil | Capability supported by file systems whose entities can be resolved using File:s. |
FSCJarFileBacked | FSCJarFileBackedUtil | Capability supported by file systems whose entities are backed by JarFile:s. |
FSCMetadata | none | This capability is supported by file systems that support metadata for its entities. It does not have any methods. |
FSCNamedEntityAttributes | none | This capability is supported by file systems that support named entity attributes objects for its entities. It does not have any methods. |
FSCNtfsAttributes | none | This capability is supported by file systems that support NTFS attributes for its entities. It does not have any methods. |
FSCPersistent | none | This capability is supported by file systems that store entity data in some kind of persistent storage, such as in an ordinary file system. |
FSCRandomAccessFiles | none | This capability is supported by file systems with support for random access to its files. |
FSCSymbolicLink | none | This capability is supported by file systems that support symbolic link entities. |
FSCUnixAttributes | none | This capability is supported by file systems that support Unix attributes for its entities. It does not have any methods. |
FSCUriResolvable | FSCUriResolvableUtil | Capability supported by file systems whose entities can be resolved using URI:s. |
FSCZipFileBacked | FSCZipFileBackedUtil | Capability supported by file systems whose entities are backed by ZipFile:s. |
Table 10.3. Capability providers
Example 10.3. Creating a Ram file system with gzip compression of file data
FileSystem fs = new RamFileSystemBuilder(). addCapabilityProvider( new GZipCompressionCapabilityProvider()).create();