Search in sources :

Example 96 with FileFilter

use of java.io.FileFilter in project oxTrust by GluuFederation.

the class ViewLogFileAction method prepareLogFiles.

private Map<Integer, String> prepareLogFiles() {
    Map<Integer, String> logFiles = new HashMap<Integer, String>();
    int fileIndex = 0;
    for (SimpleCustomProperty logTemplate : this.logViewerConfiguration.getLogTemplates()) {
        String logTemplatePattern = logTemplate.getValue2();
        if (StringHelper.isEmpty(logTemplatePattern)) {
            continue;
        }
        String logTemplatePath = FilenameUtils.getFullPath(logTemplatePattern);
        String logTemplateFile = FilenameUtils.getName(logTemplatePattern);
        File logTemplateBaseDir = new File(logTemplatePath);
        FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(logTemplateFile));
        File[] files = logTemplateBaseDir.listFiles(fileFilter);
        if (files == null) {
            continue;
        }
        for (int i = 0; i < files.length; i++) {
            logFiles.put(fileIndex++, files[i].getPath());
        }
    }
    return logFiles;
}
Also used : AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) HashMap(java.util.HashMap) SimpleCustomProperty(org.xdi.model.SimpleCustomProperty) AndFileFilter(org.apache.commons.io.filefilter.AndFileFilter) FileFileFilter(org.apache.commons.io.filefilter.FileFileFilter) FileFilter(java.io.FileFilter) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter)

Example 97 with FileFilter

use of java.io.FileFilter in project intellij-plugins by JetBrains.

the class FlashBuilderSdkFinder method findFBInstallationPath.

@Nullable
public static String findFBInstallationPath() {
    final List<File> fbDirs = new ArrayList<>();
    final FileFilter filter = dir -> {
        final String name = dir.getName();
        return dir.isDirectory() && (name.contains("Flash") || name.contains("Flex")) && name.contains("Builder") && new File(dir, SDKS_FOLDER).isDirectory();
    };
    final String programsPath = SystemInfo.isMac ? "/Applications" : SystemInfo.isWindows ? System.getenv("ProgramFiles") : null;
    final File programsDir = programsPath == null ? null : new File(programsPath);
    if (programsDir != null && programsDir.isDirectory()) {
        Collections.addAll(fbDirs, programsDir.listFiles(filter));
        final File adobeDir = new File(programsDir, "Adobe");
        if (adobeDir.isDirectory()) {
            Collections.addAll(fbDirs, adobeDir.listFiles(filter));
        }
    }
    if (SystemInfo.isWindows) {
        final String programs64Path = System.getenv("ProgramW6432");
        final File programs64Dir = programs64Path == null ? null : new File(programs64Path);
        if (programs64Dir != null && programs64Dir.isDirectory()) {
            Collections.addAll(fbDirs, programs64Dir.listFiles(filter));
            final File adobeDir = new File(programs64Dir, "Adobe");
            if (adobeDir.isDirectory()) {
                Collections.addAll(fbDirs, adobeDir.listFiles(filter));
            }
        }
    }
    if (fbDirs.size() == 0)
        return null;
    if (fbDirs.size() == 1)
        return fbDirs.get(0).getPath();
    // check the most recent
    Pair<String, String> pathAndVersion = null;
    for (File fbDir : fbDirs) {
        final String version = guessFBVersion(fbDir.getName());
        if (pathAndVersion == null || StringUtil.compareVersionNumbers(version, pathAndVersion.second) > 0) {
            pathAndVersion = Pair.create(fbDir.getPath(), version);
        }
    }
    assert pathAndVersion != null;
    return pathAndVersion.first;
}
Also used : FlexUtils(com.intellij.lang.javascript.flex.FlexUtils) java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) SelectFlexSdkDialog(com.intellij.lang.javascript.flex.projectStructure.ui.SelectFlexSdkDialog) FlexSdkType2(com.intellij.lang.javascript.flex.sdk.FlexSdkType2) JDOMException(org.jdom.JDOMException) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JDOMUtil(com.intellij.openapi.util.JDOMUtil) Project(com.intellij.openapi.project.Project) FileUtil(com.intellij.openapi.util.io.FileUtil) FlexSdkUtils(com.intellij.lang.javascript.flex.sdk.FlexSdkUtils) StringUtil(com.intellij.openapi.util.text.StringUtil) Attribute(org.jdom.Attribute) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FlexBundle(com.intellij.lang.javascript.flex.FlexBundle) Sdk(com.intellij.openapi.projectRoots.Sdk) SystemInfo(com.intellij.openapi.util.SystemInfo) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) FileFilter(java.io.FileFilter) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) FileFilter(java.io.FileFilter) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 98 with FileFilter

use of java.io.FileFilter in project CorfuDB by CorfuDB.

the class StreamLogFiles method trimPrefix.

private void trimPrefix() {
    // Trim all segments up till the segment that contains the starting address
    // (i.e. trim only complete segments)
    long endSegment = (startingAddress / RECORDS_PER_LOG_FILE) - 1;
    if (endSegment <= 0) {
        log.debug("Only one segment detected, ignoring trim");
        return;
    }
    File dir = new File(logDir);
    FileFilter fileFilter = new FileFilter() {

        public boolean accept(File file) {
            String segmentStr = file.getName().split("\\.")[0];
            return Long.parseLong(segmentStr) <= endSegment;
        }
    };
    File[] files = dir.listFiles(fileFilter);
    for (File file : files) {
        if (!file.delete()) {
            log.error("Couldn't delete/trim file {}", file.getName());
        }
    }
    log.info("Prefix trim completed, delete segments 0 to {}", endSegment);
}
Also used : ByteString(com.google.protobuf.ByteString) FileFilter(java.io.FileFilter) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) File(java.io.File)

Example 99 with FileFilter

use of java.io.FileFilter in project jabref by JabRef.

the class EntryFromFileCreatorManager method getFileFilterList.

/**
     * Returns a list of all {@link FileFilter} instances (i.e.
     * {@link EntryFromFileCreator}, plus the file filter that comes with the
     * {@link #getFileFilter()} method.
     *
     * @return A List of all known possible file filters.
     */
public List<FileFilter> getFileFilterList() {
    List<FileFilter> filters = new ArrayList<>();
    filters.add(getFileFilter());
    for (FileFilter creator : entryCreators) {
        filters.add(creator);
    }
    return filters;
}
Also used : ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter)

Example 100 with FileFilter

use of java.io.FileFilter in project uPortal by Jasig.

the class JaxbPortalDataHandlerService method importDataDirectory.

@Override
public void importDataDirectory(File directory, String pattern, final BatchImportOptions options) {
    if (!directory.exists()) {
        throw new IllegalArgumentException("The specified directory '" + directory + "' does not exist");
    }
    //Create the file filter to use when searching for files to import
    final FileFilter fileFilter;
    if (pattern != null) {
        fileFilter = new AntPatternFileFilter(true, false, pattern, this.dataFileExcludes);
    } else {
        fileFilter = new AntPatternFileFilter(true, false, this.dataFileIncludes, this.dataFileExcludes);
    }
    //Determine the parent directory to log to
    final File logDirectory = determineLogDirectory(options, "import");
    //Setup reporting file
    final File importReport = new File(logDirectory, "data-import.txt");
    final PrintWriter reportWriter;
    try {
        reportWriter = new PrintWriter(new PeriodicFlushingBufferedWriter(500, new FileWriter(importReport)));
    } catch (IOException e) {
        throw new RuntimeException("Failed to create FileWriter for: " + importReport, e);
    }
    //Convert directory to URI String to provide better logging output
    final URI directoryUri = directory.toURI();
    final String directoryUriStr = directoryUri.toString();
    IMPORT_BASE_DIR.set(directoryUriStr);
    try {
        //Scan the specified directory for files to import
        logger.info("Scanning for files to Import from: {}", directory);
        final PortalDataKeyFileProcessor fileProcessor = new PortalDataKeyFileProcessor(this.dataKeyTypes, options);
        this.directoryScanner.scanDirectoryNoResults(directory, fileFilter, fileProcessor);
        final long resourceCount = fileProcessor.getResourceCount();
        logger.info("Found {} files to Import from: {}", resourceCount, directory);
        //See if the import should fail on error
        final boolean failOnError = options != null ? options.isFailOnError() : true;
        //Map of files to import, grouped by type
        final ConcurrentMap<PortalDataKey, Queue<Resource>> dataToImport = fileProcessor.getDataToImport();
        //Import the data files
        for (final PortalDataKey portalDataKey : this.dataKeyImportOrder) {
            final Queue<Resource> files = dataToImport.remove(portalDataKey);
            if (files == null) {
                continue;
            }
            final Queue<ImportFuture<?>> importFutures = new LinkedList<ImportFuture<?>>();
            final List<FutureHolder<?>> failedFutures = new LinkedList<FutureHolder<?>>();
            final int fileCount = files.size();
            logger.info("Importing {} files of type {}", fileCount, portalDataKey);
            reportWriter.println(portalDataKey + "," + fileCount);
            while (!files.isEmpty()) {
                final Resource file = files.poll();
                //Check for completed futures on every iteration, needed to fail as fast as possible on an import exception
                final List<FutureHolder<?>> newFailed = waitForFutures(importFutures, reportWriter, logDirectory, false);
                failedFutures.addAll(newFailed);
                final AtomicLong importTime = new AtomicLong(-1);
                //Create import task
                final Callable<Object> task = new CallableWithoutResult() {

                    @Override
                    protected void callWithoutResult() {
                        IMPORT_BASE_DIR.set(directoryUriStr);
                        importTime.set(System.nanoTime());
                        try {
                            importData(file, portalDataKey);
                        } finally {
                            importTime.set(System.nanoTime() - importTime.get());
                            IMPORT_BASE_DIR.remove();
                        }
                    }
                };
                //Submit the import task
                final Future<?> importFuture = this.importExportThreadPool.submit(task);
                //Add the future for tracking
                importFutures.offer(new ImportFuture(importFuture, file, portalDataKey, importTime));
            }
            //Wait for all of the imports on of this type to complete
            final List<FutureHolder<?>> newFailed = waitForFutures(importFutures, reportWriter, logDirectory, true);
            failedFutures.addAll(newFailed);
            if (failOnError && !failedFutures.isEmpty()) {
                throw new RuntimeException(failedFutures.size() + " " + portalDataKey + " entities failed to import.\n\n" + "\tPer entity exception logs and a full report can be found in " + logDirectory + "\n");
            }
            reportWriter.flush();
        }
        if (!dataToImport.isEmpty()) {
            throw new IllegalStateException("The following PortalDataKeys are not listed in the dataTypeImportOrder List: " + dataToImport.keySet());
        }
        logger.info("For a detailed report on the data import see " + importReport);
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while waiting for entities to import", e);
    } finally {
        IOUtils.closeQuietly(reportWriter);
        IMPORT_BASE_DIR.remove();
    }
}
Also used : FileWriter(java.io.FileWriter) URI(java.net.URI) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) AntPatternFileFilter(org.apereo.portal.utils.AntPatternFileFilter) AntPatternFileFilter(org.apereo.portal.utils.AntPatternFileFilter) FileFilter(java.io.FileFilter) PeriodicFlushingBufferedWriter(org.apereo.portal.utils.PeriodicFlushingBufferedWriter) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) PrintWriter(java.io.PrintWriter) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) LinkedList(java.util.LinkedList) AtomicLong(java.util.concurrent.atomic.AtomicLong) File(java.io.File)

Aggregations

FileFilter (java.io.FileFilter)232 File (java.io.File)218 ArrayList (java.util.ArrayList)50 IOException (java.io.IOException)40 Test (org.junit.Test)13 FilenameFilter (java.io.FilenameFilter)11 URL (java.net.URL)10 HashMap (java.util.HashMap)10 FileInputStream (java.io.FileInputStream)8 FileNotFoundException (java.io.FileNotFoundException)8 HashSet (java.util.HashSet)8 JarFile (java.util.jar.JarFile)8 Pattern (java.util.regex.Pattern)8 Map (java.util.Map)7 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)7 NotNull (org.jetbrains.annotations.NotNull)7 Treebank (edu.stanford.nlp.trees.Treebank)6 Pair (edu.stanford.nlp.util.Pair)6 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)6 EvaluateTreebank (edu.stanford.nlp.parser.lexparser.EvaluateTreebank)5