Search in sources :

Example 1 with PatternFilenameFilter

use of com.google.common.io.PatternFilenameFilter in project EventHub by Codecademy.

the class ShardedEventIndexModule method getEventIndexFactory.

@Provides
public EventIndex.Factory getEventIndexFactory(@Named("eventhub.shardedeventindex.directory") final String shardedEventIndexDirectory, @Named("eventhub.eventindex.initialNumEventIdsPerDay") final int initialNumEventIdsPerDay, final DmaIdList.Factory dmaIdListFactory) {
    dmaIdListFactory.setDefaultCapacity(initialNumEventIdsPerDay);
    return new EventIndex.Factory() {

        @Override
        public EventIndex build(String eventType) {
            String eventIndexDirectory = String.format("%s/%s/", shardedEventIndexDirectory, eventType);
            List<String> dates = Lists.newArrayList();
            File[] files = new File(eventIndexDirectory).listFiles(new PatternFilenameFilter("[0-9]{8}\\.ser"));
            if (files != null) {
                for (File file : files) {
                    dates.add(file.getName().substring(0, 8));
                }
            }
            SortedMap<String, IdList> eventIdListMap = Maps.newTreeMap();
            for (String date : dates) {
                eventIdListMap.put(date, dmaIdListFactory.build(EventIndex.getEventIdListFilename(eventIndexDirectory, date)));
            }
            return new EventIndex(eventIndexDirectory, dmaIdListFactory, eventIdListMap);
        }
    };
}
Also used : PatternFilenameFilter(com.google.common.io.PatternFilenameFilter) File(java.io.File) IdList(com.codecademy.eventhub.list.IdList) DmaIdList(com.codecademy.eventhub.list.DmaIdList) Provides(com.google.inject.Provides)

Example 2 with PatternFilenameFilter

use of com.google.common.io.PatternFilenameFilter in project rpki-validator-3 by RIPE-NCC.

the class PreconfiguredTrustAnchors method managePreconfiguredTrustAnchors.

@PostConstruct
public void managePreconfiguredTrustAnchors() {
    new TransactionTemplate(transactionManager).execute((status) -> {
        log.info("Automatically adding preconfigured trust anchors");
        if (settings.isPreconfiguredTalsLoaded()) {
            log.info("Preconfigured trust anchors are already loaded, skipping");
            return null;
        }
        settings.markPreconfiguredTalsLoaded();
        File[] tals = preconfiguredTrustAnchorDirectory.listFiles(new PatternFilenameFilter(Pattern.compile("^.*\\.tal$")));
        if (ArrayUtils.isEmpty(tals)) {
            log.warn("No preconfigured trust anchors found at {}, skipping", preconfiguredTrustAnchorDirectory);
            return null;
        }
        for (File tal : tals) {
            TrustAnchorLocator locator = TrustAnchorLocator.fromFile(tal);
            if (trustAnchors.findBySubjectPublicKeyInfo(locator.getPublicKeyInfo()).isPresent()) {
                log.info("Preconfigured trust anchor '{}' already installed, skipping", locator.getCaName());
                continue;
            }
            TrustAnchor trustAnchor = new TrustAnchor(true);
            trustAnchor.setName(locator.getCaName());
            trustAnchor.setLocations(locator.getCertificateLocations().stream().map(URI::toASCIIString).collect(Collectors.toList()));
            trustAnchor.setSubjectPublicKeyInfo(locator.getPublicKeyInfo());
            trustAnchor.setRsyncPrefetchUri(locator.getPrefetchUris().stream().filter(uri -> "rsync".equalsIgnoreCase(uri.getScheme())).map(URI::toASCIIString).findFirst().orElse(null));
            trustAnchorService.add(trustAnchor);
        }
        return null;
    });
}
Also used : PatternFilenameFilter(com.google.common.io.PatternFilenameFilter) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TrustAnchor(net.ripe.rpki.validator3.domain.TrustAnchor) File(java.io.File) TrustAnchorLocator(net.ripe.rpki.validator3.util.TrustAnchorLocator) URI(java.net.URI) PostConstruct(javax.annotation.PostConstruct)

Example 3 with PatternFilenameFilter

use of com.google.common.io.PatternFilenameFilter in project calcite by apache.

the class QuidemTest method data.

protected static Collection<Object[]> data(String first) {
    // inUrl = "file:/home/fred/calcite/core/target/test-classes/sql/agg.iq"
    final URL inUrl = JdbcTest.class.getResource("/" + first);
    String x = inUrl.getFile();
    assert x.endsWith(first);
    final String base = File.separatorChar == '\\' ? x.substring(1, x.length() - first.length()).replace('/', File.separatorChar) : x.substring(0, x.length() - first.length());
    final File firstFile = new File(x);
    final File dir = firstFile.getParentFile();
    final List<String> paths = new ArrayList<>();
    final FilenameFilter filter = new PatternFilenameFilter(".*\\.iq$");
    for (File f : Util.first(dir.listFiles(filter), new File[0])) {
        assert f.getAbsolutePath().startsWith(base) : "f: " + f.getAbsolutePath() + "; base: " + base;
        paths.add(f.getAbsolutePath().substring(base.length()));
    }
    return Lists.transform(paths, new Function<String, Object[]>() {

        public Object[] apply(String path) {
            return new Object[] { path };
        }
    });
}
Also used : FilenameFilter(java.io.FilenameFilter) PatternFilenameFilter(com.google.common.io.PatternFilenameFilter) PatternFilenameFilter(com.google.common.io.PatternFilenameFilter) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL)

Example 4 with PatternFilenameFilter

use of com.google.common.io.PatternFilenameFilter in project intellij-community by JetBrains.

the class IdeaLicenseHelper method copyIDEALicense.

public static void copyIDEALicense(final String sandboxHome) {
    File sandboxSystemPath = new File(sandboxHome, "system");
    File systemPath = new File(PathManager.getSystemPath());
    File[] runningIdeaLicenses = systemPath.listFiles(new PatternFilenameFilter("idea\\d+\\.key"));
    if (runningIdeaLicenses != null) {
        for (File license : runningIdeaLicenses) {
            File devIdeaLicense = new File(sandboxSystemPath, license.getName());
            if (!devIdeaLicense.exists()) {
                try {
                    FileUtil.copy(license, devIdeaLicense);
                } catch (IOException e) {
                    LOG.error(e);
                }
            }
        }
    }
}
Also used : PatternFilenameFilter(com.google.common.io.PatternFilenameFilter) IOException(java.io.IOException) File(java.io.File)

Example 5 with PatternFilenameFilter

use of com.google.common.io.PatternFilenameFilter in project Glowstone by GlowstoneMC.

the class GlowPluginTypeDetector method scan.

public void scan() {
    GlowServer.logger.info("Scanning plugins...");
    File[] files = directory.listFiles(new PatternFilenameFilter(".+\\.jar"));
    if (files == null || files.length == 0) {
        return;
    }
    for (File file : files) {
        scanFile(file);
    }
    GlowServer.logger.info("PluginTypeDetector: found " + bukkitPlugins.size() + " Bukkit, " + spongePlugins.size() + " Sponge, " + (forgefPlugins.size() + forgenPlugins.size()) + " Forge, " + canaryPlugins.size() + " Canary, " + unrecognizedPlugins.size() + " unknown plugins (total " + files.length + ")");
    if (!unrecognizedPlugins.isEmpty()) {
        for (File file : unrecognizedPlugins) {
            GlowServer.logger.warning("Unrecognized plugin: " + file.getPath());
        }
    }
}
Also used : PatternFilenameFilter(com.google.common.io.PatternFilenameFilter) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Aggregations

PatternFilenameFilter (com.google.common.io.PatternFilenameFilter)5 File (java.io.File)5 DmaIdList (com.codecademy.eventhub.list.DmaIdList)1 IdList (com.codecademy.eventhub.list.IdList)1 Provides (com.google.inject.Provides)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ZipFile (java.util.zip.ZipFile)1 PostConstruct (javax.annotation.PostConstruct)1 TrustAnchor (net.ripe.rpki.validator3.domain.TrustAnchor)1 TrustAnchorLocator (net.ripe.rpki.validator3.util.TrustAnchorLocator)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1