Search in sources :

Example 1 with FilenameFilter

use of java.io.FilenameFilter in project jetty.project by eclipse.

the class FileSessionDataStore method doGetExpired.

/** 
     * @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
     */
@Override
public Set<String> doGetExpired(final Set<String> candidates) {
    final long now = System.currentTimeMillis();
    HashSet<String> expired = new HashSet<String>();
    File[] files = _storeDir.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            if (dir != _storeDir)
                return false;
            //dir may contain files that don't match our naming pattern
            int index = name.indexOf('_');
            if (index < 0)
                return false;
            try {
                long expiry = Long.parseLong(name.substring(0, index));
                return expiry > 0 && expiry < now;
            } catch (NumberFormatException e) {
                return false;
            }
        }
    });
    if (files != null) {
        for (File f : files) {
            expired.add(getIdFromFile(f));
        }
    }
    //longer exist and they should be expired
    for (String c : candidates) {
        if (!expired.contains(c)) {
            //check if the file exists
            File f = getFile(_storeDir, c);
            if (f == null || !f.exists())
                expired.add(c);
        }
    }
    return expired;
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with FilenameFilter

use of java.io.FilenameFilter in project jetty.project by eclipse.

the class HpackPerfTest method runStories.

private void runStories(int maxDynamicTableSize) throws Exception {
    // Find files
    File data = MavenTestingUtils.getTestResourceDir("data");
    String[] files = data.list(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.startsWith("story_");
        }
    });
    // Parse JSON
    Map<String, Object>[] stories = new Map[files.length];
    int i = 0;
    for (String story : files) stories[i++] = (Map<String, Object>) JSON.parse(new FileReader(new File(data, story)));
    ByteBuffer buffer = BufferUtil.allocate(256 * 1024);
    // Encode all the requests
    encodeStories(buffer, stories, "request");
    // clear table
    BufferUtil.clearToFill(buffer);
    BufferUtil.flipToFlush(buffer, 0);
    // Encode all the responses
    encodeStories(buffer, stories, "response");
}
Also used : FilenameFilter(java.io.FilenameFilter) FileReader(java.io.FileReader) File(java.io.File) Map(java.util.Map) ByteBuffer(java.nio.ByteBuffer)

Example 3 with FilenameFilter

use of java.io.FilenameFilter in project storm by apache.

the class Localizer method readCurrentBlobs.

// Looks for files in the directory with .current suffix
protected File[] readCurrentBlobs(String location) {
    File dir = new File(location);
    File[] files = null;
    if (dir.exists()) {
        files = dir.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(Utils.DEFAULT_CURRENT_BLOB_SUFFIX);
            }
        });
    }
    return files;
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 4 with FilenameFilter

use of java.io.FilenameFilter in project head by mifos.

the class DatasetVersionTest method checkDataSetDatabaseVersion.

@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void checkDataSetDatabaseVersion() throws Exception {
    class FileExtensionFilter implements FilenameFilter {

        String prefix = "*";

        String ext = "*";

        public FileExtensionFilter(String prefix, String ext) {
            this.prefix = prefix;
            this.ext = ext;
        }

        @Override
        public boolean accept(@SuppressWarnings("unused") File dir, String name) {
            boolean validFile = false;
            if (name.startsWith(prefix) && name.endsWith(ext)) {
                validFile = true;
            }
            return validFile;
        }
    }
    // FIXME - Path works for maven build but not from eclipse
    // To run this test in eclipse, change path below to: "acceptanceTests/target/test-classes/dataSets"
    File f = new File("target/test-classes/dataSets");
    FileExtensionFilter filter = new FileExtensionFilter("", "dbunit.xml");
    File[] acceptList = f.listFiles(filter);
    for (File element : acceptList) {
        verifyDatabaseVersion(element.getName());
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 5 with FilenameFilter

use of java.io.FilenameFilter in project pinot by linkedin.

the class CreateSegmentCommand method execute.

@Override
public boolean execute() throws Exception {
    LOGGER.info("Executing command: {}", toString());
    // Load generator config if exist.
    final SegmentGeneratorConfig segmentGeneratorConfig;
    if (_generatorConfigFile != null) {
        segmentGeneratorConfig = new ObjectMapper().readValue(new File(_generatorConfigFile), SegmentGeneratorConfig.class);
    } else {
        segmentGeneratorConfig = new SegmentGeneratorConfig();
    }
    // Load config from segment generator config.
    String configDataDir = segmentGeneratorConfig.getDataDir();
    if (_dataDir == null) {
        if (configDataDir == null) {
            throw new RuntimeException("Must specify dataDir.");
        }
        _dataDir = configDataDir;
    } else {
        if (configDataDir != null && !configDataDir.equals(_dataDir)) {
            LOGGER.warn("Find dataDir conflict in command line and config file, use config in command line: {}", _dataDir);
        }
    }
    FileFormat configFormat = segmentGeneratorConfig.getFormat();
    if (_format == null) {
        if (configFormat == null) {
            throw new RuntimeException("Format cannot be null in config file.");
        }
        _format = configFormat;
    } else {
        if (configFormat != _format && configFormat != FileFormat.AVRO) {
            LOGGER.warn("Find format conflict in command line and config file, use config in command line: {}", _format);
        }
    }
    String configOutDir = segmentGeneratorConfig.getOutDir();
    if (_outDir == null) {
        if (configOutDir == null) {
            throw new RuntimeException("Must specify outDir.");
        }
        _outDir = configOutDir;
    } else {
        if (configOutDir != null && !configOutDir.equals(_outDir)) {
            LOGGER.warn("Find outDir conflict in command line and config file, use config in command line: {}", _outDir);
        }
    }
    if (segmentGeneratorConfig.isOverwrite()) {
        _overwrite = true;
    }
    String configTableName = segmentGeneratorConfig.getTableName();
    if (_tableName == null) {
        if (configTableName == null) {
            throw new RuntimeException("Must specify tableName.");
        }
        _tableName = configTableName;
    } else {
        if (configTableName != null && !configTableName.equals(_tableName)) {
            LOGGER.warn("Find tableName conflict in command line and config file, use config in command line: {}", _tableName);
        }
    }
    String configSegmentName = segmentGeneratorConfig.getSegmentName();
    if (_segmentName == null) {
        if (configSegmentName == null) {
            throw new RuntimeException("Must specify segmentName.");
        }
        _segmentName = configSegmentName;
    } else {
        if (configSegmentName != null && !configSegmentName.equals(_segmentName)) {
            LOGGER.warn("Find segmentName conflict in command line and config file, use config in command line: {}", _segmentName);
        }
    }
    // Filter out all input files.
    File dir = new File(_dataDir);
    if (!dir.exists() || !dir.isDirectory()) {
        throw new RuntimeException("Data directory " + _dataDir + " not found.");
    }
    File[] files = dir.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(_format.toString().toLowerCase());
        }
    });
    if ((files == null) || (files.length == 0)) {
        throw new RuntimeException("Data directory " + _dataDir + " does not contain " + _format.toString().toUpperCase() + " files.");
    }
    // Make sure output directory does not already exist, or can be overwritten.
    File outDir = new File(_outDir);
    if (outDir.exists()) {
        if (!_overwrite) {
            throw new IOException("Output directory " + _outDir + " already exists.");
        } else {
            FileUtils.deleteDirectory(outDir);
        }
    }
    // Set other generator configs from command line.
    segmentGeneratorConfig.setDataDir(_dataDir);
    segmentGeneratorConfig.setFormat(_format);
    segmentGeneratorConfig.setOutDir(_outDir);
    segmentGeneratorConfig.setOverwrite(_overwrite);
    segmentGeneratorConfig.setTableName(_tableName);
    segmentGeneratorConfig.setSegmentName(_segmentName);
    if (_schemaFile != null) {
        if (segmentGeneratorConfig.getSchemaFile() != null && !segmentGeneratorConfig.getSchemaFile().equals(_schemaFile)) {
            LOGGER.warn("Find schemaFile conflict in command line and config file, use config in command line: {}", _schemaFile);
        }
        segmentGeneratorConfig.setSchemaFile(_schemaFile);
    }
    if (_readerConfigFile != null) {
        if (segmentGeneratorConfig.getReaderConfigFile() != null && !segmentGeneratorConfig.getReaderConfigFile().equals(_readerConfigFile)) {
            LOGGER.warn("Find readerConfigFile conflict in command line and config file, use config in command line: {}", _readerConfigFile);
        }
        segmentGeneratorConfig.setReaderConfigFile(_readerConfigFile);
    }
    if (_enableStarTreeIndex) {
        segmentGeneratorConfig.setEnableStarTreeIndex(true);
    }
    if (_starTreeIndexSpecFile != null) {
        if (segmentGeneratorConfig.getStarTreeIndexSpecFile() != null && !segmentGeneratorConfig.getStarTreeIndexSpecFile().equals(_starTreeIndexSpecFile)) {
            LOGGER.warn("Find starTreeIndexSpecFile conflict in command line and config file, use config in command line: {}", _starTreeIndexSpecFile);
        }
        segmentGeneratorConfig.setStarTreeIndexSpecFile(_starTreeIndexSpecFile);
    }
    ExecutorService executor = Executors.newFixedThreadPool(_numThreads);
    int cnt = 0;
    for (final File file : files) {
        final int segCnt = cnt;
        executor.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    SegmentGeneratorConfig config = new SegmentGeneratorConfig(segmentGeneratorConfig);
                    config.setInputFilePath(file.getAbsolutePath());
                    config.setSegmentName(_segmentName + "_" + segCnt);
                    config.loadConfigFiles();
                    final SegmentIndexCreationDriverImpl driver = new SegmentIndexCreationDriverImpl();
                    driver.init(config);
                    driver.build();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });
        cnt += 1;
    }
    executor.shutdown();
    return executor.awaitTermination(1, TimeUnit.HOURS);
}
Also used : IOException(java.io.IOException) FileFormat(com.linkedin.pinot.core.data.readers.FileFormat) IOException(java.io.IOException) SegmentIndexCreationDriverImpl(com.linkedin.pinot.core.segment.creator.impl.SegmentIndexCreationDriverImpl) FilenameFilter(java.io.FilenameFilter) SegmentGeneratorConfig(com.linkedin.pinot.core.indexsegment.generator.SegmentGeneratorConfig) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

FilenameFilter (java.io.FilenameFilter)820 File (java.io.File)812 IOException (java.io.IOException)195 ArrayList (java.util.ArrayList)189 Test (org.junit.Test)87 List (java.util.List)47 URL (java.net.URL)45 FileInputStream (java.io.FileInputStream)39 FileNotFoundException (java.io.FileNotFoundException)36 HashMap (java.util.HashMap)34 HashSet (java.util.HashSet)29 FileOutputStream (java.io.FileOutputStream)28 MalformedURLException (java.net.MalformedURLException)28 Pattern (java.util.regex.Pattern)28 RandomAccessFile (java.io.RandomAccessFile)27 JarFile (java.util.jar.JarFile)26 InputStream (java.io.InputStream)23 Map (java.util.Map)23 FileWriter (java.io.FileWriter)20 Properties (java.util.Properties)20