本文整理汇总了Java中org.apache.commons.io.filefilter.SuffixFileFilter类的典型用法代码示例。如果您正苦于以下问题:Java SuffixFileFilter类的具体用法?Java SuffixFileFilter怎么用?Java SuffixFileFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SuffixFileFilter类属于org.apache.commons.io.filefilter包,在下文中一共展示了SuffixFileFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findFilesToAnalyze
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
public static List<String> findFilesToAnalyze(String dirPath) {
IOFileFilter gitFilter = FileFilterUtils.notFileFilter(
FileFilterUtils.nameFileFilter(".git")
);
File dir = new File(dirPath);
String[] phpExt = new String[] {"php"};
IOFileFilter phpFilter = new SuffixFileFilter(phpExt, IOCase.INSENSITIVE);
List<File> files = (List<File>) FileUtils.listFiles(dir, phpFilter, gitFilter);
List<String> results = new ArrayList<String>();
for (File f : files) {
try {
results.add(f.getCanonicalPath());
} catch (IOException e) {
e.printStackTrace();
}
}
return results;
}
示例2: getFilePaths
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
/**
* Get a list of file paths from the command line arguments.
*
* @param cmd Parsed command line arguments.
* @return File[]
*/
public File[] getFilePaths(CommandLine cmd) {
Collection<File> fileList = new ArrayList<>();
List<?> argList = cmd.getArgList();
argList = argList.subList(1, argList.size());
String[] args = argList.toArray(new String[argList.size()]);
if (argList.isEmpty()) {
File dir = new File("input");
SuffixFileFilter sfx = new SuffixFileFilter(".txt");
fileList = FileUtils.listFiles(dir, sfx, TrueFileFilter.INSTANCE);
} else {
for (String name : args) {
fileList.add(new File(name));
}
}
File[] files = fileList.toArray(new File[fileList.size()]);
Arrays.sort(files);
return files;
}
示例3: loadPlugins
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
/**
* When the server starts up it will reload all the plugins back in
* @throws IOException
*/
@PostConstruct
public void loadPlugins() throws IOException {
File pluginsDir = new File(config.getPluginDir());
if (!pluginsDir.exists()) {
pluginsDir.mkdirs();
}
if (pluginsDir.exists()) {
FilenameFilter jarSuffix = new SuffixFileFilter(".jar");
File[] files = pluginsDir.listFiles(jarSuffix);
for (File file : files) {
storePlugin(file);
}
} else {
LOGGER.warn("Plugins directory does not exist '" + pluginsDir.getAbsolutePath() + "'");
}
}
示例4: testNoDescriptorsInSrc
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
public static void testNoDescriptorsInSrc(String srcDirectoryName) {
// collect the names of all .xml descriptors in the src directory
File srcDirectory = new File(srcDirectoryName);
Set<String> descNames = new HashSet<String>();
Iterator<?> files = org.apache.commons.io.FileUtils.iterateFiles(
srcDirectory,
new SuffixFileFilter(".xml"),
TrueFileFilter.INSTANCE);
while (files.hasNext()) {
File file = (File) files.next();
descNames.add(file.getPath());
}
if (descNames.size() > 0) {
String message = String.format("%d descriptors in src/main/java", descNames.size());
System.err.println(message);
List<String> sortedFileNames = new ArrayList<String>(descNames);
Collections.sort(sortedFileNames);
for (String name : sortedFileNames) {
System.err.println(name);
}
Assert.fail(message);
}
}
示例5: findExternalBundles
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
/**
* Find external/optional bundles from the ~/.motech/bundles directory.
* Additional modules come from that directory, additionally platform bundles
* can be override,
*/
private Map<BundleID, URL> findExternalBundles() throws IOException {
Map<BundleID, URL> externalBundles = new HashMap<>();
if (StringUtils.isNotBlank(externalBundleFolder)) {
File folder = new File(externalBundleFolder);
boolean exists = folder.exists();
if (!exists) {
exists = folder.mkdirs();
}
if (exists) {
File[] files = folder.listFiles((FileFilter) new SuffixFileFilter(".jar"));
URL[] urls = FileUtils.toURLs(files);
for (URL url : urls) {
BundleID bundleID = bundleIdFromURL(url);
if (bundleID != null) {
externalBundles.put(bundleID, url);
}
}
}
}
return externalBundles;
}
示例6: test
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
@Test
public void test() throws IOException {
List<String> imageSuffixes = Lists.newArrayList();
for (ImageInfo.Format format : ImageInfo.Format.values()) {
for (String ext : format.getCommonExtensions()) {
imageSuffixes.add("." + ext);
}
}
SuffixFileFilter filter = new SuffixFileFilter(imageSuffixes);
List<File> files = TestData.getFiles(filter);
for (File file : files) {
byte[] bytes = Files.toByteArray(file);
BytePair magic = MagicNumbers.read(bytes);
System.out.format("%s %s%n", magic, file.getName());
}
}
示例7: extractFileUserIdentifiers
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
/**
* Return set of file user identifiers from a list of files
*
* @param user user who uploaded or will upload file
* @param files list of files objects
* @return Set containing all user identifiers from list of files
*
* @see org.kuali.kfs.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List)
*/
public Set<String> extractFileUserIdentifiers(Person user, List<File> files) {
Set<String> extractedFileUserIdentifiers = new TreeSet<String>();
StringBuilder buf = new StringBuilder();
buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName()).append(FILE_NAME_PART_DELIMITER);
String prefixString = buf.toString();
IOFileFilter prefixFilter = new PrefixFileFilter(prefixString);
IOFileFilter suffixFilter = new SuffixFileFilter(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION);
IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter);
for (File file : files) {
if (combinedFilter.accept(file)) {
String fileName = file.getName();
if (fileName.endsWith(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION)) {
extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString, CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION));
} else {
LOG.error("Unable to determine file user identifier for file name: " + fileName);
throw new RuntimeException("Unable to determine file user identifier for file name: " + fileName);
}
}
}
return extractedFileUserIdentifiers;
}
示例8: VFSManager
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
public VFSManager(File systemDir, File userDir) {
super(systemDir, userDir, new SuffixFileFilter(".xml", IOCase.INSENSITIVE));
Comparator<File> nameComparator = new Comparator<File>() {
@Override
public int compare(File f1, File f2) {
// we want vfs.xml to loaded first, always.
if (f1.getName().equals("x-vfs.xml"))
return Integer.MIN_VALUE;
if (f2.getName().equals("x-vfs.xml"))
return Integer.MAX_VALUE;
return f1.getName().compareToIgnoreCase(f2.getName());
}
};
getSystemFiles().setNameComparator(nameComparator);
}
示例9: DynamicClassLoader
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
public DynamicClassLoader() {
try {
File home = new File(System.getProperty("user.home"), "netxilia");
if (!home.exists()) {
if (!home.mkdir()) {
log.error("Could not create Netxilia storage directory:" + home);
return;
}
}
addFile(home);
for (File jar : home.listFiles((FilenameFilter) new SuffixFileFilter(".jar"))) {
addFile(jar);
}
} catch (IOException e) {
log.error("ERROR:" + e);
}
}
示例10: AutoCompletionManager
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
public AutoCompletionManager(Config config) throws SearchLibException,
IOException {
this.config = config;
autoCompletionDirectory = new File(config.getDirectory(),
autoCompletionSubDirectory);
if (!autoCompletionDirectory.exists())
autoCompletionDirectory.mkdir();
autoCompItems = new TreeSet<AutoCompletionItem>();
File[] autoCompFiles = autoCompletionDirectory
.listFiles((FileFilter) new SuffixFileFilter(".xml"));
if (autoCompFiles == null)
return;
for (File autoCompFile : autoCompFiles) {
try {
add(new AutoCompletionItem(config, autoCompFile));
} catch (InvalidPropertiesFormatException e) {
Logging.warn("Invalid autocompletion file: "
+ autoCompFile.getAbsolutePath());
}
}
}
示例11: calculateNextSequence
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
/**
* Calculate the next sequence used to generate the db-changelog file.
*
* The sequence is formatted as follow:
* leftpad with 0 + number
* @return the next sequence
*/
private String calculateNextSequence() {
final File changeLogFolder = FileSystems.getDefault().getPath(CHANGELOG_FOLER).toFile();
final File[] allChangelogs = changeLogFolder.listFiles((FileFilter) new SuffixFileFilter(".xml"));
Integer sequence = 0;
for (File changelog : allChangelogs) {
String fileName = FilenameUtils.getBaseName(changelog.getName());
String currentSequence = StringUtils.substringAfterLast(fileName, "-");
int cpt = Integer.parseInt(currentSequence);
if (cpt > sequence) {
sequence = cpt;
}
}
sequence++;
return StringUtils.leftPad(sequence.toString(), 3, "0");
}
示例12: scanDirectoriesAtFolderChosen
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
/**
* Scans sub directories associated with the target 'src' folder, lists them into dirsList
* @throws IOException
*
*/
public static synchronized void scanDirectoriesAtFolderChosen(JFileChooser jfc, Path dir, ConcurrentHashMap<String, String> holdValueToKey, WatchService watcher) throws IOException{//JFileChooser jfc, Path dir
File f = new File(jfc.getSelectedFile().getAbsolutePath());
if(f.isDirectory()){
//System.out.println("Is a directory: "+jfc.getSelectedFile().getAbsolutePath());
File rFile = new File(jfc.getSelectedFile().getAbsolutePath());
SuffixFileFilter extFilter = new SuffixFileFilter("java");
Collection filesListUtil = FileUtils.listFilesAndDirs(rFile,extFilter,TrueFileFilter.INSTANCE); //get utils for files in subdir, looks for .java files as well
ArrayList<File> filesList = new ArrayList<File>();
ArrayList<File> dirsList = new ArrayList<File>();
for(java.util.Iterator fileIter = filesListUtil.iterator();fileIter.hasNext();){ //iterate through filesListUtil subdirs, add to filesList to be watched
File currentF = (File) fileIter.next();
//System.out.println("Reading Paths from: "+currentF.getAbsolutePath());
if(!(currentF.isDirectory())){
filesList.add(currentF); //add each file while iterating through subdirectories
}else{
dirsList.add(currentF); //add each dir to watch
}
}
/**
* File system traversal
*/
System.out.println("WatchService: DirectoriesList length = "+dirsList.size());
//System.out.println("FilesListUtil length: "+filesListUtil.size());
fileSystemTraversal(dirsList, dir, watcher, holdValueToKey);
}
}
示例13: findClassNamesInDirectory
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
protected static Set<String> findClassNamesInDirectory(File classesDirectory, boolean recursive) {
Set<String> classNames = Sets.newLinkedHashSet();
SimpleFileScanner simpleFileScanner = SimpleFileScanner.INSTANCE;
Set<File> classFiles = simpleFileScanner.scan(classesDirectory, recursive, new SuffixFileFilter(FileSuffixConstants.CLASS));
for (File classFile : classFiles) {
String className = resolveClassName(classesDirectory, classFile);
classNames.add(className);
}
return classNames;
}
示例14: setupExternalFileOutput
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
public static void setupExternalFileOutput() {
try {
Date currentDate = new Date();
long currentTime = currentDate.getTime();
String fileName = new SimpleDateFormat("yyMMddhhmm").format(currentDate) + ".log";
File logFile = new File(LwjglFiles.externalPath + AppConstants.LOGS_DIR + File.separator + fileName);
logFile.getParentFile().mkdirs();
for (File oldLogFile : logFile.getParentFile().listFiles((FileFilter)new SuffixFileFilter(LOG_FILE_EXTENSION))) {
long lastModified = oldLogFile.lastModified();
if (currentTime - lastModified > EXPIRATION_THRESHOLD) {
try { oldLogFile.delete(); } catch (SecurityException ignored) { }
}
}
FileOutputStream logFileOutputStream = new FileOutputStream(logFile);
System.setOut(new PrintStream(new OutputStreamMultiplexer(
new FileOutputStream(FileDescriptor.out),
logFileOutputStream
)));
System.setErr(new PrintStream(new OutputStreamMultiplexer(
new FileOutputStream(FileDescriptor.err),
logFileOutputStream
)));
System.out.println("Version: " + AppConstants.version);
System.out.println("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch"));
System.out.println("JRE: " + System.getProperty("java.version") + " " + System.getProperty("java.vendor"));
System.out.println("External log file: " + logFile.getAbsolutePath());
} catch (FileNotFoundException e) {
System.err.println("Can't setup logging to external file.");
e.printStackTrace();
}
}
示例15: getOsgiBootstrapClasspath
import org.apache.commons.io.filefilter.SuffixFileFilter; //导入依赖的package包/类
public static List<File> getOsgiBootstrapClasspath(File engineDirectory)
{
if (engineDirectory == null || !engineDirectory.isDirectory())
{
return Collections.emptyList();
}
List<File> classPathFiles = new ArrayList<>();
addToClassPath(classPathFiles, new File(engineDirectory, OsgiDir.INSTALL_AREA + "/" + OsgiDir.LIB_BOOT), new SuffixFileFilter(".jar"));
return classPathFiles;
}