Example usage for org.apache.commons.io.filefilter HiddenFileFilter VISIBLE

List of usage examples for org.apache.commons.io.filefilter HiddenFileFilter VISIBLE

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter HiddenFileFilter VISIBLE.

Prototype

IOFileFilter VISIBLE

To view the source code for org.apache.commons.io.filefilter HiddenFileFilter VISIBLE.

Click Source Link

Document

Singleton instance of visible filter

Usage

From source file:com.edduarte.protbox.Protbox.java

public static void main(String... args) {

    // activate debug / verbose mode
    if (args.length != 0) {
        List<String> argsList = Arrays.asList(args);
        if (argsList.contains("-v")) {
            Constants.verbose = true;//from   w  w  w.j  av  a  2s .  c  om
        }
    }

    // use System's look and feel
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        // If the System's look and feel is not obtainable, continue execution with JRE look and feel
    }

    // check this is a single instance
    try {
        new ServerSocket(1882);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null,
                "Another instance of Protbox is already running.\n" + "Please close the other instance first.",
                "Protbox already running", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }

    // check if System Tray is supported by this operative system
    if (!SystemTray.isSupported()) {
        JOptionPane.showMessageDialog(null,
                "Your operative system does not support system tray functionality.\n"
                        + "Please try running Protbox on another operative system.",
                "System tray not supported", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }

    // add PKCS11 providers
    FileFilter fileFilter = new AndFileFilter(new WildcardFileFilter(Lists.newArrayList("*.config")),
            HiddenFileFilter.VISIBLE);

    File[] providersConfigFiles = new File(Constants.PROVIDERS_DIR).listFiles(fileFilter);

    if (providersConfigFiles != null) {
        for (File f : providersConfigFiles) {
            try {
                List<String> lines = FileUtils.readLines(f);
                String aliasLine = lines.stream().filter(line -> line.contains("alias")).findFirst().get();
                lines.remove(aliasLine);
                String alias = aliasLine.split("=")[1].trim();

                StringBuilder sb = new StringBuilder();
                for (String s : lines) {
                    sb.append(s);
                    sb.append("\n");
                }

                Provider p = new SunPKCS11(new ReaderInputStream(new StringReader(sb.toString())));
                Security.addProvider(p);

                pkcs11Providers.put(p.getName(), alias);

            } catch (IOException | ProviderException ex) {
                if (ex.getMessage().equals("Initialization failed")) {
                    ex.printStackTrace();

                    String s = "The following error occurred:\n" + ex.getCause().getMessage()
                            + "\n\nIn addition, make sure you have "
                            + "an available smart card reader connected before opening the application.";
                    JTextArea textArea = new JTextArea(s);
                    textArea.setColumns(60);
                    textArea.setLineWrap(true);
                    textArea.setWrapStyleWord(true);
                    textArea.setSize(textArea.getPreferredSize().width, 1);

                    JOptionPane.showMessageDialog(null, textArea, "Error loading PKCS11 provider",
                            JOptionPane.ERROR_MESSAGE);
                    System.exit(1);
                } else {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(null,
                            "Error while setting up PKCS11 provider from configuration file " + f.getName()
                                    + ".\n" + ex.getMessage(),
                            "Error loading PKCS11 provider", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }

    // adds a shutdown hook to save instantiated directories into files when the application is being closed
    Runtime.getRuntime().addShutdownHook(new Thread(Protbox::exit));

    // get system tray and run tray applet
    tray = SystemTray.getSystemTray();
    SwingUtilities.invokeLater(() -> {

        if (Constants.verbose) {
            logger.info("Starting application");
        }

        //Start a new TrayApplet object
        trayApplet = TrayApplet.getInstance();
    });

    // prompts the user to choose which provider to use
    ProviderListWindow.showWindow(Protbox.pkcs11Providers.keySet(), providerName -> {

        // loads eID token
        eIDTokenLoadingWindow.showPrompt(providerName, (returnedUser, returnedCertificateData) -> {
            user = returnedUser;
            certificateData = returnedCertificateData;

            // gets a password to use on the saved registry files (for loading and saving)
            final AtomicReference<Consumer<SecretKey>> consumerHolder = new AtomicReference<>(null);
            consumerHolder.set(password -> {
                registriesPasswordKey = password;
                try {
                    // if there are serialized files, load them if they can be decoded by this user's private key
                    final List<SavedRegistry> serializedDirectories = new ArrayList<>();
                    if (Constants.verbose) {
                        logger.info("Reading serialized registry files...");
                    }

                    File[] registryFileList = new File(Constants.REGISTRIES_DIR).listFiles();
                    if (registryFileList != null) {
                        for (File f : registryFileList) {
                            if (f.isFile()) {
                                byte[] data = FileUtils.readFileToByteArray(f);
                                try {
                                    Cipher cipher = Cipher.getInstance("AES");
                                    cipher.init(Cipher.DECRYPT_MODE, registriesPasswordKey);
                                    byte[] registryDecryptedData = cipher.doFinal(data);
                                    serializedDirectories.add(new SavedRegistry(f, registryDecryptedData));
                                } catch (GeneralSecurityException ex) {
                                    if (Constants.verbose) {
                                        logger.info("Inserted Password does not correspond to " + f.getName());
                                    }
                                }
                            }
                        }
                    }

                    // if there were no serialized directories, show NewDirectory window to configure the first folder
                    if (serializedDirectories.isEmpty() || registryFileList == null) {
                        if (Constants.verbose) {
                            logger.info("No registry files were found: running app as first time!");
                        }
                        NewRegistryWindow.start(true);

                    } else { // there were serialized directories
                        loadRegistry(serializedDirectories);
                        trayApplet.repaint();
                        showTrayApplet();
                    }

                } catch (AWTException | IOException | GeneralSecurityException | ReflectiveOperationException
                        | ProtboxException ex) {

                    JOptionPane.showMessageDialog(null,
                            "The inserted password was invalid! Please try another one!", "Invalid password!",
                            JOptionPane.ERROR_MESSAGE);
                    insertPassword(consumerHolder.get());
                }
            });
            insertPassword(consumerHolder.get());
        });
    });
}

From source file:de.fau.osr.util.VisibleFilesTraverser.java

/**
 * Builds a *VisibleFilesTraverser*.//w ww.j a  v a 2 s . c o m
 * @param startDirectory
 * @param ignoreFileNames
 * @return
 */
public static VisibleFilesTraverser Get(Path startDirectory, String... ignoreFileNames) {
    return new VisibleFilesTraverser(startDirectory, ignoreFileNames, FileFilterUtils.or(
            // Show visible directories
            FileFilterUtils.and(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE),
            // Show visible files
            FileFilterUtils.and(FileFilterUtils.fileFileFilter(), HiddenFileFilter.VISIBLE)));
}

From source file:com.aionemu.gameserver.dataholders.ReloadableData.java

protected Collection<File> listFiles(File root, boolean recursive) {
    IOFileFilter dirFilter = recursive ? makeSVNAware(HiddenFileFilter.VISIBLE) : null;
    return FileUtils.listFiles(root, and(and(notFileFilter(prefixFileFilter("new")), suffixFileFilter(".xml")),
            HiddenFileFilter.VISIBLE), dirFilter);
}

From source file:com.autentia.poda.FilesCollection.java

private Collection<File> listFiles(String path, boolean followSymbolicLinks, boolean parseHiddenFiles) {
    File directoryToScan = new File(path);
    logger.info("Searching files in directory: {}", directoryToScan.getAbsolutePath());

    IOFileFilter fileFilter = parseHiddenFiles ? TrueFileFilter.INSTANCE : HiddenFileFilter.VISIBLE;
    IOFileFilter dirFilter = followSymbolicLinks ? TrueFileFilter.INSTANCE : NOT_SYMBOLIC_LINK;
    dirFilter = andFiltersIgnoringTrueFilter(dirFilter, fileFilter);

    Collection<File> scannedFiles = FileUtils.listFiles(directoryToScan, fileFilter, dirFilter);

    logger.info("Found " + scannedFiles.size() + " files.");
    return scannedFiles;
}

From source file:com.aionengine.gameserver.dataholders.DataLoader.java

/**
 * This method is supposed to be called from subclass to initialize data loading process.<br>
 * <br>//  w ww.ja v  a2s  .  c om
 * This method is using file given in the constructor to load the data and there are two possibilities:
 * <ul>
 * <li>Given file is file is in deed the <b>file</b> then it's forwarded to {@link #loadFile(File)} method</li>
 * <li>Given file is a <b>directory</b>, then this method is obtaining list of all visible .txt files in this
 * directory and subdirectiores ( except hidden ones and those named "new" ) and call {@link #loadFile(File)} for
 * each of these files.
 * </ul>
 */
protected void loadData() {
    if (dataFile.isDirectory()) {
        Collection<?> files = FileUtils
                .listFiles(dataFile,
                        FileFilterUtils
                                .andFileFilter(
                                        FileFilterUtils.andFileFilter(
                                                FileFilterUtils
                                                        .notFileFilter(FileFilterUtils.nameFileFilter("new")),
                                                FileFilterUtils.suffixFileFilter(".txt")),
                                        HiddenFileFilter.VISIBLE),
                        HiddenFileFilter.VISIBLE);

        for (Object file1 : files) {
            File f = (File) file1;
            loadFile(f);
        }
    } else {
        loadFile(dataFile);
    }
}

From source file:com.aionemu.gameserver.dataholders.DataLoader.java

/**
 * This method is supposed to be called from subclass to initialize data
 * loading process.<br>/* www  .  j  a v  a 2 s . com*/
 * <br>
 * This method is using file given in the constructor to load the data and
 * there are two possibilities:
 * <ul>
 * <li>Given file is file is in deed the <b>file</b> then it's forwarded to
 * {@link #loadFile(File)} method</li>
 * <li>Given file is a <b>directory</b>, then this method is obtaining list
 * of all visible .txt files in this directory and subdirectiores ( except
 * hidden ones and those named "new" ) and call {@link #loadFile(File)} for
 * each of these files.
 * </ul>
 */
@SuppressWarnings("deprecation")
protected void loadData() {
    if (dataFile.isDirectory()) {
        Collection<?> files = FileUtils
                .listFiles(dataFile,
                        FileFilterUtils
                                .andFileFilter(
                                        FileFilterUtils.andFileFilter(
                                                FileFilterUtils
                                                        .notFileFilter(FileFilterUtils.nameFileFilter("new")),
                                                FileFilterUtils.suffixFileFilter(".txt")),
                                        HiddenFileFilter.VISIBLE),
                        HiddenFileFilter.VISIBLE);

        for (Object file1 : files) {
            File f = (File) file1;
            loadFile(f);
        }
    } else {
        loadFile(dataFile);
    }
}

From source file:net.peakplatform.sonar.plugins.spring.file.SpringProjectFileSystem.java

public List<InputFile> getFiles() {
    List<InputFile> result = Lists.newArrayList();
    if (getSourceDirs() == null) {
        return result;
    }//from   ww  w .  j  a  v a2  s . c o m

    IOFileFilter suffixFilter = getFileSuffixFilter();
    WildcardPattern[] exclusionPatterns = getExclusionPatterns(true);
    IOFileFilter visibleFileFilter = HiddenFileFilter.VISIBLE;

    for (File dir : getSourceDirs()) {
        if (dir.exists()) {
            // exclusion filter
            IOFileFilter exclusionFilter = new ExclusionFilter(dir, exclusionPatterns);
            // visible filter
            List<IOFileFilter> fileFilters = Lists.newArrayList(visibleFileFilter, suffixFilter,
                    exclusionFilter);
            // inclusion filter
            String inclusionPattern = (String) project.getProperty(SpringPlugin.INCLUDE_FILE_FILTER);
            if (inclusionPattern != null) {
                fileFilters.add(new InclusionFilter(dir, inclusionPattern));
            }
            fileFilters.addAll(this.filters);

            // create DefaultInputFile for each file.
            List<File> files = (List<File>) FileUtils.listFiles(dir, new AndFileFilter(fileFilters),
                    HiddenFileFilter.VISIBLE);
            for (File file : files) {
                String relativePath = DefaultProjectFileSystem.getRelativePath(file, dir);
                result.add(new DefaultInputFile(dir, relativePath));
            }
        }
    }
    return result;
}

From source file:com.jkoolcloud.tnt4j.streams.custom.dirStream.DirWatchdog.java

/**
 * Creates default file filter matching file wildcard name pattern.
 *
 * @param fileWildcardName/*from   w ww.  jav  a  2s.c o  m*/
 *            file wildcard name pattern string
 *
 * @return created file filter
 */
public static FileFilter getDefaultFilter(String fileWildcardName) {
    if (StringUtils.isEmpty(fileWildcardName)) {
        return null;
    }

    IOFileFilter directories = FileFilterUtils.and(FileFilterUtils.directoryFileFilter(),
            HiddenFileFilter.VISIBLE);

    IOFileFilter files = FileFilterUtils.and(FileFilterUtils.fileFileFilter(),
            new WildcardFileFilter(fileWildcardName, IOCase.INSENSITIVE));

    IOFileFilter filter = FileFilterUtils.or(directories, files);

    return filter;
}

From source file:net.sf.jvifm.ui.Util.java

public static IOFileFilter getDefaultFileFilter() {

    IOFileFilter filter;/*w ww. j av a  2 s.c  om*/

    Preference preference = Preference.getInstance();
    if (preference.isShowHide()) {
        filter = TrueFileFilter.INSTANCE;
    } else {
        filter = HiddenFileFilter.VISIBLE;
    }
    return filter;
}

From source file:com.aliyun.odps.local.common.utils.LocalRunUtils.java

/**
 * ?????/*from   w w  w.  j  av a2  s  . c o  m*/
 *
 * @param srcFile
 * @param result
 */
public static void listAllDataFiles(File srcFile, List<File> result) {

    if (srcFile.isDirectory()) {
        final Collection<File> list = FileUtils.listFiles(srcFile, HiddenFileFilter.VISIBLE,
                HiddenFileFilter.VISIBLE);
        for (File f : list) {
            listAllDataFiles(f, result);
        }
    } else if (!Constants.SCHEMA_FILE.equals(srcFile.getName())) {
        result.add(srcFile);
    }
}