List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE
IOFileFilter INSTANCE
To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.
Click Source Link
From source file:org.apache.solr.cloud.ZkCLITest.java
@Test public void testUpConfigLinkConfigClearZk() throws Exception { File tmpDir = createTempDir().toFile(); // test upconfig String confsetname = "confsetone"; final String[] upconfigArgs; if (random().nextBoolean()) { upconfigArgs = new String[] { "-zkhost", zkServer.getZkAddress(), "-cmd", ZkCLI.UPCONFIG, "-confdir", ExternalPaths.TECHPRODUCTS_CONFIGSET, "-confname", confsetname }; } else {/*from w w w . j a v a 2 s. co m*/ final String excluderegexOption = (random().nextBoolean() ? "--" + ZkCLI.EXCLUDE_REGEX : "-" + ZkCLI.EXCLUDE_REGEX_SHORT); upconfigArgs = new String[] { "-zkhost", zkServer.getZkAddress(), "-cmd", ZkCLI.UPCONFIG, excluderegexOption, ZkCLI.EXCLUDE_REGEX_DEFAULT, "-confdir", ExternalPaths.TECHPRODUCTS_CONFIGSET, "-confname", confsetname }; } ZkCLI.main(upconfigArgs); assertTrue(zkClient.exists(ZkConfigManager.CONFIGS_ZKNODE + "/" + confsetname, true)); // print help // ZkCLI.main(new String[0]); // test linkconfig String[] args = new String[] { "-zkhost", zkServer.getZkAddress(), "-cmd", "linkconfig", "-collection", "collection1", "-confname", confsetname }; ZkCLI.main(args); ZkNodeProps collectionProps = ZkNodeProps .load(zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/collection1", null, null, true)); assertTrue(collectionProps.containsKey("configName")); assertEquals(confsetname, collectionProps.getStr("configName")); // test down config File confDir = new File(tmpDir, "solrtest-confdropspot-" + this.getClass().getName() + "-" + System.nanoTime()); assertFalse(confDir.exists()); args = new String[] { "-zkhost", zkServer.getZkAddress(), "-cmd", "downconfig", "-confdir", confDir.getAbsolutePath(), "-confname", confsetname }; ZkCLI.main(args); File[] files = confDir.listFiles(); List<String> zkFiles = zkClient.getChildren(ZkConfigManager.CONFIGS_ZKNODE + "/" + confsetname, null, true); assertEquals(files.length, zkFiles.size()); File sourceConfDir = new File(ExternalPaths.TECHPRODUCTS_CONFIGSET); // filter out all directories starting with . (e.g. .svn) Collection<File> sourceFiles = FileUtils.listFiles(sourceConfDir, TrueFileFilter.INSTANCE, new RegexFileFilter("[^\\.].*")); for (File sourceFile : sourceFiles) { int indexOfRelativePath = sourceFile.getAbsolutePath() .lastIndexOf("sample_techproducts_configs" + File.separator + "conf"); String relativePathofFile = sourceFile.getAbsolutePath().substring(indexOfRelativePath + 33, sourceFile.getAbsolutePath().length()); File downloadedFile = new File(confDir, relativePathofFile); if (ZkConfigManager.UPLOAD_FILENAME_EXCLUDE_PATTERN.matcher(relativePathofFile).matches()) { assertFalse(sourceFile.getAbsolutePath() + " exists in ZK, downloaded:" + downloadedFile.getAbsolutePath(), downloadedFile.exists()); } else { assertTrue( downloadedFile.getAbsolutePath() + " does not exist source:" + sourceFile.getAbsolutePath(), downloadedFile.exists()); assertTrue(relativePathofFile + " content changed", FileUtils.contentEquals(sourceFile, downloadedFile)); } } // test reset zk args = new String[] { "-zkhost", zkServer.getZkAddress(), "-cmd", "clear", "/" }; ZkCLI.main(args); assertEquals(0, zkClient.getChildren("/", null, true).size()); }
From source file:org.apache.vxquery.metadata.VXQueryCollectionOperatorDescriptor.java
@Override public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx, IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException { final FrameTupleAccessor fta = new FrameTupleAccessor(ctx.getFrameSize(), recordDescProvider.getInputRecordDescriptor(getActivityId(), 0)); final int fieldOutputCount = recordDescProvider.getOutputRecordDescriptor(getActivityId(), 0) .getFieldCount();//from w w w . j av a2 s . co m final ByteBuffer frame = ctx.allocateFrame(); final FrameTupleAppender appender = new FrameTupleAppender(ctx.getFrameSize(), fieldOutputCount); final short partitionId = (short) ctx.getTaskAttemptId().getTaskId().getPartition(); final ITreeNodeIdProvider nodeIdProvider = new TreeNodeIdProvider(partitionId, dataSourceId, totalDataSources); final String nodeId = ctx.getJobletContext().getApplicationContext().getNodeId(); final DynamicContext dCtx = (DynamicContext) ctx.getJobletContext().getGlobalJobData(); final String collectionName = collectionPartitions[partition % collectionPartitions.length]; final XMLParser parser = new XMLParser(false, nodeIdProvider, nodeId, frame, appender, childSeq, dCtx.getStaticContext()); return new AbstractUnaryInputUnaryOutputOperatorNodePushable() { @Override public void open() throws HyracksDataException { appender.reset(frame, true); writer.open(); } @Override public void nextFrame(ByteBuffer buffer) throws HyracksDataException { fta.reset(buffer); String collectionModifiedName = collectionName.replace("${nodeId}", nodeId); File collectionDirectory = new File(collectionModifiedName); // Go through each tuple. if (collectionDirectory.isDirectory()) { for (int tupleIndex = 0; tupleIndex < fta.getTupleCount(); ++tupleIndex) { @SuppressWarnings("unchecked") Iterator<File> it = FileUtils.iterateFiles(collectionDirectory, new VXQueryIOFileFilter(), TrueFileFilter.INSTANCE); while (it.hasNext()) { File xmlDocument = it.next(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Starting to read XML document: " + xmlDocument.getAbsolutePath()); } parser.parseElements(xmlDocument, writer, fta, tupleIndex); } } } else { throw new HyracksDataException("Invalid directory parameter (" + nodeId + ":" + collectionDirectory.getAbsolutePath() + ") passed to collection."); } } @Override public void fail() throws HyracksDataException { writer.fail(); } @Override public void close() throws HyracksDataException { // Check if needed? fta.reset(frame); if (fta.getTupleCount() > 0) { FrameUtils.flushFrame(frame, writer); } writer.close(); } }; }
From source file:org.apache.vxquery.xtest.util.DiskPerformance.java
public void setDirectory(String filename) { File directory = new File(filename); if (directory.isDirectory()) { cTestFiles = FileUtils.listFiles(directory, new VXQueryIOFileFilter(), TrueFileFilter.INSTANCE); if (cTestFiles.size() < 1) { System.err.println("No XML files found in given directory."); return; }/*from w w w.j a va2s . c o m*/ } testFilesIt = cTestFiles.iterator(); }
From source file:org.argrr.extractor.gdrive.uploader.App.java
public static void main(String[] args) throws IOException { String rootOutputPath = App.class.getClassLoader().getResource("./").getPath() + "../../../report/generated"; String rootTemplatesPath = App.class.getClassLoader().getResource("./").getPath() + "../../../templates"; Drive drive = DriveApi.getConnection(); //remove the previous generated files Logger.getLogger(App.class.getName()).log(Level.INFO, "remove old uploaded files "); emptyFolder(drive, Config.getVar("DRIVE_FOLDER_GENERATED_ID")); emptyFolder(drive, Config.getVar("DRIVE_FOLDER_TEMPLATES_ID")); //add the generated files System.out.println(rootOutputPath); for (java.io.File f : FileUtils.listFiles(new java.io.File(rootOutputPath), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {/*from w w w .j a v a 2 s . c o m*/ Logger.getLogger(App.class.getName()).log(Level.INFO, "add to gdrive file " + f.getName()); uploadFile(f, drive, Config.getVar("DRIVE_FOLDER_GENERATED_ID")); } //add the templates files for (java.io.File f : FileUtils.listFiles(new java.io.File(rootTemplatesPath), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { Logger.getLogger(App.class.getName()).log(Level.INFO, "add to gdrive file " + f.getName()); uploadFile(f, drive, Config.getVar("DRIVE_FOLDER_TEMPLATES_ID")); } uploadFile(FileUtils.getFile(rootOutputPath + "/../report.pdf"), drive, Config.getVar("DRIVE_FOLDER_GENERATED_ID")); uploadFile(FileUtils.getFile(rootOutputPath + "/../report.tex"), drive, Config.getVar("DRIVE_FOLDER_GENERATED_ID")); }
From source file:org.artificer.integration.ArchiveContext.java
/** * Returns all Files within the archive. * * @return Collection<File>/*from w w w .j av a 2 s. c om*/ */ public Collection<File> expand() { return FileUtils.listFiles(archiveWorkDir, FileFileFilter.FILE, TrueFileFilter.INSTANCE); }
From source file:org.asciidoctor.maven.AsciidoctorRefreshMojo.java
protected synchronized void doExecute() { ensureOutputExists();/* www . j a v a 2s . com*/ // delete only content files, resources are synchronized so normally up to date for (final File f : FileUtils.listFiles(outputDirectory, new RegexFileFilter(ASCIIDOC_REG_EXP_EXTENSION), TrueFileFilter.INSTANCE)) { FileUtils.deleteQuietly(f); } try { getLog().info("Re-rendered doc in " + executeAndReturnDuration() + "ms"); } catch (final MojoExecutionException e) { getLog().error(e); } catch (final MojoFailureException e) { getLog().error(e); } }
From source file:org.b3log.latke.ioc.ClassPathResolver.java
/** * scan the system file to get the URLS of the Classes. * * @param rootDirResource rootDirResource which is in File System * @param subPattern subPattern// w ww. ja va 2s . c o m * @return the URLs of all the matched classes */ private static Collection<? extends URL> doFindPathMatchingFileResources(final URL rootDirResource, final String subPattern) { File rootFile = null; final Set<URL> rets = new LinkedHashSet<URL>(); try { rootFile = new File(rootDirResource.toURI()); } catch (final URISyntaxException e) { LOGGER.log(Level.ERROR, "cat not resolve the rootFile", e); throw new RuntimeException("cat not resolve the rootFile", e); } String fullPattern = StringUtils.replace(rootFile.getAbsolutePath(), File.separator, "/"); if (!subPattern.startsWith("/")) { fullPattern += "/"; } final String filePattern = fullPattern + StringUtils.replace(subPattern, File.separator, "/"); @SuppressWarnings("unchecked") final Collection<File> files = FileUtils.listFiles(rootFile, new IOFileFilter() { @Override public boolean accept(final File dir, final String name) { return true; } @Override public boolean accept(final File file) { if (file.isDirectory()) { return false; } if (AntPathMatcher.match(filePattern, StringUtils.replace(file.getAbsolutePath(), File.separator, "/"))) { return true; } return false; } }, TrueFileFilter.INSTANCE); try { for (File file : files) { rets.add(file.toURI().toURL()); } } catch (final Exception e) { LOGGER.log(Level.ERROR, "convert file to URL error", e); throw new RuntimeException("convert file to URL error", e); } return rets; }
From source file:org.bitstrings.maven.plugins.indexer.IndexerMojo.java
private void createIndexFile(String indexFileName, String charset, File directory, List<String> includes, List<String> excludes, boolean recursive) throws MojoExecutionException { final Collection<File> files = FileUtils.listFilesAndDirs(directory, FileFilterUtils.and(new WildcardFileFilter(includes), FileFilterUtils.notFileFilter(new WildcardFileFilter(excludes))), (recursive ? TrueFileFilter.INSTANCE : null)); final File indexFile = new File(directory, indexFileName); final List<File> directories = Lists.newArrayList(); // FIXME: charset try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(indexFile), charset))) { if (!quiet) { getLog().info("Writing index for [ " + indexFile + " ]."); }// w w w . j av a 2s.co m for (File file : files) { if (file.equals(directory) || file.getName().equals(indexFileName)) { continue; } final StringBuilder sb = new StringBuilder(); if (file.isDirectory()) { sb.append("D"); directories.add(file); } else { sb.append("F"); } sb.append(","); sb.append(file.getName()); writer.write(sb.toString()); writer.newLine(); } } catch (Exception e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } if (recursive) { for (File dir : directories) { createIndexFile(indexFileName, charset, dir, includes, excludes, recursive); } } }
From source file:org.cleartk.test.util.LicenseTestUtil.java
public static void testDescriptorFiles(String directoryName) throws IOException { List<String> filesMissingLicense = new ArrayList<String>(); File directory = new File(directoryName); Iterator<?> files = org.apache.commons.io.FileUtils.iterateFiles(directory, new SuffixFileFilter(".xml"), TrueFileFilter.INSTANCE); while (files.hasNext()) { File file = (File) files.next(); String fileText = FileUtils.file2String(file); if (fileText.indexOf("Copyright (c) ") == -1 || fileText.indexOf( "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"") == -1) { if (file.getName().equals("GENIAcorpus3.02.articleA.pos.xml")) continue; if (file.getParent().equals("src/org/cleartk/descriptor".replace('/', File.separatorChar))) continue; filesMissingLicense.add(file.getPath()); }//from w w w . j a v a 2 s . co m } if (filesMissingLicense.size() > 0) { String message = String.format("%d descriptor files with no license. ", filesMissingLicense.size()); System.err.println(message); Collections.sort(filesMissingLicense); for (String path : filesMissingLicense) { System.err.println(path); } Assert.fail(message); } }
From source file:org.cleartk.test.util.LicenseTestUtil.java
public static void testFiles(String directoryName, IOFileFilter fileFilter, List<String> excludePackageNames, List<String> excludeFiles) throws IOException { List<String> filesMissingLicense = new ArrayList<String>(); File directory = new File(directoryName); Iterator<?> files = org.apache.commons.io.FileUtils.iterateFiles(directory, fileFilter, TrueFileFilter.INSTANCE); while (files.hasNext()) { File file = (File) files.next(); String fileText = FileUtils.file2String(file); if (excludePackage(file, excludePackageNames)) { continue; }//from w w w.j av a 2 s .c o m if (excludeFile(file, excludeFiles)) { continue; } if (fileText.indexOf("Copyright (c) ") == -1 || fileText.indexOf( "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"") == -1) { filesMissingLicense.add(file.getPath()); } else { if (fileText.indexOf("Copyright (c) ", 300) == -1) filesMissingLicense.add(file.getPath()); } } if (filesMissingLicense.size() > 0) { String message = String.format("%d source files with no license. ", filesMissingLicense.size()); System.err.println(message); Collections.sort(filesMissingLicense); for (String path : filesMissingLicense) { System.err.println(path); } Assert.fail(message); } }