List of usage examples for org.apache.commons.io.filefilter WildcardFileFilter WildcardFileFilter
public WildcardFileFilter(List wildcards)
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 ww. j a va2s .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:hu.bme.mit.incqueryd.engine.test.util.TestCaseFinder.java
public static File[] getTestCases(final String wildcard) { final File dir = new File(TestConstants.TEST_CASES_DIRECTORY); final FileFilter fileFilter = new WildcardFileFilter(wildcard); final File[] files = dir.listFiles(fileFilter); return files; }
From source file:com.hp.test.framework.jmeterTests.GetJmeterTestCaseFileList.java
public static List getjmeterTestcaseList() { List<String> jmeterFileList; jmeterFileList = new ArrayList<String>(); ReadJmeterConfigProps readjmeterconfigprops = new ReadJmeterConfigProps(); String path = readjmeterconfigprops.getProperty("location.java.files"); File dir = new File(path); FileFilter fileFilter = new WildcardFileFilter("*.java"); File[] files = dir.listFiles(fileFilter); for (File file : files) { jmeterFileList.add(file.getName()); }/*ww w. j av a 2 s.c om*/ return jmeterFileList; }
From source file:com.fizzed.stork.launcher.FileUtil.java
static public List<File> findFiles(String fileString, boolean ignoreNonExistent) throws IOException { if (fileString.endsWith("*")) { // file string contains a glob... File f = new File(fileString); File parent = f.getParentFile(); if (parent == null) { parent = new File("."); }//from ww w . j av a 2 s .com FileFilter fileFilter = new WildcardFileFilter(f.getName()); File[] files = parent.listFiles(fileFilter); return Arrays.asList(files); } else { File f = new File(fileString); if (!f.exists()) { if (ignoreNonExistent) { return Collections.EMPTY_LIST; } else { throw new IOException("File [" + fileString + "] does not exist"); } } else { if (f.isDirectory()) { return Arrays.asList(f.listFiles()); } else { return Arrays.asList(f); } } } }
From source file:com.gs.obevo.db.testutil.DirectoryAssert.java
/** * Primitive DB comparison method// w w w . j ava 2 s . co m * We just compare file names, not the subdirecory structure also * (so this would fail if multiple subdirectories had the same file name) */ public static void assertDirectoriesEqual(File expected, File actual) { MutableList<File> expectedFiles = FastList .newList(FileUtils.listFiles(expected, new WildcardFileFilter("*"), DIR_FILE_FILTER)); expectedFiles = expectedFiles.sortThisBy(toRelativePath(expected)); MutableList<File> actualFiles = FastList .newList(FileUtils.listFiles(actual, new WildcardFileFilter("*"), DIR_FILE_FILTER)); actualFiles = actualFiles.sortThisBy(toRelativePath(actual)); assertEquals( String.format("Directories did not have same # of files:\nExpected: %1$s\nbut was: %2$s", expectedFiles.makeString("\n"), actualFiles.makeString("\n")), expectedFiles.size(), actualFiles.size()); for (int i = 0; i < expectedFiles.size(); i++) { File expectedFile = expectedFiles.get(i); File actualFile = actualFiles.get(i); String expectedFilePath = getRelativePath(expectedFile, expected); String actualFilePath = getRelativePath(actualFile, actual); System.out.println("Comparing" + expectedFilePath + " vs " + actualFilePath); assertEquals("File " + i + " [" + expectedFile + " vs " + actualFile + " does not match paths relative from their roots", expectedFilePath, actualFilePath); FileAssert.assertEquals("Mismatch on file " + expectedFile.getAbsolutePath(), expectedFile, actualFile); } }
From source file:com.martinwunderlich.nlp.arg.aifdb.AIFdbArgumentMapFactory.java
public static List<AIFdbArgumentMap> buildArgumentMapListFromNodesetJsonFiles(String nodesetPath) { FileFilter fileFilter = new WildcardFileFilter("nodeset*.json"); File sourceDir = new File(nodesetPath); if (sourceDir == null || !sourceDir.isDirectory() || !sourceDir.exists()) throw new IllegalArgumentException("Invalid nodeset path provided for argument factory: " + nodesetPath + " is not a directory or does not exist."); File[] jsonFiles = sourceDir.listFiles(fileFilter); List<AIFdbArgumentMap> argMaps = new ArrayList<>(); for (File jsonFile : jsonFiles) { try {//from w w w .j av a 2 s . c o m AIFdbArgumentMap map = buildFromJsonFile(jsonFile.getAbsolutePath()); argMaps.add(map); } catch (Exception ex) { System.out.println("Error while trying to build argumentation map from file " + jsonFile); System.out.println("Details: " + ex.getMessage()); System.out.println(ex.getStackTrace().toString()); } } System.out.println("Building list of argumentation maps...DONE"); System.out.println("Found " + argMaps.size() + " argumentation maps."); return argMaps; }
From source file:io.kahu.hawaii.service.io.HtmlFileListGenerator.java
public List<String> createListOfHtmlFiles(File startDirectory) throws IOException { // Create a filter for Files ending in ".*html" IOFileFilter fileFilter = new WildcardFileFilter("*.*html"); // create directory filter to ignore directories starting with _ IOFileFilter dirFilter = new RegexFileFilter("^[^_].+"); FileDirectoryTreeWalker walker = new FileDirectoryTreeWalker(dirFilter, fileFilter); return walker.walk(startDirectory); }
From source file:com.ebay.logstorm.server.utils.LogStormServerDebug.java
private static File findAssemblyJarFile() { String projectRootDir = System.getProperty("user.dir"); String assemblyModuleTargeDirPath = projectRootDir + "/assembly/target/"; File assemblyTargeDirFile = new File(assemblyModuleTargeDirPath); if (!assemblyTargeDirFile.exists()) { throw new IllegalStateException( assemblyModuleTargeDirPath + " not found, please execute 'mvn install -DskipTests' under " + projectRootDir + " to build the project firstly and retry"); }/*from ww w. j a va 2s. c o m*/ String jarFileNameWildCard = "logstorm-assembly-*.jar"; Collection<File> jarFiles = FileUtils.listFiles(assemblyTargeDirFile, new WildcardFileFilter(jarFileNameWildCard), TrueFileFilter.INSTANCE); if (jarFiles.size() == 0) { throw new IllegalStateException( "jar is not found, please execute 'mvn install -DskipTests' from project root firstly and retry"); } File jarFile = jarFiles.iterator().next(); LOG.debug("Found pipeline.jar: {}", jarFile.getAbsolutePath()); return jarFile; }
From source file:com.ebay.logstorm.core.utils.PipelineEnvironmentLoaderForTest.java
private static File findAssemblyJarFile(String relativeToHomePath) { String projectRootDir = System.getProperty("user.dir"); String assemblyModuleTargeDirPath = relativeToHomePath == null ? projectRootDir + "/assembly/target/" : projectRootDir + relativeToHomePath + "/assembly/target/"; File assemblyTargeDirFile = new File(assemblyModuleTargeDirPath); if (!assemblyTargeDirFile.exists()) { throw new IllegalStateException( assemblyModuleTargeDirPath + " not found, please execute 'mvn install -DskipTests' under " + projectRootDir + " to build the project firstly and retry"); }/* w w w. j ava 2 s . c om*/ String jarFileNameWildCard = "logstorm-assembly-*.jar"; Collection<File> jarFiles = FileUtils.listFiles(assemblyTargeDirFile, new WildcardFileFilter(jarFileNameWildCard), TrueFileFilter.INSTANCE); if (jarFiles.size() == 0) { throw new IllegalStateException( "jar is not found, please execute 'mvn install -DskipTests' from project root firstly and retry"); } File jarFile = jarFiles.iterator().next(); LOG.debug("Found pipeline.jar: {}", jarFile.getAbsolutePath()); return jarFile; }
From source file:jlib.polling.MaskFileFilter.java
void add(String csMask) { if (csMask != null) { if (m_arrMaskFilters == null) m_arrMaskFilters = new ArrayList<FileFilter>(); csMask = csMask.trim();/*from w ww . j av a 2s.co m*/ FileFilter fileFilter = new WildcardFileFilter(csMask); m_arrMaskFilters.add(fileFilter); } }