Search in sources :

Example 6 with IOFileFilter

use of org.apache.commons.io.filefilter.IOFileFilter in project canal by alibaba.

the class BinLogFileQueue method listBinlogFiles.

private List<File> listBinlogFiles() {
    List<File> files = new ArrayList<File>();
    files.addAll(FileUtils.listFiles(directory, new IOFileFilter() {

        public boolean accept(File file) {
            Pattern pattern = Pattern.compile("\\d+$");
            Matcher matcher = pattern.matcher(file.getName());
            return file.getName().startsWith(baseName) && matcher.find();
        }

        public boolean accept(File dir, String name) {
            return true;
        }
    }, null));
    // 排一下序列
    Collections.sort(files, new Comparator<File>() {

        public int compare(File o1, File o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    return files;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) File(java.io.File)

Example 7 with IOFileFilter

use of org.apache.commons.io.filefilter.IOFileFilter in project atlas by alibaba.

the class TPatchTool method processBundleFiles.

/**
     * 处理bundle的patch文件
     *
     * @param newBundleFile
     * @param baseBundleFile
     * @param patchTmpDir
     * @param diffTxtFile
     */
private void processBundleFiles(File newBundleFile, File baseBundleFile, File patchTmpDir, File diffTxtFile) throws IOException, RecognitionException, PatchException {
    String bundleName = FilenameUtils.getBaseName(newBundleFile.getName());
    File destPatchBundleDir = new File(patchTmpDir, bundleName);
    if (!isModifyBundle(newBundleFile.getName())) {
        return;
    }
    final File newBundleUnzipFolder = new File(newBundleFile.getParentFile(), bundleName);
    final File baseBundleUnzipFolder = new File(baseBundleFile.getParentFile(), bundleName);
    if (null != baseBundleFile && baseBundleFile.isFile() && baseBundleFile.exists() && !noPatchBundles.contains(baseBundleFile.getName().replace("_", ".").substring(3, baseBundleFile.getName().length() - 3)) && diffBundleDex) {
        // 解压文件
        // 判断dex的差异性
        ZipUtils.unzip(newBundleFile, newBundleUnzipFolder.getAbsolutePath());
        ZipUtils.unzip(baseBundleFile, baseBundleUnzipFolder.getAbsolutePath());
        File destDex = new File(destPatchBundleDir, DEX_NAME);
        File tmpDexFolder = new File(patchTmpDir, bundleName + "-dex");
        createBundleDexPatch(newBundleUnzipFolder, baseBundleUnzipFolder, destDex, tmpDexFolder, diffTxtFile);
        // 比较其他资源文件的差异性
        Collection<File> newBundleResFiles = FileUtils.listFiles(newBundleUnzipFolder, new IOFileFilter() {

            @Override
            public boolean accept(File file) {
                // 不包括dex文件
                if (file.getName().endsWith(".dex")) {
                    return false;
                }
                String relativePath = PathUtils.toRelative(newBundleUnzipFolder, file.getAbsolutePath());
                if (null != notIncludeFiles && pathMatcher.match(notIncludeFiles, relativePath)) {
                    return false;
                }
                return true;
            }

            @Override
            public boolean accept(File file, String s) {
                return accept(new File(file, s));
            }
        }, TrueFileFilter.INSTANCE);
        for (File newBundleResFile : newBundleResFiles) {
            String resPath = PathUtils.toRelative(newBundleUnzipFolder, newBundleResFile.getAbsolutePath());
            File baseBundleResFile = new File(baseBundleUnzipFolder, resPath);
            File destResFile = new File(destPatchBundleDir, resPath);
            if (baseBundleResFile.exists()) {
                if (isFileModify(newBundleResFile, baseBundleResFile, bundleName, resPath)) {
                    // 修改的资源
                    FileUtils.copyFile(newBundleResFile, destResFile);
                }
            } else {
                // 新增的资源
                FileUtils.copyFile(newBundleResFile, destResFile);
            }
        }
    } else {
        // 新增的bundle,直接全量解压
        FileUtils.copyFileToDirectory(newBundleFile, patchTmpDir);
    }
}
Also used : IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) File(java.io.File)

Example 8 with IOFileFilter

use of org.apache.commons.io.filefilter.IOFileFilter in project symmetric-ds by JumpMind.

the class FileTrigger method createIOFileFilter.

public IOFileFilter createIOFileFilter() {
    String[] includes = StringUtils.isNotBlank(includesFiles) ? includesFiles.split(",") : new String[] { "*" };
    String[] excludes = StringUtils.isNotBlank(excludesFiles) ? excludesFiles.split(",") : null;
    IOFileFilter filter = new WildcardFileFilter(includes);
    if (excludes != null && excludes.length > 0) {
        List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
        fileFilters.add(filter);
        fileFilters.add(new NotFileFilter(new WildcardFileFilter(excludes)));
        filter = new AndFileFilter(fileFilters);
    }
    if (!recurse) {
        List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
        fileFilters.add(filter);
        fileFilters.add(new NotFileFilter(FileFilterUtils.directoryFileFilter()));
        filter = new AndFileFilter(fileFilters);
    } else {
        List<IOFileFilter> fileFilters = new ArrayList<IOFileFilter>();
        fileFilters.add(filter);
        fileFilters.add(FileFilterUtils.directoryFileFilter());
        filter = new OrFileFilter(fileFilters);
    }
    return filter;
}
Also used : AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) OrFileFilter(org.apache.commons.io.filefilter.OrFileFilter) ArrayList(java.util.ArrayList) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) NotFileFilter(org.apache.commons.io.filefilter.NotFileFilter) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter)

Example 9 with IOFileFilter

use of org.apache.commons.io.filefilter.IOFileFilter in project pcgen by PCGen.

the class ExportDialog method refreshFiles.

private void refreshFiles() {
    if (allTemplates != null) {
        String outputSheetsDir;
        SheetFilter sheetFilter = (SheetFilter) exportBox.getSelectedItem();
        IOFileFilter ioFilter = FileFilterUtils.asFileFilter(sheetFilter);
        IOFileFilter prefixFilter;
        String defaultSheet = null;
        String outputSheetDirectory = SettingsHandler.getGame().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.getGame().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();
        Object[] uriList = new Object[files.size()];
        for (int i = 0; i < uriList.length; i++) {
            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);
        }
    }
}
Also used : IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) CharacterFacade(pcgen.facade.core.CharacterFacade) File(java.io.File) URI(java.net.URI)

Aggregations

IOFileFilter (org.apache.commons.io.filefilter.IOFileFilter)9 File (java.io.File)8 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 URI (java.net.URI)1 Calendar (java.util.Calendar)1 AndFileFilter (org.apache.commons.io.filefilter.AndFileFilter)1 DirectoryFileFilter (org.apache.commons.io.filefilter.DirectoryFileFilter)1 NotFileFilter (org.apache.commons.io.filefilter.NotFileFilter)1 OrFileFilter (org.apache.commons.io.filefilter.OrFileFilter)1 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)1 GitException (org.eclipse.che.api.git.exception.GitException)1 DiffCommitFile (org.eclipse.che.api.git.shared.DiffCommitFile)1 DirCache (org.eclipse.jgit.dircache.DirCache)1 CharacterFacade (pcgen.facade.core.CharacterFacade)1