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:de.mprengemann.intellij.plugin.androidicons.dialogs.AndroidMultiDrawableImporter.java

private void importZipArchive(VirtualFile virtualFile) {
    final String filePath = virtualFile.getCanonicalPath();
    if (filePath == null) {
        return;/*from ww w .  j  ava2 s .  co m*/
    }
    final File tempDir = new File(ImageInformation.getTempDir(), virtualFile.getNameWithoutExtension());
    final String archiveName = virtualFile.getName();
    new Task.Modal(project, "Importing Archive...", true) {
        @Override
        public void run(@NotNull final ProgressIndicator progressIndicator) {
            progressIndicator.setIndeterminate(true);
            try {
                FileUtils.forceMkdir(tempDir);
                ZipUtil.extract(new File(filePath), tempDir, new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        final String mimeType = new MimetypesFileTypeMap().getContentType(name);
                        final String type = mimeType.split("/")[0];
                        return type.equals("image");
                    }
                }, true);
                progressIndicator.checkCanceled();

                final Iterator<File> fileIterator = FileUtils.iterateFiles(tempDir, TrueFileFilter.INSTANCE,
                        TrueFileFilter.INSTANCE);
                while (fileIterator.hasNext()) {
                    File file = fileIterator.next();
                    if (file.isDirectory() || file.isHidden()) {
                        continue;
                    }
                    final String fileRoot = file.getParent().toUpperCase();
                    final String name = FilenameUtils.getBaseName(file.toString());
                    if (name.startsWith(".") || fileRoot.contains("__MACOSX")) {
                        continue;
                    }
                    for (Resolution resolution : RESOLUTIONS) {
                        if (name.toUpperCase().contains("-" + resolution)
                                || name.toUpperCase().contains("_" + resolution)
                                || fileRoot.contains(resolution.toString())) {
                            controller.addZipImage(file, resolution);
                            break;
                        }
                    }
                }
                progressIndicator.checkCanceled();

                final Map<Resolution, List<ImageInformation>> zipImages = controller.getZipImages();
                final List<Resolution> foundResolutions = new ArrayList<Resolution>();
                int foundAssets = 0;
                for (Resolution resolution : zipImages.keySet()) {
                    final List<ImageInformation> assetInformation = zipImages.get(resolution);
                    if (assetInformation != null && assetInformation.size() > 0) {
                        foundAssets += assetInformation.size();
                        foundResolutions.add(resolution);
                    }
                }
                progressIndicator.checkCanceled();

                final int finalFoundAssets = foundAssets;
                UIUtil.invokeLaterIfNeeded(new DumbAwareRunnable() {
                    public void run() {
                        final String title = String.format("Import '%s'", archiveName);
                        if (foundResolutions.size() == 0 || finalFoundAssets == 0) {
                            Messages.showErrorDialog("No assets found.", title);
                            FileUtils.deleteQuietly(tempDir);
                            return;
                        }
                        final String[] options = new String[] { "Import", "Cancel" };
                        final String description = String.format("Import %d assets for %s to %s.",
                                finalFoundAssets, StringUtils.join(foundResolutions, ", "),
                                controller.getTargetRoot());
                        final int selection = Messages.showDialog(description, title, options, 0,
                                Messages.getQuestionIcon());
                        if (selection == 0) {
                            controller.getZipTask(project, tempDir).queue();
                            close(0);
                        } else {
                            FileUtils.deleteQuietly(tempDir);
                        }
                    }
                });
            } catch (ProcessCanceledException e) {
                FileUtils.deleteQuietly(tempDir);
            } catch (IOException e) {
                LOGGER.error(e);
            }
        }
    }.queue();
}

From source file:net.pms.dlna.MapFile.java

private void manageFile(File f) {
    if (f.isFile() || f.isDirectory()) {
        String lcFilename = f.getName().toLowerCase();

        if (!f.isHidden()) {
            if (configuration.isArchiveBrowsing()
                    && (lcFilename.endsWith(".zip") || lcFilename.endsWith(".cbz"))) {
                addChild(new ZippedFile(f));
            } else if (configuration.isArchiveBrowsing()
                    && (lcFilename.endsWith(".rar") || lcFilename.endsWith(".cbr"))) {
                addChild(new RarredFile(f));
            } else if (configuration.isArchiveBrowsing()
                    && (lcFilename.endsWith(".tar") || lcFilename.endsWith(".gzip")
                            || lcFilename.endsWith(".gz") || lcFilename.endsWith(".7z"))) {
                addChild(new SevenZipFile(f));
            } else if ((lcFilename.endsWith(".iso") || lcFilename.endsWith(".img"))
                    || (f.isDirectory() && f.getName().toUpperCase().equals("VIDEO_TS"))) {
                addChild(new DVDISOFile(f));
            } else if (lcFilename.endsWith(".m3u") || lcFilename.endsWith(".m3u8")
                    || lcFilename.endsWith(".pls") || lcFilename.endsWith(".cue")
                    || lcFilename.endsWith(".ups")) {
                DLNAResource d = PlaylistFolder.getPlaylist(lcFilename, f.getAbsolutePath(), 0);
                if (d != null) {
                    addChild(d);//w  ww .j  a  v  a 2s.  com
                }
            } else {
                /* Optionally ignore empty directories */
                if (f.isDirectory() && configuration.isHideEmptyFolders()
                        && !FileUtil.isFolderRelevant(f, configuration)) {
                    LOGGER.debug("Ignoring empty/non-relevant directory: " + f.getName());
                    // Keep track of the fact that we have empty folders, so when we're asked if we should refresh,
                    // we can re-scan the folders in this list to see if they contain something relevant
                    if (emptyFoldersToRescan == null) {
                        emptyFoldersToRescan = new ArrayList<>();
                    }
                    if (!emptyFoldersToRescan.contains(f)) {
                        emptyFoldersToRescan.add(f);
                    }
                } else { // Otherwise add the file
                    RealFile rf = new RealFile(f);
                    if (searchList != null) {
                        searchList.add(rf);
                    }
                    addChild(rf);
                }
            }
        }

        // FIXME this causes folder thumbnails to take precedence over file thumbnails
        if (f.isFile() && (lcFilename.equals("folder.jpg") || lcFilename.equals("folder.png")
                || (lcFilename.contains("albumart") && lcFilename.endsWith(".jpg")))) {
            potentialCover = f;
        }
    }
}

From source file:br.com.thinkti.android.filechooserfrag.fragFileChooser.java

private void fill(File f) {
    File[] dirs = null;/*  w ww . j  av  a 2 s  .co m*/
    if (fileFilter != null)
        dirs = f.listFiles(fileFilter);
    else
        dirs = f.listFiles();

    _main.setTitle(f.getName());
    List<Option> dir = new ArrayList<Option>();
    List<Option> fls = new ArrayList<Option>();
    try {
        for (File ff : dirs) {
            if (ff.isDirectory() && !ff.isHidden())
                dir.add(new Option(ff.getName(), getString(R.string.folder), ff.getAbsolutePath(), true, false,
                        false));
            else {
                if (!ff.isHidden())
                    fls.add(new Option(ff.getName(), getString(R.string.fileSize) + ": " + ff.length(),
                            ff.getAbsolutePath(), false, false, false));
            }
        }
    } catch (Exception e) {

    }
    Collections.sort(dir);
    Collections.sort(fls);
    dir.addAll(fls);
    dir.add(0, new Option(".", getString(R.string.currentDir), f.getAbsolutePath(), true, false, false));
    if (!f.getName().equalsIgnoreCase("sdcard")) {
        if (f.getParentFile() != null) {
            dir.add(0,
                    new Option("..", getString(R.string.parentDirectory), f.getParent(), false, true, false));
        }
    }
    adapter = new FileArrayAdapter(getActivity(), R.layout.file_view, dir);
    this.setListAdapter(adapter);
}

From source file:org.b3log.latke.plugin.PluginManager.java

/**
 * Loads plugins from directory {@literal webRoot/plugins/}.
 *//*from  w w  w .  ja  v  a2 s. c  o  m*/
public void load() {
    Stopwatchs.start("Load Plugins");

    classLoaders.clear();

    final File[] pluginsDirs = new File(PLUGIN_ROOT).listFiles();
    final List<AbstractPlugin> plugins = new ArrayList<AbstractPlugin>();
    HashMap<String, HashSet<AbstractPlugin>> holder = pluginCache.get(PLUGIN_CACHE_NAME);

    if (null == holder) {
        LOGGER.info("Creates an empty plugin holder");
        holder = new HashMap<String, HashSet<AbstractPlugin>>();
    }

    if (pluginsDirs != null) {
        for (int i = 0; i < pluginsDirs.length; i++) {
            final File pluginDir = pluginsDirs[i];

            if (pluginDir.isDirectory() && !pluginDir.isHidden() && !pluginDir.getName().startsWith(".")) {
                try {
                    LOGGER.log(Level.INFO, "Loading plugin under directory[{0}]", pluginDir.getName());

                    final AbstractPlugin plugin = load(pluginDir, holder);

                    if (plugin != null) {
                        plugins.add(plugin);
                    }
                } catch (final Exception e) {
                    LOGGER.log(Level.WARNING, "Load plugin under directory[" + pluginDir.getName() + "] failed",
                            e);
                }
            } else {
                LOGGER.log(Level.WARNING, "It[{0}] is not a directory under " + "directory plugins, ignored",
                        pluginDir.getName());
            }
        }
    }

    try {
        EventManager.getInstance()
                .fireEventSynchronously(new Event<List<AbstractPlugin>>(PLUGIN_LOADED_EVENT, plugins));
    } catch (final EventException e) {
        throw new RuntimeException("Plugin load error", e);
    }

    pluginCache.put(PLUGIN_CACHE_NAME, holder);

    Stopwatchs.end();
}

From source file:com.fimagena.filepicker.FilePickerFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);/*from   w ww  .  j a  v  a  2  s .c  o m*/
    setRetainInstance(true);

    File mnt = new File("/storage");
    if (!mnt.exists())
        mnt = new File("/mnt");
    mFileSystemRoots = mnt.listFiles(new FileFilter() {
        @Override
        public boolean accept(File f) {
            try {
                File canon = (f.getParent() == null) ? f
                        : new File(f.getParentFile().getCanonicalFile(), f.getName());
                boolean isSymlink = !canon.getCanonicalFile().equals(canon.getAbsoluteFile());
                return f.isDirectory() && f.exists() && f.canWrite() && !f.isHidden() && !isSymlink;
            } catch (Exception e) {
                return false;
            }
        }
    });

    mAdapter = new FileItemAdapter(this, mParams, mStartPath);
}

From source file:org.geoserver.importer.Directory.java

@Override
public void prepare(ProgressMonitor m) throws IOException {
    files = new ArrayList<FileData>();

    //recursively search for spatial files, maintain a queue of directories to recurse into
    LinkedList<File> q = new LinkedList<File>();
    q.add(file);// ww  w  .  j  a  v a  2 s . co m

    while (!q.isEmpty()) {
        File dir = q.poll();

        if (m.isCanceled()) {
            return;
        }
        m.setTask("Scanning " + dir.getPath());

        //get all the regular (non directory) files
        Set<File> all = new LinkedHashSet<File>(Arrays.asList(dir.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return !new File(dir, name).isDirectory();
            }
        })));

        //scan all the files looking for spatial ones
        for (File f : dir.listFiles()) {
            if (f.isHidden()) {
                all.remove(f);
                continue;
            }
            if (f.isDirectory()) {
                if (!recursive && !f.equals(file)) {
                    //skip it
                    continue;
                }
                // @hacky - ignore __MACOSX
                // this could probably be dealt with in a better way elsewhere
                // like by having Directory ignore the contents since they
                // are all hidden files anyway
                if (!"__MACOSX".equals(f.getName())) {
                    Directory d = new Directory(f);
                    d.prepare(m);

                    files.add(d);
                }
                //q.push(f);
                continue;
            }

            //special case for .aux files, they are metadata but get picked up as readable 
            // by the erdas imagine reader...just ignore them for now 
            if ("aux".equalsIgnoreCase(FilenameUtils.getExtension(f.getName()))) {
                continue;
            }

            //determine if this is a spatial format or not
            DataFormat format = DataFormat.lookup(f);

            if (format != null) {
                SpatialFile sf = newSpatialFile(f, format);

                //gather up the related files
                sf.prepare(m);

                files.add(sf);

                all.removeAll(sf.allFiles());
            }
        }

        //take any left overs and add them as unspatial/unrecognized
        for (File f : all) {
            files.add(new ASpatialFile(f));
        }
    }

    format = format();
    //        //process ignored for files that should be grouped with the spatial files
    //        for (DataFile df : files) {
    //            SpatialFile sf = (SpatialFile) df;
    //            String base = FilenameUtils.getBaseName(sf.getFile().getName());
    //            for (Iterator<File> i = ignored.iterator(); i.hasNext(); ) {
    //                File f = i.next();
    //                if (base.equals(FilenameUtils.getBaseName(f.getName()))) {
    //                    //.prj file?
    //                    if ("prj".equalsIgnoreCase(FilenameUtils.getExtension(f.getName()))) {
    //                        sf.setPrjFile(f);
    //                    }
    //                    else {
    //                        sf.getSuppFiles().add(f);
    //                    }
    //                    i.remove();
    //                }
    //            }
    //        }
    //        
    //        //take any left overs and add them as unspatial/unrecognized
    //        for (File f : ignored) {
    //            files.add(new ASpatialFile(f));
    //        }
    //        
    //        return files;
    //        
    //        for (DataFile f : files()) {
    //            f.prepare();
    //        }
}

From source file:com.otway.picasasync.syncutil.SyncManager.java

private List<File> getNewSubFolders(List<AlbumEntry> albums, File rootFolder) throws ServiceException {
    List<File> result = new ArrayList<File>();

    log.info("Looking for new local sub folders in " + rootFolder + "...");

    final HashSet<String> albumNameLookup = new HashSet<String>();
    for (AlbumEntry remoteAlbum : albums)
        albumNameLookup.add(remoteAlbum.getTitle().getPlainText());

    File[] newFolders = rootFolder.listFiles(new FilenameFilter() {
        public boolean accept(File current, String name) {
            File file = new File(current, name);
            if (file.isDirectory() && !file.isHidden()) {
                if (!albumNameLookup.contains(file.getName())
                        && !file.getName().equals(PicasawebClient.AUTO_BACKUP_FOLDER)) {
                    return true;
                }//from  w w w  .  j  a  v  a 2 s  .  c o m
            }
            return false;
        }
    });

    if (newFolders != null) {
        result = Arrays.asList(newFolders);

        TimeUtils.sortFoldersNewestFirst(result);
    }

    return result;
}

From source file:it.readbeyond.minstrel.commander.Commander.java

private void listRecursively(File path, boolean recursive, boolean ignoreHidden, boolean directoriesOnly,
        List<String> acc) {
    File[] files = path.listFiles();
    for (File f : files) {
        if ((f.canRead()) && (!f.isHidden())) {
            String n = f.getName();
            if (!((n.startsWith(".")) && (ignoreHidden))) {
                if (f.isDirectory()) {
                    if (directoriesOnly) {
                        acc.add(f.getAbsolutePath());
                    }//from  w  w  w .j  a  va2s  .com
                    if (recursive) {
                        listRecursively(f, recursive, ignoreHidden, directoriesOnly, acc);
                    }
                } else {
                    if (!directoriesOnly) {
                        acc.add(f.getAbsolutePath());
                    }
                }
            }
        }
    }
}

From source file:io.proleap.vb6.asg.runner.impl.VbParserRunnerImpl.java

protected void parseFile(final File inputFile, final Program program) throws IOException {
    if (!inputFile.isFile()) {
        LOG.warn("Could not find file {}", inputFile.getAbsolutePath());
    } else if (inputFile.isHidden()) {
        LOG.warn("Ignoring hidden file {}", inputFile.getAbsolutePath());
    } else if (!isClazzModule(inputFile) && !isStandardModule(inputFile)) {
        LOG.info("Ignoring file {} because of file extension.", inputFile.getAbsolutePath());
    } else {//from  www  .  j  a v a2s  . co  m
        LOG.info("Parsing file {}.", inputFile.getName());

        final InputStream inputStream = new FileInputStream(inputFile);

        final VisualBasic6Lexer lexer = new VisualBasic6Lexer(new ANTLRInputStream(inputStream));

        // get a list of matched tokens
        final CommonTokenStream tokens = new CommonTokenStream(lexer);

        // pass the tokens to the parser
        final VisualBasic6Parser parser = new VisualBasic6Parser(tokens);

        // specify our entry point
        final StartRuleContext ctx = parser.startRule();

        // determine the module name
        final String declaredModuleName = analyzeDeclaredModuleName(ctx);
        final String moduleName;

        if (declaredModuleName != null && !declaredModuleName.isEmpty()) {
            moduleName = declaredModuleName;
        } else {
            moduleName = getModuleName(inputFile);
        }

        // analyze contained modules and types
        final boolean isClazzModule = isClazzModule(inputFile);
        final boolean isStandardModule = isStandardModule(inputFile);

        final ParserVisitor visitor = new VbTypeVisitorImpl(program, moduleName, isClazzModule,
                isStandardModule);

        LOG.info("Collecting types in file {}.", inputFile.getName());
        visitor.visit(ctx);
    }
}

From source file:org.efaps.esjp.archives.Archive_Base.java

/**
 * Check if access will be granted to the cmd to create a root node.
 *
 * @param _parameter Parameter as passed by the eFaps API
 * @return new Return// ww  w .  ja  va2 s .c  om
 * @throws EFapsException on error
 */
public Return createFromZip(final Parameter _parameter) throws EFapsException {
    final Context.FileParameter fileItem = Context.getThreadContext().getFileParameters().get("upload");
    if (fileItem != null) {
        try {
            final InputStream input = fileItem.getInputStream();
            final ZipInputStream zis = new ZipInputStream(new BufferedInputStream(input));
            ZipEntry entry;
            final FileUtil fileUtil = new FileUtil();
            final List<File> files = new ArrayList<>();
            while ((entry = zis.getNextEntry()) != null) {
                int size;
                final byte[] buffer = new byte[2048];
                final File file = fileUtil.getFile(entry.getName());
                if (!file.isHidden()) {
                    files.add(file);
                    final FileOutputStream fos = new FileOutputStream(file);
                    final BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
                    while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
                        bos.write(buffer, 0, size);
                    }
                    bos.flush();
                    bos.close();
                }
            }
            for (final File file : files) {
                if (file.length() > 0) {
                    final Context.FileParameter fileTmp = new FileItem(file);
                    Context.getThreadContext().getFileParameters().put("upload", fileTmp);
                    _parameter.getParameters().put("name", new String[] { fileTmp.getName() });
                    create(_parameter);
                }
            }
        } catch (final IOException e) {
            throw new EFapsException(Archive_Base.class, "createFromZip", e);
        }
    }
    return new Return();
}