Java Code Examples for org.apache.commons.vfs2.FileSelectInfo#getFile()

The following examples show how to use org.apache.commons.vfs2.FileSelectInfo#getFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CanWriteFileFilter.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to see if the file can be written to.
 *
 * @param fileInfo the File to check
 *
 * @return {@code true} if the file can be written to, otherwise {@code false}.
 * @throws FileSystemException Thrown for file system errors.
 */
@Override
public boolean accept(final FileSelectInfo fileInfo) throws FileSystemException {
    try (final FileObject file = fileInfo.getFile()) {
        final FileSystem fileSystem = file.getFileSystem();
        if (file.exists()) {
            if (!fileSystem.hasCapability(Capability.WRITE_CONTENT)) {
                return false;
            }
            return file.isWriteable();
        }
        if (!fileSystem.hasCapability(Capability.CREATE)) {
            return false;
        }
        return file.getParent().isWriteable();
    }
}
 
Example 2
Source File: EmptyFileFilter.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to see if the file is empty. A non-existing file is also considered empty.
 *
 * @param fileInfo the file or directory to check
 *
 * @return {@code true} if the file or directory is <i>empty</i>, otherwise {@code false}.
 * @throws FileSystemException Thrown for file system errors.
 */
@Override
public boolean accept(final FileSelectInfo fileInfo) throws FileSystemException {
    try (final FileObject file = fileInfo.getFile()) {
        if (!file.exists()) {
            return true;
        }
        if (file.getType() == FileType.FOLDER) {
            final FileObject[] files = file.getChildren();
            return files == null || files.length == 0;
        }
        try (final FileContent content = file.getContent();) {
            return content.isEmpty();
        }
    }
}
 
Example 3
Source File: VerifyingFileSelector.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if a file or folder should be selected.
 */
@Override
public boolean includeFile(final FileSelectInfo fileInfo) throws FileSystemException {
    final FileObject file = fileInfo.getFile();
    if (file == currentFolder) {
        // Pop current folder
        assertEquals(0, children.size());
        currentFolder = currentFolder.getParent();
        currentFolderInfo = currentFolderInfo.getParent();
        children = stack.remove(0);
    }

    final String baseName = file.getName().getBaseName();

    final FileInfo childInfo = getChild(baseName);
    assertSame(childInfo.type, file.getType());

    final boolean isChild = children.remove(baseName);
    assertTrue(isChild);

    files.add(file);
    return true;
}
 
Example 4
Source File: LanguageFileScanSelector.java    From spoofax with Apache License 2.0 5 votes vote down vote up
@Override public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
    final FileObject file = fileInfo.getFile();
    if(isLanguageSpecDirectory(file)) {
        return true;
    }
    return file.getName().getExtension().equals("spoofax-language");
}
 
Example 5
Source File: LanguagesFileSelector.java    From spoofax with Apache License 2.0 4 votes vote down vote up
@Override public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
    final FileObject file = fileInfo.getFile();
    return FileType.FILE.equals(file.getType()) && languageIdentifierService.identify(file, languages) != null;
}
 
Example 6
Source File: SpoofaxIgnoresSelector.java    From spoofax with Apache License 2.0 4 votes vote down vote up
@Override public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
    final int depth = fileInfo.getDepth();
    final FileObject resource = fileInfo.getFile();
    final FileName name = resource.getName();
    final String base = name.getBaseName();

    switch(depth) {
        case 1:
            switch(base) {
                case "include": // Spoofax/Stratego
                case ".cache": // Spoofax/Stratego
                case "bin": // Eclipse
                case ".settings": // Eclipse
                case "target": // Maven
                case ".mvn": // Maven
                case "build": // Gradle
                case ".gradle": // Gradle
                case "out": // IntelliJ
                case ".idea": // IntelliJ
                case ".git": // Git
                    return false;
            }
            break;
        case 3:
            switch(base) {
                // Ignore editor/java/trans and src-gen/stratego-java/trans.
                case "trans": {
                    final FileObject parent1 = resource.getParent();
                    if(parent1 != null) {
                        final String parent1base = parent1.getName().getBaseName();
                        if(parent1base.equals("java") || parent1base.equals("stratego-java")) {
                            final FileObject parent2 = parent1.getParent();
                            if(parent2 != null) {
                                final String parent2base = parent2.getName().getBaseName();
                                return !(parent2base.equals("editor") || parent2base.equals("src-gen"));
                            }
                        }
                    }
                    break;
                }
            }
            break;
    }

    return true;
}
 
Example 7
Source File: LanguageFileScanSelector.java    From spoofax with Apache License 2.0 4 votes vote down vote up
@Override public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
    final FileObject file = fileInfo.getFile();
    // Do not traverse directory if the directory is a language specification with a component config file. This
    // directory will be selected instead.
    return !isLanguageSpecDirectory(file);
}
 
Example 8
Source File: SizeFileFilter.java    From commons-vfs with Apache License 2.0 3 votes vote down vote up
/**
 * Checks to see if the size of the file is favorable.
 * <p>
 * If size equals threshold and smaller files are required, file <b>IS NOT</b>
 * selected. If size equals threshold and larger files are required, file
 * <b>IS</b> selected.
 * </p>
 * <p>
 * Non-existing files return always false (will never be accepted).
 * </p>
 *
 * @param fileInfo the File to check
 *
 * @return true if the file name matches
 * @throws FileSystemException Thrown for file system errors.
 */
@Override
public boolean accept(final FileSelectInfo fileInfo) throws FileSystemException {
    try (final FileObject file = fileInfo.getFile()) {
        if (!file.exists()) {
            return false;
        }
        try (final FileContent content = file.getContent();) {
            final long length = content.getSize();
            final boolean smaller = length < size;
            return acceptLarger ? !smaller : smaller;
        }
    }
}