Example usage for java.io File isDirectory

List of usage examples for java.io File isDirectory

Introduction

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

Prototype

public boolean isDirectory() 

Source Link

Document

Tests whether the file denoted by this abstract pathname is a directory.

Usage

From source file:kenh.xscript.ScriptUtils.java

public static void main(String[] args) {
    String file = null;/* w  w w.  j  a va  2 s.  c  o  m*/

    for (String arg : args) {
        if (StringUtils.startsWithAny(StringUtils.lowerCase(arg), "-f:", "-file:")) {
            file = StringUtils.substringAfter(arg, ":");
        }
    }

    Element e = null;
    try {
        if (StringUtils.isBlank(file)) {

            JFileChooser chooser = new JFileChooser();
            chooser.setDialogTitle("xScript");
            chooser.setAcceptAllFileFilterUsed(false);
            chooser.setFileFilter(new FileFilter() {
                public boolean accept(File f) {
                    if (f.isDirectory()) {
                        return true;
                    } else if (f.isFile() && StringUtils.endsWithIgnoreCase(f.getName(), ".xml")) {
                        return true;
                    }
                    return false;
                }

                public String getDescription() {
                    return "xScript (*.xml)";
                }
            });

            int returnVal = chooser.showOpenDialog(null);
            chooser.requestFocus();

            if (returnVal == JFileChooser.CANCEL_OPTION)
                return;

            File f = chooser.getSelectedFile();

            e = getInstance(f, null);
        } else {
            e = getInstance(new File(file), null);
        }
        //debug(e);
        //System.out.println("----------------------");

        int result = e.invoke();
        if (result == Element.EXCEPTION) {
            Object obj = e.getEnvironment().getVariable(Constant.VARIABLE_EXCEPTION);
            if (obj != null && obj instanceof Throwable) {
                System.err.println();
                ((Throwable) obj).printStackTrace();

            } else {
                System.err.println();
                System.err.println("Unknown EXCEPTION is thrown.");
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();

        System.err.println();

        if (ex instanceof UnsupportedScriptException) {
            UnsupportedScriptException ex_ = (UnsupportedScriptException) ex;
            if (ex_.getElement() != null) {
                debug(ex_.getElement(), System.err);
            }
        }
    } finally {
        if (e != null)
            e.getEnvironment().callback();
    }
}

From source file:com.linkedin.pinot.integration.tests.HybridClusterIntegrationTestCommandLineRunner.java

public static void main(String[] args) throws Exception {
    int numArgs = args.length;
    if (!((numArgs == 5) || (numArgs == 6 && args[0].equals("--llc")))) {
        printUsage();/*from  ww w  . j  a va 2 s .co  m*/
    }

    CustomHybridClusterIntegrationTest._enabled = true;

    int argIdx = 0;
    if (args[0].equals("--llc")) {
        CustomHybridClusterIntegrationTest._useLlc = true;
        argIdx++;
    }

    CustomHybridClusterIntegrationTest._tableName = args[argIdx++];
    File schemaFile = new File(args[argIdx++]);
    Preconditions.checkState(schemaFile.isFile());
    CustomHybridClusterIntegrationTest._schemaFile = schemaFile;
    File dataDir = new File(args[argIdx++]);
    Preconditions.checkState(dataDir.isDirectory());
    CustomHybridClusterIntegrationTest._dataDir = dataDir;
    CustomHybridClusterIntegrationTest._invertedIndexColumns = Arrays.asList(args[argIdx++].split(","));
    CustomHybridClusterIntegrationTest._sortedColumn = args[argIdx];

    TestListenerAdapter testListenerAdapter = new TestListenerAdapter();
    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[] { CustomHybridClusterIntegrationTest.class });
    testNG.addListener(testListenerAdapter);
    testNG.run();

    System.out.println(testListenerAdapter.toString());
    boolean success = true;
    List<ITestResult> skippedTests = testListenerAdapter.getSkippedTests();
    if (!skippedTests.isEmpty()) {
        System.out.println("Skipped tests: " + skippedTests);
        for (ITestResult skippedTest : skippedTests) {
            System.out.println(skippedTest.getName() + ": " + skippedTest.getThrowable());
        }
        success = false;
    }
    List<ITestResult> failedTests = testListenerAdapter.getFailedTests();
    if (!failedTests.isEmpty()) {
        System.err.println("Failed tests: " + failedTests);
        for (ITestResult failedTest : failedTests) {
            System.out.println(failedTest.getName() + ": " + failedTest.getThrowable());
        }
        success = false;
    }
    if (success) {
        System.exit(0);
    } else {
        System.exit(1);
    }
}

From source file:io.s4.MainApp.java

public static void main(String args[]) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c"));

    options.addOption(/*w  w w  .j a  v a2 s.  co  m*/
            OptionBuilder.withArgName("appshome").hasArg().withDescription("applications home").create("a"));

    options.addOption(OptionBuilder.withArgName("s4clock").hasArg().withDescription("s4 clock").create("d"));

    options.addOption(OptionBuilder.withArgName("seedtime").hasArg()
            .withDescription("event clock initialization time").create("s"));

    options.addOption(
            OptionBuilder.withArgName("extshome").hasArg().withDescription("extensions home").create("e"));

    options.addOption(
            OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i"));

    options.addOption(
            OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t"));

    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = null;
    String clockType = "wall";

    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException pe) {
        System.err.println(pe.getLocalizedMessage());
        System.exit(1);
    }

    int instanceId = -1;
    if (commandLine.hasOption("i")) {
        String instanceIdStr = commandLine.getOptionValue("i");
        try {
            instanceId = Integer.parseInt(instanceIdStr);
        } catch (NumberFormatException nfe) {
            System.err.println("Bad instance id: %s" + instanceIdStr);
            System.exit(1);
        }
    }

    if (commandLine.hasOption("c")) {
        coreHome = commandLine.getOptionValue("c");
    }

    if (commandLine.hasOption("a")) {
        appsHome = commandLine.getOptionValue("a");
    }

    if (commandLine.hasOption("d")) {
        clockType = commandLine.getOptionValue("d");
    }

    if (commandLine.hasOption("e")) {
        extsHome = commandLine.getOptionValue("e");
    }

    String configType = "typical";
    if (commandLine.hasOption("t")) {
        configType = commandLine.getOptionValue("t");
    }

    long seedTime = 0;
    if (commandLine.hasOption("s")) {
        seedTime = Long.parseLong(commandLine.getOptionValue("s"));
    }

    File coreHomeFile = new File(coreHome);
    if (!coreHomeFile.isDirectory()) {
        System.err.println("Bad core home: " + coreHome);
        System.exit(1);
    }

    File appsHomeFile = new File(appsHome);
    if (!appsHomeFile.isDirectory()) {
        System.err.println("Bad applications home: " + appsHome);
        System.exit(1);
    }

    if (instanceId > -1) {
        System.setProperty("instanceId", "" + instanceId);
    } else {
        System.setProperty("instanceId", "" + S4Util.getPID());
    }

    List loArgs = commandLine.getArgList();

    if (loArgs.size() < 1) {
        // System.err.println("No bean configuration file specified");
        // System.exit(1);
    }

    // String s4ConfigXml = (String) loArgs.get(0);
    // System.out.println("s4ConfigXml is " + s4ConfigXml);

    ClassPathResource propResource = new ClassPathResource("s4-core.properties");
    Properties prop = new Properties();
    if (propResource.exists()) {
        prop.load(propResource.getInputStream());
    } else {
        System.err.println("Unable to find s4-core.properties. It must be available in classpath");
        System.exit(1);
    }

    ApplicationContext coreContext = null;
    String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType;
    String configPath = "";
    List<String> coreConfigUrls = new ArrayList<String>();
    File configFile = null;

    // load clock configuration
    configPath = configBase + File.separatorChar + clockType + "-clock.xml";
    coreConfigUrls.add(configPath);

    // load core config xml
    configPath = configBase + File.separatorChar + "s4-core-conf.xml";
    configFile = new File(configPath);
    if (!configFile.exists()) {
        System.err.printf("S4 core config file %s does not exist\n", configPath);
        System.exit(1);
    }

    coreConfigUrls.add(configPath);
    String[] coreConfigFiles = new String[coreConfigUrls.size()];
    coreConfigUrls.toArray(coreConfigFiles);

    String[] coreConfigFileUrls = new String[coreConfigFiles.length];
    for (int i = 0; i < coreConfigFiles.length; i++) {
        coreConfigFileUrls[i] = "file:" + coreConfigFiles[i];
    }

    coreContext = new FileSystemXmlApplicationContext(coreConfigFileUrls, coreContext);
    ApplicationContext context = coreContext;

    Clock s4Clock = (Clock) context.getBean("clock");
    if (s4Clock instanceof EventClock && seedTime > 0) {
        EventClock s4EventClock = (EventClock) s4Clock;
        s4EventClock.updateTime(seedTime);
        System.out.println("Intializing event clock time with seed time " + s4EventClock.getCurrentTime());
    }

    PEContainer peContainer = (PEContainer) context.getBean("peContainer");

    Watcher w = (Watcher) context.getBean("watcher");
    w.setConfigFilename(configPath);

    // load extension modules
    String[] configFileNames = getModuleConfigFiles(extsHome, prop);
    if (configFileNames.length > 0) {
        String[] configFileUrls = new String[configFileNames.length];
        for (int i = 0; i < configFileNames.length; i++) {
            configFileUrls[i] = "file:" + configFileNames[i];
        }
        context = new FileSystemXmlApplicationContext(configFileUrls, context);
    }

    // load application modules
    configFileNames = getModuleConfigFiles(appsHome, prop);
    if (configFileNames.length > 0) {
        String[] configFileUrls = new String[configFileNames.length];
        for (int i = 0; i < configFileNames.length; i++) {
            configFileUrls[i] = "file:" + configFileNames[i];
        }
        context = new FileSystemXmlApplicationContext(configFileUrls, context);
        // attach any beans that implement ProcessingElement to the PE
        // Container
        String[] processingElementBeanNames = context.getBeanNamesForType(ProcessingElement.class);
        for (String processingElementBeanName : processingElementBeanNames) {
            Object bean = context.getBean(processingElementBeanName);
            try {
                Method getS4ClockMethod = bean.getClass().getMethod("getS4Clock");

                if (getS4ClockMethod.getReturnType().equals(Clock.class)) {
                    if (getS4ClockMethod.invoke(bean) == null) {
                        Method setS4ClockMethod = bean.getClass().getMethod("setS4Clock", Clock.class);
                        setS4ClockMethod.invoke(bean, coreContext.getBean("clock"));
                    }
                }
            } catch (NoSuchMethodException mnfe) {
                // acceptable
            }
            System.out.println("Adding processing element with bean name " + processingElementBeanName + ", id "
                    + ((ProcessingElement) bean).getId());
            peContainer.addProcessor((ProcessingElement) bean, processingElementBeanName);
        }
    }
}

From source file:org.apache.s4.MainApp.java

public static void main(String args[]) throws Exception {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c"));

    options.addOption(/*ww w  . j  a  va 2s.  co m*/
            OptionBuilder.withArgName("appshome").hasArg().withDescription("applications home").create("a"));

    options.addOption(OptionBuilder.withArgName("s4clock").hasArg().withDescription("s4 clock").create("d"));

    options.addOption(OptionBuilder.withArgName("seedtime").hasArg()
            .withDescription("event clock initialization time").create("s"));

    options.addOption(
            OptionBuilder.withArgName("extshome").hasArg().withDescription("extensions home").create("e"));

    options.addOption(
            OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i"));

    options.addOption(
            OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t"));

    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = null;
    String clockType = "wall";

    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException pe) {
        System.err.println(pe.getLocalizedMessage());
        System.exit(1);
    }

    int instanceId = -1;
    if (commandLine.hasOption("i")) {
        String instanceIdStr = commandLine.getOptionValue("i");
        try {
            instanceId = Integer.parseInt(instanceIdStr);
        } catch (NumberFormatException nfe) {
            System.err.println("Bad instance id: %s" + instanceIdStr);
            System.exit(1);
        }
    }

    if (commandLine.hasOption("c")) {
        coreHome = commandLine.getOptionValue("c");
    }

    if (commandLine.hasOption("a")) {
        appsHome = commandLine.getOptionValue("a");
    }

    if (commandLine.hasOption("d")) {
        clockType = commandLine.getOptionValue("d");
    }

    if (commandLine.hasOption("e")) {
        extsHome = commandLine.getOptionValue("e");
    }

    String configType = "typical";
    if (commandLine.hasOption("t")) {
        configType = commandLine.getOptionValue("t");
    }

    long seedTime = 0;
    if (commandLine.hasOption("s")) {
        seedTime = Long.parseLong(commandLine.getOptionValue("s"));
    }

    File coreHomeFile = new File(coreHome);
    if (!coreHomeFile.isDirectory()) {
        System.err.println("Bad core home: " + coreHome);
        System.exit(1);
    }

    File appsHomeFile = new File(appsHome);
    if (!appsHomeFile.isDirectory()) {
        System.err.println("Bad applications home: " + appsHome);
        System.exit(1);
    }

    if (instanceId > -1) {
        System.setProperty("instanceId", "" + instanceId);
    } else {
        System.setProperty("instanceId", "" + S4Util.getPID());
    }

    List loArgs = commandLine.getArgList();

    if (loArgs.size() < 1) {
        // System.err.println("No bean configuration file specified");
        // System.exit(1);
    }

    // String s4ConfigXml = (String) loArgs.get(0);
    // System.out.println("s4ConfigXml is " + s4ConfigXml);

    ClassPathResource propResource = new ClassPathResource("s4-core.properties");
    Properties prop = new Properties();
    if (propResource.exists()) {
        prop.load(propResource.getInputStream());
    } else {
        System.err.println("Unable to find s4-core.properties. It must be available in classpath");
        System.exit(1);
    }

    ApplicationContext coreContext = null;
    String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType;
    String configPath = "";
    List<String> coreConfigUrls = new ArrayList<String>();
    File configFile = null;

    // load clock configuration
    configPath = configBase + File.separatorChar + clockType + "-clock.xml";
    coreConfigUrls.add(configPath);

    // load core config xml
    configPath = configBase + File.separatorChar + "s4-core-conf.xml";
    configFile = new File(configPath);
    if (!configFile.exists()) {
        System.err.printf("S4 core config file %s does not exist\n", configPath);
        System.exit(1);
    }

    coreConfigUrls.add(configPath);
    String[] coreConfigFiles = new String[coreConfigUrls.size()];
    coreConfigUrls.toArray(coreConfigFiles);

    String[] coreConfigFileUrls = new String[coreConfigFiles.length];
    for (int i = 0; i < coreConfigFiles.length; i++) {
        coreConfigFileUrls[i] = "file:" + coreConfigFiles[i];
    }

    coreContext = new FileSystemXmlApplicationContext(coreConfigFileUrls, coreContext);
    ApplicationContext context = coreContext;

    Clock clock = (Clock) context.getBean("clock");
    if (clock instanceof EventClock && seedTime > 0) {
        EventClock s4EventClock = (EventClock) clock;
        s4EventClock.updateTime(seedTime);
        System.out.println("Intializing event clock time with seed time " + s4EventClock.getCurrentTime());
    }

    PEContainer peContainer = (PEContainer) context.getBean("peContainer");

    Watcher w = (Watcher) context.getBean("watcher");
    w.setConfigFilename(configPath);

    // load extension modules
    String[] configFileNames = getModuleConfigFiles(extsHome, prop);
    if (configFileNames.length > 0) {
        String[] configFileUrls = new String[configFileNames.length];
        for (int i = 0; i < configFileNames.length; i++) {
            configFileUrls[i] = "file:" + configFileNames[i];
        }
        context = new FileSystemXmlApplicationContext(configFileUrls, context);
    }

    // load application modules
    configFileNames = getModuleConfigFiles(appsHome, prop);
    if (configFileNames.length > 0) {
        String[] configFileUrls = new String[configFileNames.length];
        for (int i = 0; i < configFileNames.length; i++) {
            configFileUrls[i] = "file:" + configFileNames[i];
        }
        context = new FileSystemXmlApplicationContext(configFileUrls, context);
        // attach any beans that implement ProcessingElement to the PE
        // Container
        String[] processingElementBeanNames = context.getBeanNamesForType(AbstractPE.class);
        for (String processingElementBeanName : processingElementBeanNames) {
            AbstractPE bean = (AbstractPE) context.getBean(processingElementBeanName);
            bean.setClock(clock);
            try {
                bean.setSafeKeeper((SafeKeeper) context.getBean("safeKeeper"));
            } catch (NoSuchBeanDefinitionException ignored) {
                // no safe keeper = no checkpointing / recovery
            }
            // if the application did not specify an id, use the Spring bean name
            if (bean.getId() == null) {
                bean.setId(processingElementBeanName);
            }
            System.out.println("Adding processing element with bean name " + processingElementBeanName + ", id "
                    + ((AbstractPE) bean).getId());
            peContainer.addProcessor((AbstractPE) bean);
        }
    }
}

From source file:com.justgiving.raven.kissmetrics.utils.KissmetricsRowParser.java

public static void main(String[] args) throws FileNotFoundException, IOException {
    for (String s : args) {
        System.out.println(s);//from  w w w.  j  a  v  a  2s.c  o m
    }

    String inputFile = "D:\\datasets\\kissmetrics\\input\\2250.json";
    String outputFile = "D:\\datasets\\kissmetrics\\output\\2250.json";
    // String inputFile ="D:\\datasets\\kissmetrics\\input\\";
    //String inputFile = "D:\\datasets\\kissmetrics\\input5\\";
    //String outputFile = "D:\\datasets\\kissmetrics\\output5\\";

    if (args.length == 2) {
        try {
            inputFile = args[0];
            outputFile = args[1];
        } catch (Exception e) {
            System.err.println(
                    "Error unable to extract arguments, valid arguments are inputFilePath inputFilePath");
            System.exit(1);
        }
    } else if (args == null || args.length == 0) {
        logger.info("using defaul values for inputFile=" + inputFile + " outputFile=" + outputFile);
    }

    String logConfigPath = Paths.get(System.getProperty("user.dir"), "log4j.properties").toString();

    File f = new File(logConfigPath);
    if (f.exists() && !f.isDirectory()) {
        System.out.println("log config file used: " + logConfigPath);
        PropertyConfigurator.configure(logConfigPath);
        logger.info("log config file used: " + logConfigPath);
    } else {
        System.out.println(
                "no log file detected, please copy the log4j.properties to the same folder as the JAR");
    }

    if (inputFile.endsWith("\\")) {
        logger.info("Detected folder");
        processFolder(inputFile, outputFile);
    } else {
        logger.info("Detected file");
        runonfileValidJson(inputFile, outputFile);
    }
}

From source file:scalespace.filter.Gaussian_Derivative_.java

public static void main(String[] args) {

    try {// w ww  . ja va  2 s . c  o  m

        File f = new File(args[0]);

        if (f.exists() && f.isDirectory()) {
            System.setProperty("plugins.dir", args[0]);
            new ImageJ();
        } else {
            throw new IllegalArgumentException();
        }
    } catch (Exception ex) {
        IJ.log("plugins.dir misspecified\n");
        ex.printStackTrace();
    }

}

From source file:com.sangupta.snowpack.SnowpackRecover.java

public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println(/*from   ww w .  j a v  a2s.co  m*/
                "Usage: java -classpath snowpack.jar com.sangupta.snowpack.SnowpackRecover <base-folder>");
        return;
    }

    File base = new File(args[0]);
    if (!base.exists()) {
        System.out.println("Base folder does not exists.");
        return;
    }

    if (!base.isDirectory()) {
        System.out.println("Base folder does not represent a valid directory on disk.");
        return;
    }

    long start = System.currentTimeMillis();
    recover(base);
    long end = System.currentTimeMillis();

    System.out.println("Recovery process complete in " + (end - start) + "ms.");
}

From source file:com.ms.commons.test.tool.GenerateTestCase.java

public static void main(String[] args) {
    if (args.length < 2) {
        System.err.println("Usage:\r\n.frameworktest_maketests antx|maven fileter");
        System.exit(-1);// w w  w  . ja  v  a 2  s  .com
    }

    final com.ms.commons.test.runner.filter.expression.internal.Expression filterExpression;
    try {
        System.out.println("Filter: " + args[1]);
        filterExpression = ExpressionParseUtil.parse(args[1], new SimpleExpressionBuiler() {

            public AbstractSimpleExpression build(String value) {
                return new StringExpressionImpl(value);
            }
        });
    } catch (ParseException e) {
        throw ExceptionUtil.wrapToRuntimeException(e);
    }
    final FullClassNameFilter fullClassNameFilter = new FullClassNameFilter() {

        public boolean accept(String fullClassName) {

            return ((Boolean) filterExpression.evaluate(fullClassName)).booleanValue();
        }
    };

    String userDir = System.getProperty("user.dir");

    ProjectPath pp = getProjectPath(args[0]);

    final String mainSource = userDir + File.separator + pp.getMainSource();
    final String testSource = userDir + File.separator + pp.getTestSource();

    FileUtil.listFiles(null, new File(mainSource), new FileFilter() {

        public boolean accept(File pathname) {
            if (pathname.isDirectory()) {
                return !pathname.toString().contains(".svn");
            }
            if (pathname.toString().contains(".svn")) {
                return false;
            }
            if (!pathname.toString().toLowerCase().endsWith(".java")) {
                return false;
            }
            try {
                processJavaFile(pathname, testSource, fullClassNameFilter);
            } catch (Exception e) {
                System.err.println("Parse java file failed:" + pathname);
                e.printStackTrace();
            }
            return false;
        }
    });
}

From source file:com.trailmagic.image.util.ImagesParserImpl.java

public static final void main(String[] args) {
    File baseDir = new File(args[0]);
    if (!baseDir.isDirectory()) {
        printUsage();//from  w w w.j a  v a2s. c o m
        System.exit(1);
    }

    File metadataFile = new File(baseDir, METADATA_FILENAME);
    if (!metadataFile.isFile()) {
        s_logger.error("Error: Couldn't find " + baseDir + File.separator + METADATA_FILENAME);
        System.exit(1);
    }

    s_logger.info("Starting context...");

    ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {
            "applicationContext-global.xml", "applicationContext-user.xml", "applicationContext-imagestore.xml",
            "applicationContext-imagestore-authorization.xml", "applicationContext-standalone.xml" });
    ImagesParser handler = (ImagesParser) appContext.getBean("imagesParser");

    s_logger.info("Beginning parse.");

    try {
        handler.parseFile(baseDir, metadataFile);
        s_logger.info("Parse completed.");
    } catch (Throwable t) {
        s_logger.error("Parse Failed!", t);
    }

    System.exit(0);
}

From source file:com.zimbra.cs.redolog.util.RedoLogVerify.java

public static void main(String[] cmdlineargs) {
    CliUtil.toolSetup();/*  w ww. j a  va  2s. c  om*/
    CommandLine cl = parseArgs(cmdlineargs);
    Params params = initParams(cl);
    if (params.help)
        usage(null);

    String[] args = cl.getArgs();

    if (args.length < 1)
        usage("No redolog file/directory list specified");

    boolean allGood = true;
    RedoLogVerify verify = new RedoLogVerify(params, System.out);

    for (int i = 0; i < args.length; i++) {
        File f = new File(args[i]);
        boolean good = false;
        if (f.isDirectory())
            good = verify.verifyDirectory(f);
        else
            good = verify.verifyFile(f);
        allGood = allGood && good;
    }

    if (!allGood) {
        verify.listErrors();
        System.exit(1);
    }
}