Chapter 10. Capabilities

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


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

CapabilityUtility classDescription
DCSymbolicLinknoneSymbolicLink entity support. This is still experimental.
ECFileResolvableECFileResolvableUtilFor entities that are backed by a File object, this capability gives access to that File.
ECJarEntryECJarEntryUtilFor 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.
ECMetadataECMetadataUtilMetadata support for entities. This capability give an entity one metadata container. See Chapter 11, Metadata support.
ECNamedMetadataECNamedMetadataUtilMetadata support for entities. This capability give an entity any number of metadata containers. See Chapter 11, Metadata support.
ECNamedEntityAttributesnoneThis capability is supported by entities that have several, named EntityAttributes objects. This is currently not implemented by any capability provider.
ECNtfsAttributesECNtfsAttributesUtilNtfsAttributes support for entities. See Chapter 12, Entity attributes.
ECUnixAttributesECUnixAttributesUtilUnixAttributes support for entities. See Chapter 12, Entity attributes.
ECUriResolvableECUriResolvableUtilFor entities whose locations can be represented by a URI, this capability gives access to that URI.
ECZipEntryECZipEntryUtilFor 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.
FCAppendablenoneThis capability marks that a file can be appended to. It does not have any methods.
FCFileBackedFCFileBackedUtilFor files that are backed by a File object, this capability has methods for manipulating that File.
FCRandomAccessnoneThis capability marks that a file can be opened for random access. It does not have any methods.

Table 10.2. File system capabilities

CapabilityUtility classDescription
FSCAppendableFilesnoneThis capability is supported by file systems whose files can be appended to. It does not have any methods.
FSCCompressionnoneThis capability is supported by file systems that compress file data. It does not have any methods.
FSCDirectoryMetadatanoneThis capability is supported by file systems that support metadata for its directories. It does not have any methods.
FSCFileResolvableFSCFileResolvableUtilCapability supported by file systems whose entities can be resolved using File:s.
FSCJarFileBackedFSCJarFileBackedUtilCapability supported by file systems whose entities are backed by JarFile:s.
FSCMetadatanoneThis capability is supported by file systems that support metadata for its entities. It does not have any methods.
FSCNamedEntityAttributesnoneThis capability is supported by file systems that support named entity attributes objects for its entities. It does not have any methods.
FSCNtfsAttributesnoneThis capability is supported by file systems that support NTFS attributes for its entities. It does not have any methods.
FSCPersistentnoneThis capability is supported by file systems that store entity data in some kind of persistent storage, such as in an ordinary file system.
FSCRandomAccessFilesnoneThis capability is supported by file systems with support for random access to its files.
FSCSymbolicLinknoneThis capability is supported by file systems that support symbolic link entities.
FSCUnixAttributesnoneThis capability is supported by file systems that support Unix attributes for its entities. It does not have any methods.
FSCUriResolvableFSCUriResolvableUtilCapability supported by file systems whose entities can be resolved using URI:s.
FSCZipFileBackedFSCZipFileBackedUtilCapability 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();