Java Code Examples for org.apache.commons.io.filefilter.FileFilterUtils#and()

The following examples show how to use org.apache.commons.io.filefilter.FileFilterUtils#and() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HbaseConfigMonitor.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
public void init(HbaseAdapter hbaseAdapter, Properties envProperties) {
    this.hbaseAdapter = hbaseAdapter;
    this.envProperties = envProperties;
    File confDir = Util.getConfDirPath(adapterName);
    try {
        FileAlterationObserver observer = new FileAlterationObserver(confDir,
            FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml")));
        FileListener listener = new FileListener();
        observer.addListener(listener);
        fileMonitor = new FileAlterationMonitor(3000, observer);
        fileMonitor.start();

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 2
Source File: HbaseConfigMonitor.java    From canal with Apache License 2.0 6 votes vote down vote up
public void init(HbaseAdapter hbaseAdapter, Properties envProperties) {
    this.hbaseAdapter = hbaseAdapter;
    this.envProperties = envProperties;
    File confDir = Util.getConfDirPath(adapterName);
    try {
        FileAlterationObserver observer = new FileAlterationObserver(confDir,
            FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml")));
        FileListener listener = new FileListener();
        observer.addListener(listener);
        fileMonitor = new FileAlterationMonitor(3000, observer);
        fileMonitor.start();

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 3
Source File: ApplicationConfigMonitor.java    From canal with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
    File confDir = Util.getConfDirPath();
    try {
        FileAlterationObserver observer = new FileAlterationObserver(confDir,
            FileFilterUtils.and(FileFilterUtils.fileFileFilter(),
                FileFilterUtils.prefixFileFilter("application"),
                FileFilterUtils.suffixFileFilter("yml")));
        FileListener listener = new FileListener();
        observer.addListener(listener);
        fileMonitor = new FileAlterationMonitor(3000, observer);
        fileMonitor.start();

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 4
Source File: ESConfigMonitor.java    From canal with Apache License 2.0 6 votes vote down vote up
public void init(ESAdapter esAdapter, Properties envProperties) {
    this.esAdapter = esAdapter;
    this.envProperties = envProperties;
    this.adapterName = envProperties.getProperty("es.version");
    File confDir = Util.getConfDirPath(adapterName);
    try {
        FileAlterationObserver observer = new FileAlterationObserver(confDir,
            FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml")));
        FileListener listener = new FileListener();
        observer.addListener(listener);
        fileMonitor = new FileAlterationMonitor(3000, observer);
        fileMonitor.start();

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 5
Source File: RdbConfigMonitor.java    From canal with Apache License 2.0 6 votes vote down vote up
public void init(String key, RdbAdapter rdbAdapter, Properties envProperties) {
    this.key = key;
    this.rdbAdapter = rdbAdapter;
    this.envProperties = envProperties;
    File confDir = Util.getConfDirPath(adapterName);
    try {
        FileAlterationObserver observer = new FileAlterationObserver(confDir,
            FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml")));
        FileListener listener = new FileListener();
        observer.addListener(listener);
        fileMonitor = new FileAlterationMonitor(3000, observer);
        fileMonitor.start();

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 6
Source File: ESConfigMonitor.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
public void init(ESAdapter esAdapter, Properties envProperties) {
        this.esAdapter = esAdapter;
        this.envProperties = envProperties;
        File confDir = Util.getConfDirPath(adapterName);
        try {
            FileAlterationObserver observer = new FileAlterationObserver(confDir,
                FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml")));
//            文件变化监听采用的common io的类库
            FileListener listener = new FileListener();
            observer.addListener(listener);
            fileMonitor = new FileAlterationMonitor(3000, observer);
            fileMonitor.start();

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
 
Example 7
Source File: RdbConfigMonitor.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
public void init(String key, RdbAdapter rdbAdapter, Properties envProperties) {
    this.key = key;
    this.rdbAdapter = rdbAdapter;
    this.envProperties = envProperties;
    File confDir = Util.getConfDirPath(adapterName);
    try {
        FileAlterationObserver observer = new FileAlterationObserver(confDir,
            FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml")));
        FileListener listener = new FileListener();
        observer.addListener(listener);
        fileMonitor = new FileAlterationMonitor(3000, observer);
        fileMonitor.start();

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 8
Source File: ApplicationConfigMonitor.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
    File confDir = Util.getConfDirPath();
    try {
        FileAlterationObserver observer = new FileAlterationObserver(confDir,
            FileFilterUtils.and(FileFilterUtils.fileFileFilter(),
                FileFilterUtils.prefixFileFilter("application"),
                FileFilterUtils.suffixFileFilter("yml")));
        FileListener listener = new FileListener();
        observer.addListener(listener);
        fileMonitor = new FileAlterationMonitor(3000, observer);
        fileMonitor.start();

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 9
Source File: SensitiveWordMonitor.java    From everyone-java-blog with Apache License 2.0 5 votes vote down vote up
public void monitor(String directory, int interval) {
    FileAlterationObserver fileAlterationObserver = new FileAlterationObserver(directory, FileFilterUtils.and(FileFilterUtils.nameFileFilter(SENSITIVE_WORD_FILE_NAME)), null);
    fileAlterationObserver.addListener(this);
    FileAlterationMonitor fileAlterationMonitor = new FileAlterationMonitor(interval, fileAlterationObserver);

    try {
        fileAlterationMonitor.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 10
Source File: KuduConfigMonitor.java    From canal with Apache License 2.0 5 votes vote down vote up
public void init(KuduAdapter kuduAdapter, Properties envProperties) {
    this.kuduAdapter = kuduAdapter;
    this.envProperties = envProperties;
    File confDir = Util.getConfDirPath(adapterName);
    try {
        FileAlterationObserver observer = new FileAlterationObserver(confDir,
            FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("yml")));
        FileListener listener = new FileListener();
        observer.addListener(listener);
        fileMonitor = new FileAlterationMonitor(3000, observer);
        fileMonitor.start();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example 11
Source File: PrintPreviewDialog.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Object[] doInBackground()
{
	IOFileFilter pdfFilter = FileFilterUtils.asFileFilter(this);
	IOFileFilter suffixFilter = FileFilterUtils.notFileFilter(new SuffixFileFilter(".fo"));
	IOFileFilter sheetFilter = FileFilterUtils.prefixFileFilter(Constants.CHARACTER_TEMPLATE_PREFIX);
	IOFileFilter fileFilter = FileFilterUtils.and(pdfFilter, suffixFilter, sheetFilter);

	IOFileFilter dirFilter = TrueFileFilter.INSTANCE;
	File dir = new File(ConfigurationSettings.getOutputSheetsDir());
	Collection<File> files = FileUtils.listFiles(dir, fileFilter, dirFilter);
	URI osPath = new File(ConfigurationSettings.getOutputSheetsDir()).toURI();
	return files.stream().map(v -> osPath.relativize(v.toURI())).toArray();
}
 
Example 12
Source File: PrintPreviewDialog.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Object[] doInBackground()
{
	IOFileFilter pdfFilter = FileFilterUtils.asFileFilter(this);
	IOFileFilter suffixFilter = FileFilterUtils.notFileFilter(new SuffixFileFilter(".fo"));
	IOFileFilter sheetFilter = FileFilterUtils.prefixFileFilter(Constants.CHARACTER_TEMPLATE_PREFIX);
	IOFileFilter fileFilter = FileFilterUtils.and(pdfFilter, suffixFilter, sheetFilter);

	IOFileFilter dirFilter = TrueFileFilter.INSTANCE;
	File dir = new File(ConfigurationSettings.getOutputSheetsDir());
	Collection<File> files = FileUtils.listFiles(dir, fileFilter, dirFilter);
	URI osPath = new File(ConfigurationSettings.getOutputSheetsDir()).toURI();
	return files.stream().map(v -> osPath.relativize(v.toURI())).toArray();
}
 
Example 13
Source File: ImportWorker.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a filter that returns everything in the "mods" folder except
 * the specified cubes which are distributed with each new release and
 * any existing themes which are now found in the "themes" folder.
 */
private FileFilter getModsFileFilter() {
    final String[] excludedCubes = new String[]{
        "legacy_cube.txt", "modern_cube.txt", "standard_cube.txt", "extended_cube.txt", "ubeefx_cube.txt"
    };
    final IOFileFilter cubesFilter = new NameFileFilter(excludedCubes, IOCase.INSENSITIVE);
    final IOFileFilter excludeCubes = FileFilterUtils.notFileFilter(cubesFilter);
    final IOFileFilter excludeThemes = FileFilterUtils.notFileFilter(new WildcardFileFilter("*_theme*"));
    return FileFilterUtils.and(excludeCubes, excludeThemes);
}
 
Example 14
Source File: AbstractIteratorMojo.java    From iterator-maven-plugin with Apache License 2.0 5 votes vote down vote up
public List<String> getFolders()
    throws MojoExecutionException
{
    IOFileFilter folders = FileFilterUtils.and( HiddenFileFilter.VISIBLE, DirectoryFileFilter.DIRECTORY );
    IOFileFilter makeSVNAware = FileFilterUtils.makeSVNAware( folders );
    IOFileFilter makeCVSAware = FileFilterUtils.makeCVSAware( makeSVNAware );

    String[] list = folder.list( makeCVSAware );
    if ( list == null )
    {
        throw new MojoExecutionException( "The specified folder doesn't exist: " + folder );
    }

    List<File> listOfDirectories = new ArrayList<File>();
    for ( String item : list )
    {
        listOfDirectories.add( new File( folder, item ) );
    }

    Collections.sort( listOfDirectories, convertSortOrder() );
    List<String> resultList = new ArrayList<String>();
    for ( File file : listOfDirectories )
    {
        resultList.add( file.getName() );
    }
    return resultList;
}
 
Example 15
Source File: ExportDialog.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void refreshFiles()
{
	String outputSheetsDir;
	SheetFilter sheetFilter = (SheetFilter) exportBox.getSelectedItem();
	IOFileFilter ioFilter = FileFilterUtils.asFileFilter(sheetFilter);
	IOFileFilter prefixFilter;
	String defaultSheet = null;
	String outputSheetDirectory = SettingsHandler.getGameAsProperty().get().getOutputSheetDirectory();
	if (outputSheetDirectory == null)
	{
		outputSheetsDir = ConfigurationSettings.getOutputSheetsDir() + "/" + sheetFilter.getPath();
	}
	else
	{
		outputSheetsDir = ConfigurationSettings.getOutputSheetsDir() + "/" + outputSheetDirectory + "/"
			+ sheetFilter.getPath();
	}

	if (partyBox.isSelected())
	{
		prefixFilter = FileFilterUtils.prefixFileFilter(Constants.PARTY_TEMPLATE_PREFIX);
	}
	else
	{
		CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem();
		prefixFilter = FileFilterUtils.prefixFileFilter(Constants.CHARACTER_TEMPLATE_PREFIX);
		defaultSheet = character.getDefaultOutputSheet(sheetFilter == SheetFilter.PDF);
		if (StringUtils.isEmpty(defaultSheet))
		{
			defaultSheet = outputSheetsDir + "/"
				+ SettingsHandler.getGameAsProperty().get().getOutputSheetDefault(sheetFilter.getTag());
		}
	}
	IOFileFilter filter = FileFilterUtils.and(prefixFilter, ioFilter);
	List<File> files = FileFilterUtils.filterList(filter, allTemplates);
	Collections.sort(files);

	URI osPath = new File(outputSheetsDir).toURI();
	URI[] uriList = new URI[files.size()];
	Arrays.setAll(uriList, i -> osPath.relativize(files.get(i).toURI()));
	fileList.setListData(uriList);
	if (StringUtils.isNotEmpty(defaultSheet))
	{
		URI defaultPath = new File(defaultSheet).toURI();
		fileList.setSelectedValue(osPath.relativize(defaultPath), true);
	}
}
 
Example 16
Source File: ExportDialog.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void refreshFiles()
{
	String outputSheetsDir;
	SheetFilter sheetFilter = (SheetFilter) exportBox.getSelectedItem();
	IOFileFilter ioFilter = FileFilterUtils.asFileFilter(sheetFilter);
	IOFileFilter prefixFilter;
	String defaultSheet = null;
	String outputSheetDirectory = SettingsHandler.getGameAsProperty().get().getOutputSheetDirectory();
	if (outputSheetDirectory == null)
	{
		outputSheetsDir = ConfigurationSettings.getOutputSheetsDir() + "/" + sheetFilter.getPath();
	}
	else
	{
		outputSheetsDir = ConfigurationSettings.getOutputSheetsDir() + "/" + outputSheetDirectory + "/"
			+ sheetFilter.getPath();
	}

	if (partyBox.isSelected())
	{
		prefixFilter = FileFilterUtils.prefixFileFilter(Constants.PARTY_TEMPLATE_PREFIX);
	}
	else
	{
		CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem();
		prefixFilter = FileFilterUtils.prefixFileFilter(Constants.CHARACTER_TEMPLATE_PREFIX);
		defaultSheet = character.getDefaultOutputSheet(sheetFilter == SheetFilter.PDF);
		if (StringUtils.isEmpty(defaultSheet))
		{
			defaultSheet = outputSheetsDir + "/"
				+ SettingsHandler.getGameAsProperty().get().getOutputSheetDefault(sheetFilter.getTag());
		}
	}
	IOFileFilter filter = FileFilterUtils.and(prefixFilter, ioFilter);
	List<File> files = FileFilterUtils.filterList(filter, allTemplates);
	Collections.sort(files);

	URI osPath = new File(outputSheetsDir).toURI();
	URI[] uriList = new URI[files.size()];
	Arrays.setAll(uriList, i -> osPath.relativize(files.get(i).toURI()));
	fileList.setListData(uriList);
	if (StringUtils.isNotEmpty(defaultSheet))
	{
		URI defaultPath = new File(defaultSheet).toURI();
		fileList.setSelectedValue(osPath.relativize(defaultPath), true);
	}
}
 
Example 17
Source File: FileMonitorTest.java    From spring-boot with Apache License 2.0 3 votes vote down vote up
/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {


    // 监控根目录,会递归监控子文件夹变化

    String rootDir = "D:\\download";
    // 轮询间隔 5 秒,通过重新启动 FileAlterationMonitor 实现
    long interval = TimeUnit.SECONDS.toMillis(5);


    // 创建一个文件观察器用于处理文件的格式
    // Create a FileFilter
    IOFileFilter directories = FileFilterUtils.and(FileFilterUtils.directoryFileFilter(), HiddenFileFilter.VISIBLE);
    IOFileFilter files = FileFilterUtils.and(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter(".java"));
    IOFileFilter filter = FileFilterUtils.or(directories, files);

    // Create the File system observer and register File Listeners
    FileAlterationObserver observer = new FileAlterationObserver(rootDir, filter, null);
    observer.addListener(new FileMonitorFileListener()); //设置文件变化监听器

    //创建文件变化监听器
    FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer);

    // 开始监控
    monitor.start();

}
 
Example 18
Source File: FileUtils.java    From aion-germany with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a filter that accepts directories in addition to the {@link File} objects accepted by the given filter.
 * 
 * @param dirFilter a base filter to add to
 * @return a filter that accepts directories 
 */
private static IOFileFilter setUpEffectiveDirFilter(IOFileFilter dirFilter) {
    return dirFilter == null ? FalseFileFilter.INSTANCE : FileFilterUtils.and(dirFilter,
            DirectoryFileFilter.INSTANCE);
}
 
Example 19
Source File: FileUtils.java    From aion-germany with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns a filter that accepts files in addition to the {@link File} objects accepted by the given filter.
 * 
 * @param fileFilter a base filter to add to
 * @return a filter that accepts files 
 */
private static IOFileFilter setUpEffectiveFileFilter(IOFileFilter fileFilter) {
    return FileFilterUtils.and(fileFilter, FileFilterUtils.notFileFilter(DirectoryFileFilter.INSTANCE));
}
 
Example 20
Source File: FileUtils.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns a filter that accepts directories in addition to the {@link File} objects accepted by the given filter.
 *
 * @param dirFilter a base filter to add to
 * @return a filter that accepts directories
 */
private static IOFileFilter setUpEffectiveDirFilter(final IOFileFilter dirFilter) {
    return dirFilter == null ? FalseFileFilter.INSTANCE : FileFilterUtils.and(dirFilter,
            DirectoryFileFilter.INSTANCE);
}