Example usage for java.io File list

List of usage examples for java.io File list

Introduction

In this page you can find the example usage for java.io File list.

Prototype

public String[] list(FilenameFilter filter) 

Source Link

Document

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.

Usage

From source file:com.linkedin.pinot.perf.FilterOperatorBenchmark.java

public static void main(String[] args) throws Exception {
    String rootDir = args[0];/*from  w w  w .ja va 2 s .  c  o  m*/
    File[] segmentDirs = new File(rootDir).listFiles();
    String query = args[1];
    AtomicInteger totalDocsMatched = new AtomicInteger(0);
    Pql2Compiler pql2Compiler = new Pql2Compiler();
    BrokerRequest brokerRequest = pql2Compiler.compileToBrokerRequest(query);
    List<Callable<Void>> segmentProcessors = new ArrayList<>();
    long[] timesSpent = new long[segmentDirs.length];
    for (int i = 0; i < segmentDirs.length; i++) {
        File indexSegmentDir = segmentDirs[i];
        System.out.println("Loading " + indexSegmentDir.getName());
        Configuration tableDataManagerConfig = new PropertiesConfiguration();
        List<String> invertedColumns = new ArrayList<>();
        FilenameFilter filter = new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".bitmap.inv");
            }
        };
        String[] indexFiles = indexSegmentDir.list(filter);
        for (String indexFileName : indexFiles) {
            invertedColumns.add(indexFileName.replace(".bitmap.inv", ""));
        }
        tableDataManagerConfig.setProperty(IndexLoadingConfigMetadata.KEY_OF_LOADING_INVERTED_INDEX,
                invertedColumns);
        IndexLoadingConfigMetadata indexLoadingConfigMetadata = new IndexLoadingConfigMetadata(
                tableDataManagerConfig);
        IndexSegmentImpl indexSegmentImpl = (IndexSegmentImpl) Loaders.IndexSegment.load(indexSegmentDir,
                ReadMode.heap, indexLoadingConfigMetadata);
        segmentProcessors
                .add(new SegmentProcessor(i, indexSegmentImpl, brokerRequest, totalDocsMatched, timesSpent));
    }
    ExecutorService executorService = Executors.newCachedThreadPool();
    for (int run = 0; run < 5; run++) {
        System.out.println("START RUN:" + run);
        totalDocsMatched.set(0);
        long start = System.currentTimeMillis();
        List<Future<Void>> futures = executorService.invokeAll(segmentProcessors);
        for (int i = 0; i < futures.size(); i++) {
            futures.get(i).get();
        }
        long end = System.currentTimeMillis();
        System.out.println("Total docs matched:" + totalDocsMatched + " took:" + (end - start));
        System.out.println("Times spent:" + Arrays.toString(timesSpent));
        System.out.println("END RUN:" + run);
    }
    System.exit(0);
}

From source file:org.biopax.validator.BiopaxValidatorClient.java

/**
 * Checks BioPAX files using the online BioPAX Validator. 
 * //w ww  .j a va 2s.  c o m
 * @see <a href="http://www.biopax.org/validator">BioPAX Validator Webservice</a>
 * 
 * @param argv
 * @throws IOException
 */
public static void main(String[] argv) throws IOException {
    if (argv.length == 0) {
        System.err.println("Available parameters: \n"
                + "<path> <output> [xml|html|biopax] [auto-fix] [only-errors] [maxerrors=n] [notstrict]\n"
                + "\t- validate a BioPAX file/directory (up to ~25MB in total size, -\n"
                + "\totherwise, please use the biopax-validator.jar instead)\n"
                + "\tin the directory using the online BioPAX Validator service\n"
                + "\t(generates html or xml report, or gets the processed biopax\n"
                + "\t(cannot fix all errros though) see http://www.biopax.org/validator)");
        System.exit(-1);
    }

    final String input = argv[0];
    final String output = argv[1];

    File fileOrDir = new File(input);
    if (!fileOrDir.canRead()) {
        System.err.println("Cannot read from " + input);
        System.exit(-1);
    }
    if (output == null || output.isEmpty()) {
        System.err.println("No output file specified (for the validation report).");
        System.exit(-1);
    }

    // default options
    RetFormat outf = RetFormat.HTML;
    boolean fix = false;
    Integer maxErrs = null;
    Behavior level = null; //will report both errors and warnings
    String profile = null;

    // match optional arguments
    for (int i = 2; i < argv.length; i++) {
        if ("html".equalsIgnoreCase(argv[i])) {
            outf = RetFormat.HTML;
        } else if ("xml".equalsIgnoreCase(argv[i])) {
            outf = RetFormat.XML;
        } else if ("biopax".equalsIgnoreCase(argv[i])) {
            outf = RetFormat.OWL;
        } else if ("auto-fix".equalsIgnoreCase(argv[i])) {
            fix = true;
        } else if ("only-errors".equalsIgnoreCase(argv[i])) {
            level = Behavior.ERROR;
        } else if ((argv[i]).toLowerCase().startsWith("maxerrors=")) {
            String num = argv[i].substring(10);
            maxErrs = Integer.valueOf(num);
        } else if ("notstrict".equalsIgnoreCase(argv[i])) {
            profile = "notstrict";
        }
    }

    // collect files
    Collection<File> files = new HashSet<File>();

    if (fileOrDir.isDirectory()) {
        // validate all the OWL files in the folder
        FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return (name.endsWith(".owl"));
            }
        };

        for (String s : fileOrDir.list(filter)) {
            files.add(new File(fileOrDir.getCanonicalPath() + File.separator + s));
        }
    } else {
        files.add(fileOrDir);
    }

    // upload and validate using the default URL: http://www.biopax.org/biopax-validator/check.html        
    if (!files.isEmpty()) {
        BiopaxValidatorClient val = new BiopaxValidatorClient();
        val.validate(fix, profile, outf, level, maxErrs, null, files.toArray(new File[] {}),
                new FileOutputStream(output));
    }
}

From source file:de.uniwue.dmir.heatmap.EntryPointIncremental.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) throws IOException, ParseException {

    DateFormat df = new SimpleDateFormat(DATE_FORMAT);
    SimpleDateFormat backupDf = new SimpleDateFormat(BACKUP_DATE_FORMAT);

    String workDir = System.getProperty("workDir", ".");
    LOGGER.debug("Work dir: {}", workDir);
    String configDir = System.getProperty("configDir", ".");
    LOGGER.debug("Config dir: {}", configDir);

    File seedDir = new File(workDir, SEED_DIR);
    LOGGER.debug("Seed dir: {}", seedDir);
    File currentDir = new File(workDir, CURRENT_DIR);
    LOGGER.debug("Current dir: {}", currentDir);
    File backupDir = new File(workDir, BACKUP_DIR);
    LOGGER.debug("Backup dir: {}", backupDir);

    String initialMinTimeString = System.getProperty("minTime");
    LOGGER.debug("Initial minimal time parameter: {}", initialMinTimeString);
    Date initialMinTime = initialMinTimeString == null ? new Date(0) : df.parse(initialMinTimeString);
    LOGGER.debug("Initial minimal time: {}", df.format(initialMinTime));

    String absoluteMaxTimeString = System.getProperty("maxTime");
    LOGGER.debug("Absolute maximal time parameter: {}", absoluteMaxTimeString);
    Date absoluteMaxTime = absoluteMaxTimeString == null ? new Date()
            : new SimpleDateFormat(DATE_FORMAT).parse(absoluteMaxTimeString);
    LOGGER.debug("Absolute maximal time: {}", df.format(absoluteMaxTime));

    String incrementalFile = new File("file:" + configDir, INCREMENTAL_FILE).getPath();
    String settingsFile = new File("file:" + configDir, HEATMAP_PROCESSOR__FILE).getPath();

    LOGGER.debug("Initializing incremental control file: {}", incrementalFile);
    FileSystemXmlApplicationContext incrementalContext = new FileSystemXmlApplicationContext(incrementalFile);

    // get point limit
    int pointLimit = Integer
            .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${point.limit}"));
    LOGGER.debug("Print limit: {}", pointLimit);

    // get backups to keep
    int backupsToKeep = Integer
            .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${backups.to.keep}"));
    LOGGER.debug("Backups to keep: {}", pointLimit);

    LOGGER.debug("Initializing process components (manager and limiter).");
    IProcessManager processManager = incrementalContext.getBean(IProcessManager.class);
    IProcessLimiter processLimiter = incrementalContext.getBean(IProcessLimiter.class);

    LOGGER.debug("Starting incremental loop.");
    while (true) { // break as soon as no new points are available

        // cleanup --- just in case
        LOGGER.debug("Deleting \"current\" dir.");
        FileUtils.deleteDirectory(currentDir);

        // copy from seed to current
        LOGGER.debug("Copying seed.");
        seedDir.mkdirs();/*from   w w  w .j  av a  2 s .c o m*/
        FileUtils.copyDirectory(seedDir, currentDir);

        // get min time
        LOGGER.debug("Getting minimal time ...");
        Date minTime = initialMinTime;
        ProcessManagerEntry entry = processManager.getEntry();
        if (entry != null && entry.getMaxTime() != null) {
            minTime = entry.getMaxTime();
        }
        LOGGER.debug("Minimal time: {}", new SimpleDateFormat(DATE_FORMAT).format(minTime));

        // break if we processed all available points (minTime is greater than or equal to absoluteMaxTime)
        if (minTime.getTime() >= absoluteMaxTime.getTime()) {
            LOGGER.debug("Processed all points.");
            break;
        }

        // get the maximal time
        LOGGER.debug("Get maximal time.");

        // get the time from the newest point in our point range (pointMaxTime) ...
        Date pointMaxTime = processLimiter.getMaxTime(minTime, pointLimit);

        // ... and possibly break the loop if no new points are available
        if (pointMaxTime == null)
            break;

        // set the max time and make sure we are not taking to many points 
        // (set max time to the minimum of pointMaxTime and absoluteMaxTime)
        Date maxTime = pointMaxTime.getTime() > absoluteMaxTime.getTime() ? absoluteMaxTime : pointMaxTime;

        LOGGER.debug("Maximal time: {}", new SimpleDateFormat(DATE_FORMAT).format(maxTime));

        // start process
        processManager.start(minTime);

        System.setProperty("minTimestamp", new SimpleDateFormat(DATE_FORMAT).format(minTime));

        System.setProperty("maxTimestamp", new SimpleDateFormat(DATE_FORMAT).format(maxTime));

        FileSystemXmlApplicationContext heatmapContext = new FileSystemXmlApplicationContext(settingsFile);

        IHeatmap heatmap = heatmapContext.getBean(HEATMAP_BEAN, IHeatmap.class);

        ITileProcessor tileProcessor = heatmapContext.getBean(WRITER_BEAN, ITileProcessor.class);

        heatmap.processTiles(tileProcessor);

        tileProcessor.close();
        heatmapContext.close();

        // finish process
        processManager.finish(maxTime);

        // move old seed
        if (backupsToKeep > 0) {
            FileUtils.moveDirectory(seedDir, new File(backupDir, backupDf.format(minTime))); // minTime is the maxTime of the seed

            // cleanup backups
            String[] backups = backupDir.list(DirectoryFileFilter.DIRECTORY);
            File oldestBackup = null;
            if (backups.length > backupsToKeep) {
                for (String bs : backups) {
                    File b = new File(backupDir, bs);
                    if (oldestBackup == null || oldestBackup.lastModified() > b.lastModified()) {
                        oldestBackup = b;
                    }
                }
                FileUtils.deleteDirectory(oldestBackup);
            }

        } else {
            FileUtils.deleteDirectory(seedDir);
        }

        // move new seed
        FileUtils.moveDirectory(currentDir, seedDir);

    }

    incrementalContext.close();

}

From source file:Main.java

/**
 * Returns album IDs containing at least one cached track.
 * @return Albums IDs// w ww  . j av  a2s.  c om
 */
public static Set<String> getCachedAlbumSet() {
    File cacheDir = getMusicCacheDir();
    File[] albumList = cacheDir.listFiles();
    Set<String> output = new HashSet<>();
    for (File album : albumList) {
        if (album.list(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String filename) {
                return filename.endsWith(".complete");
            }
        }).length > 0) {
            output.add(album.getName());
        }
    }
    return output;
}

From source file:ee.ria.xroad.asyncdb.AsyncDBUtil.java

/**
 * Returns all the directories under current directory that are not hidden.
 * @param file - directory under which to look for subdirectories
 * @return - list of directory names//from www  .  j a  v  a  2  s.c o  m
 */
public static String[] getDirectoriesList(File file) {
    return file.list((dir, name) -> new File(dir, name).isDirectory() && !name.startsWith("."));
}

From source file:it.polimi.diceH2020.launcher.FileService.java

public static String[] listFile(String folder, String ext) {

    GenericExtFilter filter = new GenericExtFilter(ext);
    File dirInput = new File(folder);

    String[] list = dirInput.list(filter);

    return list;/*w w  w . ja v  a2 s .co m*/
}

From source file:com.jkoolcloud.tnt4j.streams.utils.ZorkaAttach.java

/**
 * Entry point for loading Zorka as java agent.
 *
 * @param zorkaHomePath/* w  w  w.ja  va  2  s  .  c o m*/
 *            Zorka home dir path
 * @param inst
 *            JVM instrumentation
 * @throws Exception
 *             if exception occurs while loading java agent
 *
 * @see AgentMain#premain(String, Instrumentation)
 */
public static void agentmain(final String zorkaHomePath, final Instrumentation inst) throws Exception {
    final String zorkaDirPath = new File(zorkaHomePath).getAbsolutePath();
    System.setProperty("zorka.home.dir", zorkaDirPath);
    LOGGER.log(OpLevel.DEBUG,
            StreamsResources.getString(ZorkaConstants.RESOURCE_BUNDLE_NAME, "ZorkaAttach.zorka.path"),
            zorkaDirPath);

    File zorkaPath = new File(zorkaDirPath);
    final String[] classPathEntries = zorkaPath.list(new WildcardFileFilter("*.jar")); // NON-NLS
    if (classPathEntries != null) {
        for (String classPathEntry : classPathEntries) {
            File pathFile = new File(classPathEntry);
            extendClasspath(pathFile.toURI().toURL());
        }
    }
    AgentMain.premain(null, inst);
}

From source file:docbook.ArticleRoundTripTest.java

private static TestSuite listCases(File dir) {
    TestSuite cases = new TestSuite(dir.getName());
    String[] testFiles = dir.list(new FilenameFilter() {
        public boolean accept(File file, String filename) {
            return !filename.startsWith(".") && filename.endsWith(".docbook");
        }//  w w w .  j a va  2s.  c om
    });
    Arrays.sort(testFiles);
    for (String filename : testFiles) {
        File f = new File(dir, filename);
        if (f.isDirectory()) {
            cases.addTest(listCases(f));
        } else {
            String name = f.getAbsolutePath();
            if (f.getPath().startsWith(testDir.getPath() + '/')) {
                name = f.getPath().substring(testDir.getPath().length() + 1);
            }
            cases.addTest(new ArticleRoundTripTest(name));
        }
    }
    return cases;
}

From source file:Main.java

public static String prepareFilePathForVideoSaveWithDraftUri(Uri draftUri) {
    String draftPath = draftUri.getPath();
    String draftMediaDirPath = draftPath.substring(0, draftPath.length() - 5);
    File draftMediaDir = new File(draftMediaDirPath);
    if (!draftMediaDir.exists()) {
        draftMediaDir.mkdirs();//from   w  w w .  j a v a2 s. com
    }
    String[] files = draftMediaDir.list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String filename) {
            return filename.endsWith("-0.mp4") || filename.endsWith("-a.mp4");
        }
    });
    List<String> filePaths = Arrays.asList(files);
    Collections.sort(filePaths, new Comparator<String>() {
        @Override
        public int compare(String lhs, String rhs) {
            return rhs.compareTo(lhs);
        }
    });
    if (filePaths.size() > 0) {
        for (String file : filePaths) {
            return new File(draftMediaDir, file.substring(0, file.length() - 6) + ".mp4").getAbsolutePath();
        }
    }
    return new File(draftMediaDir, generateRandomFilename("mp4")).getAbsolutePath();
}

From source file:Main.java

public static String[] listNarDir() {
    File narDir = new File(Environment.getExternalStorageDirectory(), "nar");
    if (narDir.exists() == false || narDir.isDirectory() == false)
        return null;

    String[] ret = narDir.list(narFilter);
    return ret;/*w  w  w  .  j a v a  2 s. c om*/
}