Example usage for org.apache.commons.vfs2 FileSystem hasCapability

List of usage examples for org.apache.commons.vfs2 FileSystem hasCapability

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileSystem hasCapability.

Prototype

boolean hasCapability(Capability capability);

Source Link

Document

Determines if this file system has a particular capability.

Usage

From source file:org.fuin.vfs2.filter.CanWriteFileFilter.java

/**
 * Checks to see if the file can be written to.
 * // ww w .  j  a  v  a  2  s. co  m
 * @param fileInfo
 *            the File to check
 * 
 * @return {@code true} if the file can be written to, otherwise
 *         {@code false}.
 */
@Override
public boolean accept(final FileSelectInfo fileInfo) {
    try {
        final FileSystem fileSystem = fileInfo.getFile().getFileSystem();
        if (fileInfo.getFile().exists()) {
            if (!fileSystem.hasCapability(Capability.WRITE_CONTENT)) {
                return false;
            }
            return fileInfo.getFile().isWriteable();
        } else {
            if (!fileSystem.hasCapability(Capability.CREATE)) {
                return false;
            }
            return fileInfo.getFile().getParent().isWriteable();
        }
    } catch (final FileSystemException ex) {
        throw new RuntimeException(ex);
    }
}