Example usage for java.io File isHidden

List of usage examples for java.io File isHidden

Introduction

In this page you can find the example usage for java.io File isHidden.

Prototype

public boolean isHidden() 

Source Link

Document

Tests whether the file named by this abstract pathname is a hidden file.

Usage

From source file:org.paxle.crawler.fs.impl.FsCrawler.java

public ICrawlerDocument request(URI location) {

    final ICrawlerContext ctx = this.contextLocal.getCurrentContext();

    ICrawlerDocument cdoc = null;//from   w w w  .ja v a2s.  c  om
    try {
        // creating an empty crawler-document
        cdoc = ctx.createDocument();

        final ICommandProfile cmdProfile = ctx.getCommandProfile();
        boolean omitHidden = true;
        boolean inclParent = false;
        int readMode = VAL_READ_MODE_STD;
        if (cmdProfile != null) {
            Serializable val;
            if ((val = cmdProfile.getProperty(PROP_VALIDATE_NOT_HIDDEN)) != null)
                omitHidden = ((Boolean) val).booleanValue();
            if ((val = cmdProfile.getProperty(PROP_READ_MODE)) != null)
                readMode = ((Integer) val).intValue();
            if ((val = cmdProfile.getProperty(PROP_INCLUDE_PARENT_DIR)) != null)
                inclParent = ((Boolean) val).booleanValue();
        }

        ICrawlerDocument.Status status = ICrawlerDocument.Status.OK;
        String err = null;
        final File file = new File(location);

        if (!file.exists()) {
            err = "File not found";
            status = ICrawlerDocument.Status.NOT_FOUND;
        } else if (!file.canRead()) {
            err = "Read permission denied";
            status = ICrawlerDocument.Status.UNKNOWN_FAILURE;/*      java 1.6
                                                             } else if (file.isDirectory() && !file.canExecute()) {
                                                             err = "Permission to enter directory denied";
                                                             status = ICrawlerDocument.Status.UNKNOWN_FAILURE;*/
        } else if (omitHidden && file.isHidden()) {
            err = "Hidden";
            status = ICrawlerDocument.Status.UNKNOWN_FAILURE;
        }

        cdoc.setStatus(status);
        if (err != null) {
            logger.warn(String.format("Error crawling %s: %s", location, err));
            cdoc.setStatusText(err);
            return cdoc;
        }

        cdoc.setCrawlerDate(new Date());
        cdoc.setLastModDate(new Date(file.lastModified()));
        cdoc.setLocation(location);

        final ICrawlerTools crawlerTools = ctx.getCrawlerTools();
        if (file.isDirectory()) {
            final File[] list = file.listFiles();
            final Iterator<DirlistEntry> dirlistIt = new DirlistIterator(list, omitHidden);
            try {
                crawlerTools.saveListing(cdoc, dirlistIt, inclParent, list.length > 0);
            } catch (IOException e) {
                final String msg = String.format("Error saving dir-listing for '%s': %s", location,
                        e.getMessage());
                logger.error(msg, e);
                cdoc.setStatus(ICrawlerDocument.Status.UNKNOWN_FAILURE, msg);
                return cdoc;
            }
        } else {
            final File contentFile = generateContentFile(readMode, file, cdoc);
            cdoc.setContent(contentFile);
        }

    } catch (Exception e) {
        final String msg = String.format("Unexpected %s while crawling '%s'", e.getClass().getName(), location);
        logger.error(msg, e);
        if (cdoc != null) {
            cdoc.setStatus(ICrawlerDocument.Status.UNKNOWN_FAILURE, msg);
        }
    }

    return cdoc;
}

From source file:alba.components.FilteredShowFileRequestHandler.java

private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) {
    File adminFile = getAdminFileFromFileSystem(req, rsp, hiddenFiles);

    if (adminFile == null) { // exception already recorded
        return;/*from  w  ww  . j  av  a  2  s  .  c  om*/
    }

    // Make sure the file exists, is readable and is not a hidden file
    if (!adminFile.exists()) {
        log.error("Can not find: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]");
        rsp.setException(new SolrException(ErrorCode.NOT_FOUND,
                "Can not find: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]"));
        return;
    }
    if (!adminFile.canRead() || adminFile.isHidden()) {
        log.error("Can not show: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]");
        rsp.setException(new SolrException(ErrorCode.NOT_FOUND,
                "Can not show: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]"));
        return;
    }

    // Show a directory listing
    if (adminFile.isDirectory()) {
        // it's really a directory, just go for it.
        int basePath = adminFile.getAbsolutePath().length() + 1;
        NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>();
        for (File f : adminFile.listFiles()) {
            String path = f.getAbsolutePath().substring(basePath);
            path = path.replace('\\', '/'); // normalize slashes

            if (isHiddenFile(req, rsp, f.getName().replace('\\', '/'), false, hiddenFiles)) {
                continue;
            }

            SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>();
            files.add(path, fileInfo);
            if (f.isDirectory()) {
                fileInfo.add("directory", true);
            } else {
                // TODO? content type
                fileInfo.add("size", f.length());
            }
            fileInfo.add("modified", new Date(f.lastModified()));
        }
        rsp.add("files", files);
    } else {
        // Include the file contents
        //The file logic depends on RawResponseWriter, so force its use.
        ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
        params.set(CommonParams.WT, "raw");
        req.setParams(params);

        ContentStreamBase content = new ContentStreamBase.FileStream(adminFile);
        content.setContentType(req.getParams().get(USE_CONTENT_TYPE));

        rsp.add(RawResponseWriter.CONTENT, content);
    }
    rsp.setHttpCaching(false);
}

From source file:plugin.notes.gui.NotesTreeNode.java

/**
 * //w  ww  . ja  v  a  2 s. c o  m
 * @param childDir
 * @return true if the file is to be included
 */
private boolean include(File childDir) {
    return childDir.isDirectory() && !childDir.isHidden();
}

From source file:org.jini.commands.files.List.java

/**
 * Print the results//  w ww . j  a  va2s . c o m
 *
 * @param withDetails
 * @param fileList
 * @return
 */
private boolean printResults(boolean withDetails, ArrayList<File> fileList) {

    if (this.getJcError() == false) {
        if (withDetails == true) {
            TablePrinter tableF = new TablePrinter("Name", "Type", "Readable", "Writable", "Executable",
                    "Size KB", "Size MB", "Last Modified");
            for (File v : fileList) {

                java.util.Date lastModified = new java.util.Date(v.lastModified());
                long filesizeInKB = v.length() / 1024;
                double bytes = v.length();
                double kilobytes = (bytes / 1024);
                double megabytes = (kilobytes / 1024);

                String type = "";

                DecimalFormat df = new DecimalFormat("####.####");

                if (v.isDirectory()) {
                    type = "Dir";
                }
                if (v.isFile()) {
                    type = "File";
                }

                if (v.isFile() && v.isHidden()) {
                    type = "File (Hidden)";
                }
                if (v.isDirectory() && (v.isHidden())) {
                    type = "Dir (Hidden)";
                }

                String canExec = "" + v.canExecute();
                String canRead = "" + v.canRead();
                String canWrite = "" + v.canWrite();
                String filesizeInKBStr = Long.toString(filesizeInKB);
                String filesizeInMBStr = df.format(megabytes);

                tableF.addRow(v.getName(), type, canRead, canWrite, canExec, filesizeInKBStr, filesizeInMBStr,
                        lastModified.toString());
            }

            tableF.print();
        } else {
            for (File v : fileList) {
                System.out.println(v.getName());
            }
        }
    }

    return true;
}

From source file:org.eclipse.ice.item.utilities.moose.MOOSEFileHandler.java

/**
 * This method recursively goes through the Block and gives the list of
 * files available in the project to any File Entries.
 * //from   w  ww  . jav a  2 s . c o m
 * @param block
 * @param projectDir
 */
private void setFileEntries(Block block, String projectDir) {
    // Local Declarations
    String availableFiles = "";

    // Search the block with no children
    if (block.getSubblocks().isEmpty()) {
        for (Parameter p : block.getParameters()) {
            if (p.getCpp_type().contains("FileName")) {
                File[] files = new File(projectDir).listFiles();
                for (File file : files) {
                    if (!file.isHidden() && !file.isDirectory()) {
                        // If it is a mesh file, only add exodus extensions
                        if (p.getCpp_type().contains("Mesh")) {
                            String extension = FilenameUtils.getExtension(file.getName());
                            if (extension.equals("e") || extension.equals("exo")) {
                                availableFiles += file.getName() + " ";
                            }
                        } else {
                            availableFiles += file.getName() + " ";
                        }
                    }
                }

                p.setOptions(availableFiles);
            }
        }
    } else {
        // else loop over all sub blocks
        for (Block subBlock : block.getSubblocks()) {
            setFileEntries(subBlock, projectDir);
        }

        // Once we're through that, we still have to check
        // the top level block
        for (Parameter p : block.getParameters()) {
            if (p.getCpp_type().contains("FileName")) {
                File[] files = new File(projectDir).listFiles();
                for (File file : files) {
                    if (!file.isHidden() && !file.isDirectory()) {
                        // If it is a mesh file, only add exodus extensions
                        if (p.getCpp_type().contains("Mesh")) {
                            String extension = FilenameUtils.getExtension(file.getName());
                            if (extension.equals("e") || extension.equals("exo")) {
                                availableFiles += file.getName() + " ";
                            }
                        } else {
                            availableFiles += file.getName() + " ";
                        }
                    }
                }

                p.setOptions(availableFiles);
            }
        }
    }

}

From source file:net.unicon.demetrius.fac.filesystem.FsResourceFactory.java

/**
 * Returns the contents of a given folder.
 * @param f//w  w  w. jav  a  2  s  . c  om
 *  The <code>IFolder</code> for which the contents will be returned.
 * @param rt
 *  The <code>ResourceType[]</code> denotes types of resources to return.
 * @return
 *  An array of <code>IResource</code> objects for the given folder.
 */
public IResource[] getContents(IFolder f, ResourceType[] rt) throws DemetriusException {

    // Assertions.
    if (f == null) {
        String msg = "Argument 'f [IFolder]' cannot be null.";
        throw new IllegalArgumentException(msg);
    }
    if (rt == null) {
        String msg = "Argument 'rt' cannot be null.";
        throw new IllegalArgumentException(msg);
    }

    IResource[] contents = new IResource[0];
    File[] files = null;
    File[] fileTypes = null;
    File[] folderTypes = null;
    File dir = new File(evaluateFsPath(dataSource, f));

    for (int i = 0; i < rt.length; i++) {
        if (rt[i].equals(ResourceType.FOLDER)) {
            folderTypes = dir.listFiles(new FileFilter() {
                public boolean accept(File pathname) {
                    return pathname.isDirectory();
                }
            });
            if (folderTypes != null) {
                files = folderTypes;
            } else {
                throw new DemetriusException("The abstract pathname does not denote a directory.");
            }
        }
        if (rt[i].equals(ResourceType.FILE)) {
            fileTypes = dir.listFiles(new FileFilter() {
                public boolean accept(File pathname) {
                    return pathname.isFile();
                }
            });
            files = fileTypes;
        }
    }

    if (rt.length > 1) {
        files = new File[folderTypes.length + fileTypes.length];
        System.arraycopy(folderTypes, 0, files, 0, folderTypes.length);
        System.arraycopy(fileTypes, 0, files, folderTypes.length, fileTypes.length);
    }

    contents = new IResource[files.length];
    File curr = null;
    for (int i = 0; i < files.length; i++) {
        curr = files[i];
        if (curr.isDirectory()) {
            IResource resource = new FolderImpl(curr.getName(), this, 0, new Date(curr.lastModified()), f,
                    curr.isHidden());
            contents[i] = resource;

        } else {
            IResource resource = new FileImpl(curr.getName(), this, curr.length(),
                    new Date(curr.lastModified()), f, curr.isHidden(), null);
            contents[i] = resource;
        }
    }

    return contents;
}

From source file:com.ehsy.solr.util.SimplePostTool.java

/**
 * Posts a whole directory//from   www  .  j  a v a  2 s .com
 * @return number of files posted total
 */
private int postDirectory(File dir, OutputStream out, String type) {
    if (dir.isHidden() && !dir.getName().equals("."))
        return (0);
    info("Indexing directory " + dir.getPath() + " (" + dir.listFiles(globFileFilter).length + " files, depth="
            + currentDepth + ")");
    int posted = 0;
    posted += postFiles(dir.listFiles(globFileFilter), out, type);
    if (recursive > currentDepth) {
        for (File d : dir.listFiles()) {
            if (d.isDirectory()) {
                currentDepth++;
                posted += postDirectory(d, out, type);
                currentDepth--;
            }
        }
    }
    return posted;
}

From source file:net.unicon.demetrius.fac.filesystem.FsResourceFactory.java

/**
 * Returns the contents of a given folder.
 * @param f//from   w ww . j  a v  a  2s  .c om
 *  The <code>IFolder</code> for which the contents will be returned.
 * @return
 *  An array of <code>IResource</code> objects for the given folder.
 */
public IResource[] getContents(IFolder f) {
    // assertions
    if (f == null) {
        throw new IllegalArgumentException("The given " + "resource must not be null.");
    }

    IResource[] contents = new IResource[0];
    File dir = new File(evaluateFsPath(dataSource, f));
    ;

    File[] folderTypes = dir.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    });

    File[] fileTypes = dir.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.isFile();
        }
    });

    File[] files = null;
    if (folderTypes != null && fileTypes != null) {
        files = new File[folderTypes.length + fileTypes.length];
        System.arraycopy(folderTypes, 0, files, 0, folderTypes.length);
        System.arraycopy(fileTypes, 0, files, folderTypes.length, fileTypes.length);
    } else if (fileTypes != null) {
        files = fileTypes;
    } else if (folderTypes != null) {
        files = folderTypes;
    }

    if (files != null) {
        contents = new IResource[files.length];
        File curr = null;
        for (int i = 0; i < files.length; i++) {
            curr = files[i];
            if (curr.isDirectory()) {
                IResource resource = new FolderImpl(curr.getName(), this, 0, new Date(curr.lastModified()), f,
                        curr.isHidden());
                contents[i] = resource;

            } else {
                IResource resource = new FileImpl(curr.getName(), this, curr.length(),
                        new Date(curr.lastModified()), f, curr.isHidden(), null);
                contents[i] = resource;
            }
        }
    }

    return contents;
}

From source file:com.ehsy.solr.util.SimplePostTool.java

/**
 * Posts a list of file names// w w  w . java 2 s. c  o m
 * @return number of files posted
 */
int postFiles(File[] files, OutputStream out, String type) {
    int filesPosted = 0;
    for (File srcFile : files) {
        try {
            if (!srcFile.isFile() || srcFile.isHidden())
                continue;
            postFile(srcFile, out, type);
            Thread.sleep(delay * 1000);
            filesPosted++;
        } catch (InterruptedException e) {
            throw new RuntimeException();
        }
    }
    return filesPosted;
}

From source file:com.lrodriguez.SVNBrowser.java

private void doGetGetFile2(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    logDebug("dispatching serveFile request");
    if (request.getParameter("serveFile") != null) {
        if (request.getParameter("serveFile").indexOf("..") >= 0) {
            response.sendError(404);/*ww  w . j  a  v a2s  .  co  m*/
            System.err.println("******** Invalid serveFile attempt from " + request.getRemoteAddr());
            return;
        }
        String workingCopyDir = webappRoot
                + getInitParameter(REPOSITORY_DIR).replaceAll("[/\\\\]+", "\\" + File.separator);
        String fileName = workingCopyDir
                + request.getParameter("serveFile").replaceAll("[/\\\\]+", "\\" + File.separator);

        File f = new File(fileName);

        try {
            if (f.getCanonicalPath().indexOf(workingCopyDir) != 0 || !f.exists() || !f.isFile()
                    || f.isHidden()) {
                response.sendError(404);
                System.err.println(
                        "******** Invalid serveFile attempt " + fileName + " from " + request.getRemoteAddr());
                return;
            }
        } catch (IOException e) {
            e.printStackTrace();
            response.sendError(404);
            System.err.println(
                    "******** Invalid serveFile attempt " + fileName + " from " + request.getRemoteAddr());
            return;
        }
        int length = 0;
        byte[] bbuf = new byte[1024];
        DataInputStream in = new DataInputStream(new FileInputStream(f));
        response.setHeader("Content-disposition", "attachment; filename=\"" + request.getParameter("serveFile")
                .substring(request.getParameter("serveFile").lastIndexOf("/") + 1));
        while ((in != null) && ((length = in.read(bbuf)) != -1)) {
            response.getOutputStream().write(bbuf, 0, length);
        }
        in.close();
        response.getOutputStream().flush();
        response.getOutputStream().close();
        return;
    }
}