Example usage for org.apache.commons.vfs2 FileObject isHidden

List of usage examples for org.apache.commons.vfs2 FileObject isHidden

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject isHidden.

Prototype

boolean isHidden() throws FileSystemException;

Source Link

Document

Determines if this file is hidden.

Usage

From source file:org.renjin.primitives.files.Files.java

/**
 * {@code list.files} produce a character vector of the names of files in the named directory.
 *
 * @param paths  a character vector of full path names; the default corresponds to the working
 *  directory getwd(). Missing values will be ignored.
 * @param pattern an optional regular expression. Only file names which match the regular
 * expression will be returned.//w w  w  .  j  a  v a  2 s  .  c  o m
 * @param allFiles  If FALSE, only the names of visible files are returned. If TRUE, all
 * file names will be returned.
 * @param fullNames If TRUE, the directory path is prepended to the file names. If FALSE,
 * only the file names are returned.
 * @param recursive Should the listing recurse into directories?
 * @param ignoreCase Should pattern-matching be case-insensitive?
 *
 * If a path does not exist or is not a directory or is unreadable it is skipped, with a warning.
 * The files are sorted in alphabetical order, on the full path if full.names = TRUE. Directories are included only if recursive = FALSE.
 *
 * @return
 */
@Internal("list.files")
public static StringVector listFiles(@Current final Context context, final StringVector paths,
        final String pattern, final boolean allFiles, final boolean fullNames, final boolean recursive,
        final boolean ignoreCase, final boolean includeDirs) throws IOException {

    return new Object() {

        private final StringVector.Builder result = new StringVector.Builder();
        private final RE filter = pattern == null ? null : new ExtendedRE(pattern).ignoreCase(ignoreCase);

        public StringVector list() throws IOException {
            for (String path : paths) {
                FileObject folder = context.resolveFile(path);
                if (folder.getType() == FileType.FOLDER) {
                    if (allFiles & !recursive) {
                        add(path, ".");
                        add(path, "..");
                    }
                    for (FileObject child : folder.getChildren()) {
                        if (filter(child)) {
                            add(path, child);
                        }
                    }
                }
            }
            return result.build();
        }

        void add(String path, FileObject file) {
            if (fullNames) {
                result.add(path + "/" + file.getName().getBaseName());
            } else {
                result.add(file.getName().getBaseName());
            }
        }

        void add(String path, String name) throws FileSystemException {
            if (fullNames) {
                result.add(path + "/" + name);
            } else {
                result.add(name);
            }
        }

        boolean filter(FileObject child) throws FileSystemException {
            if (!allFiles && isHidden(child)) {
                return false;
            }
            if (recursive && !includeDirs && child.getType() == FileType.FOLDER) {
                return false;
            }
            if (filter != null && !filter.match(child.getName().getBaseName())) {
                return false;
            }
            return true;
        }

        private boolean isHidden(FileObject file) throws FileSystemException {
            return file.isHidden() || file.getName().getBaseName().startsWith(".");
        }
    }.list();
}

From source file:pl.otros.vfs.browser.table.VfsTableModelHiddenFileRowFilter.java

protected boolean checkIfInclude(FileObject fileObject) {
    if (!showHidden) {
        try {/*from w  w w. ja  v  a  2s.c  o m*/
            if (fileObject.getName().getBaseName().startsWith(".") || fileObject.isHidden()) {
                return false;
            }
        } catch (FileSystemException e) {

        }
    }
    return true;
}

From source file:pl.otros.vfs.browser.table.VfsTableModelHiddenFileRowFilterTest.java

@Test(dataProvider = "candidateFiles")
public void testCheckIfInclude(String path, boolean hiddenAttribute, boolean showHidden, boolean expected)
        throws Exception {
    //given/* w w w  . ja  va2s . c  o m*/
    VfsTableModelHiddenFileRowFilter rowFilter = new VfsTableModelHiddenFileRowFilter(showHidden);
    FileObject fileObject = mock(FileObject.class);
    FileName fileName = mock(FileName.class);
    when(fileObject.getName()).thenReturn(fileName);
    when(fileName.getBaseName()).thenReturn(path);
    when(fileObject.isHidden()).thenReturn(hiddenAttribute);

    //when
    boolean result = rowFilter.checkIfInclude(fileObject);

    //then
    Assert.assertEquals(result, expected,
            String.format("Result for file \"%s\" with hidden attribute %s and showHidden checked %s should "
                    + "be %s, was %s", path, hiddenAttribute, showHidden, result, expected));

}

From source file:poisondog.commons.vfs.AllNotHiddenFile.java

@Override
public boolean includeFile(FileSelectInfo fileInfo) {
    FileObject file = fileInfo.getFile();
    try {//from   www . ja  v a2 s .com
        if (file.getType() == FileType.FOLDER)
            return false;
        if (file.isHidden())
            return false;
    } catch (Exception e) {
    }
    return super.includeFile(fileInfo);
}

From source file:poisondog.commons.vfs.AllNotHiddenFile.java

@Override
public boolean traverseDescendents(FileSelectInfo fileInfo) {
    FileObject file = fileInfo.getFile();
    try {/*from   w  ww .j a v  a 2 s  .  c o m*/
        if (file.isHidden()) {
            return false;
        }
    } catch (Exception e) {
    }
    return super.traverseDescendents(fileInfo);
}

From source file:se.kth.hopsworks.zeppelin.notebook.repo.FSNotebookRepo.java

@Override
public List<NoteInfo> list() throws IOException {
    FileObject rootDir = getRootDir();
    FileObject projectDir = null;
    if (this.project != null) {
        projectDir = rootDir.resolveFile(this.project.getName(), NameScope.CHILD);
    }//from ww w.  j  ava 2s .c  o  m

    LinkedList<FileObject> children = getNotes(rootDir, projectDir);

    List<NoteInfo> infos = new LinkedList<>();
    for (FileObject f : children) {
        String fileName = f.getName().getBaseName();
        if (f.isHidden() || fileName.startsWith(".") || fileName.startsWith("#") || fileName.startsWith("~")) {
            // skip hidden, temporary files
            continue;
        }

        if (!isDirectory(f)) {
            // currently single note is saved like, [NOTE_ID]/note.json.
            // so it must be a directory
            continue;
        }

        NoteInfo info = null;

        try {
            info = getNoteInfo(f);
            if (info != null) {
                infos.add(info);
            }
        } catch (IOException e) {
            logger.error("Can't read note " + f.getName().toString(), e);
        }
    }

    return infos;
}