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:languageTools.Analyzer.java

/**
 *
 * @param args/*from  w  w w .  j  a  v  a  2s  .co  m*/
 * @throws Exception
 */
public static void main(String[] args) {

    // Get start time.
    long startTime = System.nanoTime();

    // Parse command line options
    File file;
    try {
        file = parseOptions(args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        showHelp();
        return;
    }

    // Get all files that should be analyzed
    List<File> files = new ArrayList<File>();
    if (file.isDirectory()) {
        // Search directory for indicated file types
        files = searchDirectory(file);
        System.out.println("Found " + files.size() + " file(s).\n");
    } else {
        files.add(file);
    }

    // Process files found
    for (File filefound : files) {
        System.out.println("Processing file: " + filefound.getPath() + ".\n");
        Validator<?, ?, ?, ?> validator = null;
        switch (Extension.getFileExtension(filefound)) {
        case GOAL:
            validator = new AgentValidator(filefound.getPath());
            // TODO we need to set a KR interface; use default (only one)
            // right now. Best we can do now
            // is to ask user to set it.
            try {
                ((AgentValidator) validator).setKRInterface(KRFactory.getDefaultInterface());
            } catch (KRInitFailedException e) {
                // TODO: use logger.
                System.out.println(e.getMessage());
            }
            break;
        case MOD2G:
            validator = new ModuleValidator(filefound.getPath());
            // TODO we need to set a KR interface; use default (only one)
            // right now. Best we can do now
            // is to ask user to set it.
            try {
                ((ModuleValidator) validator).setKRInterface(KRFactory.getDefaultInterface());
            } catch (KRInitFailedException e) {
                // TODO: use logger.
                System.out.println(e.getMessage());
            }
            break;
        case MAS2G:
            validator = new MASValidator(filefound.getPath());
            break;
        case TEST2G:
            validator = new TestValidator(filefound.getPath());
            break;
        default:
            // TODO: use logger.
            System.out.println("Expected file with extension 'goal', 'mas2g', 'mod2g', or 'test2g'");
            continue;
        }

        // Validate program file
        validator.validate();

        // Print lexer tokens
        if (lexer) {
            validator.printLexerTokens();
        }

        // Print constructed program
        if (program) {
            System.out.println("\n\n" + validator.getProgram().toString(" ", " "));
        }

        // Print report with warnings, and parsing and validation messages
        System.out.println(validator.report());
    }

    // Get elapsed time.
    long elapsedTime = (System.nanoTime() - startTime) / 1000000;
    System.out.println("Took " + elapsedTime + " milliseconds to analyze " + files.size() + " file(s).");
}

From source file:net.skyebook.zerocollada.ZeroCollada.java

/**
 * @param args/*from   ww w.j av  a 2 s . com*/
 * @throws ParseException 
 * @throws IOException 
 * @throws JDOMException 
 */
public static void main(String[] args) throws ParseException, JDOMException, IOException {
    // Setup Apache Commons CLI
    optionsSetup();

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);

    if (args.length == 0 || cmd.hasOption(ZCOpts.help)) {
        showHelp();
    }

    // was there a valid operation specified?
    if (hasValidOption(cmd)) {
        File fileFromCommandLine = new File(args[args.length - 1]);
        if (!fileFromCommandLine.exists()) {
            System.err.println(
                    "The file located at " + fileFromCommandLine.toString() + " does not exist!  Qutting.");
            return;
        } else if (fileFromCommandLine.isFile() && fileFromCommandLine.toString().endsWith(".dae")) {
            // we've been given a single file.  Act on this single file
            doRequestedAction(fileFromCommandLine, cmd);
        } else if (fileFromCommandLine.isDirectory()) {
            // We've been given a directory of files process the ones that are .dae
            for (File file : fileFromCommandLine.listFiles()) {
                if (file.isFile() && file.toString().endsWith(".dae")) {
                    doRequestedAction(file, cmd);
                } else {
                    System.err.println(file.toString() + " does not seem to be a COLLADA file");
                }
            }
        }
    } else {
        // Then why are we here?
        if (cmd.hasOption(ZCOpts.includeY)) {
            System.err.println(
                    "You have used the " + ZCOpts.includeY + " option but have not asked for a transform (t)");
        } else if (cmd.hasOption(ZCOpts.anchorCenter)) {
            System.err.println(
                    "You have used the " + ZCOpts.includeY + " option but have not asked for a transform (t)");
        }
    }

}

From source file:DIA_Umpire_To_Skyline.DIA_Umpire_To_Skyline.java

/**
 * @param args the command line arguments
 *//*from   w  ww  .jav a  2  s  .  c  om*/
public static void main(String[] args) throws FileNotFoundException, IOException, Exception {
    System.out.println(
            "=================================================================================================");
    System.out.println("DIA-Umpire_To_Skyline (version: " + UmpireInfo.GetInstance().Version + ")");
    if (args.length < 1) {
        System.out.println(
                "command format error, it should be like: java -jar -Xmx20G DIA_Umpire_To_Skyline.jar Path NoThreads");
        System.out.println("command : java -jar -Xmx20G DIA_Umpire_To_Skyline.jar Path [Option]\n");
        System.out.println("\nOptions");
        System.out.println("\t-t\tNo. of threads, Ex: -t4 (using four threads, default value)");
        System.out.println(
                "\t-cP\tPath of msconvert.exe for mzXML conversion, Ex: -cP (using four threads, default value)");
        return;
    }
    try {
        ConsoleLogger.SetConsoleLogger(Level.DEBUG);
        ConsoleLogger.SetFileLogger(Level.DEBUG,
                FilenameUtils.getFullPath(args[0]) + "diaumpire_to_skyline.log");
    } catch (Exception e) {
        System.out.println("Logger initialization failed");
    }

    Logger.getRootLogger().info("Path:" + args[0]);
    String msconvertpath = "C:/inetpub/tpp-bin/msconvert";

    String WorkFolder = args[0];
    int NoCPUs = 4;

    for (int i = 1; i < args.length; i++) {
        if (args[i].startsWith("-")) {
            if (args[i].startsWith("-cP")) {
                msconvertpath = args[i].substring(3);
                Logger.getRootLogger().info("MSConvert path: " + msconvertpath);
            }
            if (args[i].startsWith("-t")) {
                NoCPUs = Integer.parseInt(args[i].substring(2));
                Logger.getRootLogger().info("No. of threads: " + NoCPUs);
            }
        }
    }

    HashMap<String, File> AssignFiles = new HashMap<>();

    try {
        File folder = new File(WorkFolder);
        if (!folder.exists()) {
            Logger.getRootLogger().info("Path: " + folder.getAbsolutePath() + " cannot be found.");
        }
        for (final File fileEntry : folder.listFiles()) {
            if (fileEntry.isFile() && fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzxml")
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q1.mzxml")
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q2.mzxml")
                    && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) {
                AssignFiles.put(fileEntry.getAbsolutePath(), fileEntry);
            }
            if (fileEntry.isDirectory()) {
                for (final File fileEntry2 : fileEntry.listFiles()) {
                    if (fileEntry2.isFile() && fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzxml")
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q1.mzxml")
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q2.mzxml")
                            && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) {
                        AssignFiles.put(fileEntry2.getAbsolutePath(), fileEntry2);
                    }
                }
            }
        }

        Logger.getRootLogger().info("No. of files assigned :" + AssignFiles.size());
        for (File fileEntry : AssignFiles.values()) {
            Logger.getRootLogger().info(fileEntry.getAbsolutePath());
        }

        ExecutorService executorPool = null;
        executorPool = Executors.newFixedThreadPool(3);

        for (File fileEntry : AssignFiles.values()) {
            String mzXMLFile = fileEntry.getAbsolutePath();
            FileThread thread = new FileThread(mzXMLFile, NoCPUs, msconvertpath);
            executorPool.execute(thread);
        }
        executorPool.shutdown();
        try {
            executorPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
        } catch (InterruptedException e) {
            Logger.getRootLogger().info("interrupted..");
        }
    } catch (Exception e) {
        Logger.getRootLogger().error(e.getMessage());
        throw e;
    }
    Logger.getRootLogger().info("Job done");
    Logger.getRootLogger().info(
            "=================================================================================================");

}

From source file:net.sf.firemox.xml.XmlConfiguration.java

/**
 * <ul>//from w w w  .  j av a  2s  .  com
 * 2 modes:
 * <li>Update the a MDB for specified TBS against the XML files (main file,
 * cards and fragments). Arguments are : TBS_NAME</li>
 * <li>Rebuild completely the MDB for specified TBS. Arguments are : -full
 * TBS_NAME</li>
 * </ul>
 * 
 * @param args
 *          main arguments.
 */
public static void main(String... args) {
    options = new Options();
    final CmdLineParser parser = new CmdLineParser(options);
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        // Display help
        info(e.getMessage());
        parser.setUsageWidth(80);
        parser.printUsage(System.out);
        System.exit(-1);
        return;
    }

    if (options.isVersion()) {
        // Display version
        info("Version is " + IdConst.VERSION);
        System.exit(-1);
        return;
    }

    if (options.isHelp()) {
        // Display help
        parser.setUsageWidth(80);
        parser.printUsage(System.out);
        System.exit(-1);
        return;
    }

    warning = 0;
    uncompleted = 0;
    error = 0;
    long start = System.currentTimeMillis();
    XmlTools.initHashMaps();
    MToolKit.tbsName = options.getMdb();
    String xmlFile = MToolKit.getFile(IdConst.TBS_DIR + "/" + MToolKit.tbsName + ".xml", false)
            .getAbsolutePath();
    try {
        if (options.isForce()) {
            final File recycledDir = MToolKit.getTbsFile("recycled");
            if (!recycledDir.exists() || !recycledDir.isDirectory()) {
                recycledDir.mkdir();
            }

            parseRules(xmlFile, MToolKit.getTbsFile("recycled").getAbsolutePath(),
                    new FileOutputStream(MToolKit.getTbsFile(MToolKit.tbsName + ".mdb", false)));
        } else {
            // Check the up-to-date state of MDB
            final File file = MToolKit
                    .getFile(IdConst.TBS_DIR + "/" + MToolKit.tbsName + "/" + MToolKit.tbsName + ".mdb");
            final long lastModifiedMdb;
            if (file == null) {
                lastModifiedMdb = 0;
            } else {
                lastModifiedMdb = file.lastModified();
            }
            boolean update = false;
            // Check the up-to-date state of MDB against the main XML file
            if (MToolKit.getFile(xmlFile).lastModified() > lastModifiedMdb) {
                // The main XML file is newer than MDB
                System.out.println("MDB is out of date, " + xmlFile + " is newer");
                update = true;
            } else {
                final File fragmentDir = MToolKit.getTbsFile("");
                for (File frament : fragmentDir.listFiles(
                        (FilenameFilter) FileFilterUtils.andFileFilter(FileFilterUtils.suffixFileFilter("xml"),
                                FileFilterUtils.prefixFileFilter("fragment-")))) {
                    if (frament.lastModified() > lastModifiedMdb) {
                        // One card is newer than MDB
                        System.out.println(
                                "MDB is out of date, at least one fragment found : " + frament.getName());
                        update = true;
                        break;
                    }
                }
                if (!update) {
                    // Check the up-to-date state of MDB against the cards
                    final File recycledDir = MToolKit.getTbsFile("recycled");
                    if (!recycledDir.exists() || !recycledDir.isDirectory()) {
                        recycledDir.mkdir();
                    }
                    if (recycledDir.lastModified() > lastModifiedMdb) {
                        // The recycled XML file is newer than MDB
                        System.out.println("MDB is out of date, the recycled directory is new");
                        update = true;
                    } else {
                        for (File card : recycledDir.listFiles((FilenameFilter) FileFilterUtils.andFileFilter(
                                FileFilterUtils.suffixFileFilter("xml"), FileFilterUtils.notFileFilter(
                                        FileFilterUtils.suffixFileFilter(IdConst.FILE_DATABASE_SAVED))))) {
                            if (card.lastModified() > lastModifiedMdb) {
                                // One card is newer than MDB
                                System.out.println("MDB is out of date, at least one new card found : " + card);
                                update = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (!update) {
                return;
            }
            // Need to update the whole MDB
            parseRules(xmlFile, MToolKit.getTbsFile("recycled").getAbsolutePath(),
                    new FileOutputStream(MToolKit.getTbsFile(MToolKit.tbsName + ".mdb", false)));
        }
    } catch (SAXParseException e) {
        // Ignore this error
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (warning > 0) {
        System.out.println("\t" + warning + " warning" + (warning > 1 ? "s" : ""));
    }
    if (error > 0) {
        System.out.println("\t" + error + " error" + (error > 1 ? "s" : ""));
        System.out.println("Some cards have not been built correctly. Fix them.");
    } else {
        System.out.println("\tSuccessfull build");
    }
    System.out.println("\tTime : " + (System.currentTimeMillis() - start) / 1000 + " s");
}

From source file:de.prozesskraft.ptest.Compare.java

public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException {

    //      try/*from   w ww  .  j a  v  a2s . c om*/
    //      {
    //         if (args.length != 3)
    //         {
    //            System.out.println("Please specify processdefinition file (xml) and an outputfilename");
    //         }
    //         
    //      }
    //      catch (ArrayIndexOutOfBoundsException e)
    //      {
    //         System.out.println("***ArrayIndexOutOfBoundsException: Please specify processdefinition.xml, openoffice_template.od*, newfile_for_processdefinitions.odt\n" + e.toString());
    //      }

    /*----------------------------
      get options from ini-file
    ----------------------------*/
    File inifile = new java.io.File(
            WhereAmI.getInstallDirectoryAbsolutePath(Compare.class) + "/" + "../etc/ptest-compare.ini");

    if (inifile.exists()) {
        try {
            ini = new Ini(inifile);
        } catch (InvalidFileFormatException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else {
        System.err.println("ini file does not exist: " + inifile.getAbsolutePath());
        System.exit(1);
    }

    /*----------------------------
      create boolean options
    ----------------------------*/
    Option ohelp = new Option("help", "print this message");
    Option ov = new Option("v", "prints version and build-date");

    /*----------------------------
      create argument options
    ----------------------------*/
    Option oref = OptionBuilder.withArgName("PATH").hasArg()
            .withDescription("[mandatory] directory or fingerprint, that the --exam will be checked against")
            //            .isRequired()
            .create("ref");

    Option oexam = OptionBuilder.withArgName("PATH").hasArg().withDescription(
            "[optional; default: parent directory of -ref] directory or fingerprint, that will be checked against --ref")
            //            .isRequired()
            .create("exam");

    Option oresult = OptionBuilder.withArgName("FILE").hasArg().withDescription(
            "[mandatory; default: result.txt] the result (success|failed) of the comparison will be printed to this file")
            //            .isRequired()
            .create("result");

    Option osummary = OptionBuilder.withArgName("all|error|debug").hasArg().withDescription(
            "[optional] 'error' prints a summary reduced to failed matches. 'all' prints a full summary. 'debug' is like 'all' plus debug statements")
            //            .isRequired()
            .create("summary");

    Option omd5 = OptionBuilder.withArgName("no|yes").hasArg()
            .withDescription("[optional; default: yes] to ignore md5 information in comparison use -md5=no")
            //            .isRequired()
            .create("md5");

    /*----------------------------
      create options object
    ----------------------------*/
    Options options = new Options();

    options.addOption(ohelp);
    options.addOption(ov);
    options.addOption(oref);
    options.addOption(oexam);
    options.addOption(oresult);
    options.addOption(osummary);
    options.addOption(omd5);

    /*----------------------------
      create the parser
    ----------------------------*/
    CommandLineParser parser = new GnuParser();
    try {
        // parse the command line arguments
        commandline = parser.parse(options, args);

    } catch (Exception exp) {
        // oops, something went wrong
        System.err.println("Parsing failed. Reason: " + exp.getMessage());
        exiter();
    }

    /*----------------------------
      usage/help
    ----------------------------*/
    if (commandline.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("compare", options);
        System.exit(0);
    }

    else if (commandline.hasOption("v")) {
        System.err.println("web:     " + web);
        System.err.println("author: " + author);
        System.err.println("version:" + version);
        System.err.println("date:     " + date);
        System.exit(0);
    }

    /*----------------------------
      ueberpruefen ob eine schlechte kombination von parametern angegeben wurde
    ----------------------------*/
    boolean error = false;
    String result = "";
    boolean md5 = false;
    String ref = null;
    String exam = null;

    if (!(commandline.hasOption("ref"))) {
        System.err.println("option -ref is mandatory");
        error = true;
    } else {
        ref = commandline.getOptionValue("ref");
    }

    if (!(commandline.hasOption("exam"))) {
        java.io.File refFile = new java.io.File(ref).getCanonicalFile();
        java.io.File examFile = refFile.getParentFile();
        exam = examFile.getCanonicalPath();

        System.err.println("setting default: -exam=" + exam);
    } else {
        exam = commandline.getOptionValue("exam");
    }

    if (error) {
        exiter();
    }

    if (!(commandline.hasOption("result"))) {
        System.err.println("setting default: -result=result.txt");
        result = "result.txt";
    }

    if (!(commandline.hasOption("md5"))) {
        System.err.println("setting default: -md5=yes");
        md5 = true;
    } else if (commandline.getOptionValue("md5").equals("no")) {
        md5 = false;
    } else if (commandline.getOptionValue("md5").equals("yes")) {
        md5 = true;
    } else {
        System.err.println("use only values no|yes for -md5");
        System.exit(1);
    }

    /*----------------------------
      die lizenz ueberpruefen und ggf abbrechen
    ----------------------------*/

    // check for valid license
    ArrayList<String> allPortAtHost = new ArrayList<String>();
    allPortAtHost.add(ini.get("license-server", "license-server-1"));
    allPortAtHost.add(ini.get("license-server", "license-server-2"));
    allPortAtHost.add(ini.get("license-server", "license-server-3"));

    MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1");

    // lizenz-logging ausgeben
    for (String actLine : (ArrayList<String>) lic.getLog()) {
        System.err.println(actLine);
    }

    // abbruch, wenn lizenz nicht valide
    if (!lic.isValid()) {
        System.exit(1);
    }

    /*----------------------------
      die eigentliche business logic
    ----------------------------*/

    // einlesen der referenzdaten
    java.io.File refPath = new java.io.File(ref);

    Dir refDir = new Dir();

    // wenn es ein directory ist, muss der fingerprint erzeugt werden
    if (refPath.exists() && refPath.isDirectory()) {
        refDir.setBasepath(refPath.getCanonicalPath());
        refDir.genFingerprint(0f, true, new ArrayList<String>());
        refDir.setRespectMd5Recursive(md5);
        System.err.println("-ref is a directory");
    }
    // wenn es ein fingerprint ist, muss er eingelesen werden
    else if (refPath.exists()) {
        refDir.setInfilexml(refPath.getCanonicalPath());
        System.err.println("-ref is a fingerprint");
        try {
            refDir.readXml();
        } catch (JAXBException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        refDir.setRespectMd5Recursive(md5);
    } else if (!refPath.exists()) {
        System.err.println("-ref does not exist! " + refPath.getAbsolutePath());
        exiter();
    }

    // einlesen der prueflingsdaten
    java.io.File examPath = new java.io.File(exam);

    Dir examDir = new Dir();

    // wenn es ein directory ist, muss der fingerprint erzeugt werden
    if (examPath.exists() && examPath.isDirectory()) {
        examDir.setBasepath(examPath.getCanonicalPath());
        examDir.genFingerprint(0f, true, new ArrayList<String>());
        examDir.setRespectMd5Recursive(md5);
        System.err.println("-exam is a directory");
    }
    // wenn es ein fingerprint ist, muss er eingelesen werden
    else if (examPath.exists()) {
        examDir.setInfilexml(examPath.getCanonicalPath());
        System.err.println("-exam is a fingerprint");
        try {
            examDir.readXml();
        } catch (JAXBException e) {
            System.err.println("error while reading xml");
            e.printStackTrace();
        }
        examDir.setRespectMd5Recursive(md5);
    } else if (!examPath.exists()) {
        System.err.println("-exam does not exist! " + examPath.getAbsolutePath());
        exiter();
    }

    // durchfuehren des vergleichs
    refDir.runCheck(examDir);

    //      if(examDir.isMatchSuccessfullRecursive() && refDir.isMatchSuccessfullRecursive())
    if (refDir.isMatchSuccessfullRecursive()) {
        System.out.println("SUCCESS");
    } else {
        System.out.println("FAILED");
    }

    // printen der csv-ergebnis-tabelle
    if (commandline.hasOption("summary")) {
        if (commandline.getOptionValue("summary").equals("error")) {
            System.err.println("the results of the reference are crucial for result FAILED|SUCCESS");
            System.err.println(refDir.sprintSummaryAsCsv("error"));
            System.err.println(examDir.sprintSummaryAsCsv("error"));
        } else if (commandline.getOptionValue("summary").equals("all")) {
            System.err.println(refDir.sprintSummaryAsCsv("all"));
            System.err.println(examDir.sprintSummaryAsCsv("all"));
        } else if (commandline.getOptionValue("summary").equals("debug")) {
            System.err.println(refDir.sprintSummaryAsCsv("all"));
            System.err.println(examDir.sprintSummaryAsCsv("all"));
            // printen des loggings
            System.err.println("------ logging of reference --------");
            System.err.println(refDir.getLogAsStringRecursive());
            System.err.println("------ logging of examinee --------");
            System.err.println(examDir.getLogAsStringRecursive());
        } else {
            System.err.println("for option -summary you only may use all|error");
            exiter();
        }
    }

}

From source file:com.act.lcms.db.analysis.IonDetectionAnalysis.java

public static void main(String[] args) throws Exception {

    Options opts = new Options();
    for (Option.Builder b : OPTION_BUILDERS) {
        opts.addOption(b.build());/*from  w w  w .jav a  2 s .com*/
    }

    CommandLine cl = null;
    try {
        CommandLineParser parser = new DefaultParser();
        cl = parser.parse(opts, args);
    } catch (ParseException e) {
        System.err.format("Argument parsing failed: %s", e.getMessage());
        HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        System.exit(1);
    }

    if (cl.hasOption("help")) {
        HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        return;
    }

    File lcmsDir = new File(cl.getOptionValue(OPTION_LCMS_FILE_DIRECTORY));
    if (!lcmsDir.isDirectory()) {
        System.err.format("File at %s is not a directory", lcmsDir.getAbsolutePath());
        HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null,
                true);
        System.exit(1);
    }

    String plottingDirectory = cl.getOptionValue(OPTION_PLOTTING_DIR);

    // Get include and excluse ions from command line
    Set<String> includeIons;
    if (cl.hasOption(OPTION_INCLUDE_IONS)) {
        includeIons = new HashSet<>(Arrays.asList(cl.getOptionValues(OPTION_INCLUDE_IONS)));
        LOGGER.info("Including ions in search: %s", StringUtils.join(includeIons, ", "));
    } else {
        includeIons = new HashSet<>();
        includeIons.add(DEFAULT_ION);
    }

    try (DB db = DB.openDBFromCLI(cl)) {
        ScanFile.insertOrUpdateScanFilesInDirectory(db, lcmsDir);

        File inputPredictionCorpus = new File(cl.getOptionValue(OPTION_INPUT_PREDICTION_CORPUS));

        Map<Double, Set<Pair<String, String>>> massChargeToChemicalAndIon = constructMassChargeToChemicalIonsFromInputFile(
                inputPredictionCorpus, includeIons, cl.hasOption(OPTION_LIST_OF_INCHIS_INPUT_FILE));

        Pair<Set<Pair<String, Double>>, Map<String, Double>> values = constructFakeNameToMassChargeAndSetOfMassChargePairs(
                massChargeToChemicalAndIon.keySet());
        Set<Pair<String, Double>> searchMZs = values.getLeft();
        Map<String, Double> chemIDToMassCharge = values.getRight();

        LOGGER.info("The number of mass charges are: %d", searchMZs.size());

        Map<ScanData.KIND, List<LCMSWell>> wellTypeToLCMSWells = readInputExperimentalSetup(db,
                new File(cl.getOptionValue(OPTION_INPUT_POSITIVE_AND_NEGATIVE_CONTROL_WELLS_FILE)));

        // Get experimental setup ie. positive and negative wells from config file
        List<LCMSWell> positiveWells = wellTypeToLCMSWells.get(ScanData.KIND.POS_SAMPLE);
        List<LCMSWell> negativeWells = wellTypeToLCMSWells.get(ScanData.KIND.NEG_CONTROL);

        LOGGER.info("Number of positive wells is: %d", positiveWells.size());
        LOGGER.info("Number of negative wells is: %d", negativeWells.size());

        HashMap<Integer, Plate> plateCache = new HashMap<>();
        String outputPrefix = cl.getOptionValue(OPTION_OUTPUT_PREFIX);

        IonDetectionAnalysis<LCMSWell> ionDetectionAnalysis = new IonDetectionAnalysis<LCMSWell>(lcmsDir,
                positiveWells, negativeWells, plottingDirectory, plateCache, searchMZs, db);

        ionDetectionAnalysis.runLCMSMiningAnalysisAndPlotResults(chemIDToMassCharge, massChargeToChemicalAndIon,
                outputPrefix, cl.hasOption(OPTION_NON_REPLICATE_ANALYSIS));
    }
}

From source file:fr.inria.edelweiss.kgimport.RdfSplitter.java

/**
 * The application entrypoint, configured through the command line input
 * arguments./*from w  ww  .j a va2  s.c o  m*/
 *
 * @param args the input command line arguments.
 */
public static void main(String args[]) {

    RdfSplitter rdfSplitter = new RdfSplitter();

    Options options = new Options();
    Option helpOpt = new Option("h", "help", false, "Print usage information.");
    Option inDirOpt = new Option("i", "input-dir", true, "The directory containing RDF files to be loaded.");
    Option outDirOpt = new Option("o", "output-dir", true,
            "The directory containing the generated RDF fragments");
    Option predFiltOpt = new Option("p", "predicate-filter", true,
            "Predicate filter used to segment the dataset. "
                    + "You can use multiple filters, typically one per fragment.");
    Option fragNbOpt = new Option("n", "number-of-fragments", true,
            "Number of fragments generated for the whole input dataset.");
    Option fragRepOpt = new Option("f", "fractionning-percentage", true,
            "Percentage of the whole input dataset for this fragment.");
    Option tdbOpt = new Option("tdb", "tdb-storage", false,
            "RDF fragments are persisted into a Jena TDB backend.");
    Option versionOpt = new Option("v", "version", false, "Print the version information and exit.");
    options.addOption(inDirOpt);
    options.addOption(outDirOpt);
    options.addOption(predFiltOpt);
    options.addOption(helpOpt);
    options.addOption(versionOpt);
    options.addOption(fragNbOpt);
    options.addOption(fragRepOpt);
    options.addOption(tdbOpt);

    String header = "RDF data fragmentation tool command line interface";
    String footer = "\nPlease report any issue to alban.gaignard@cnrs.fr";

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar [].jar", header, options, footer, true);
            System.exit(0);
        }

        if (!cmd.hasOption("i")) {
            logger.warn("You must specify a valid input directory !");
            System.exit(-1);
        } else {
            rdfSplitter.setInputDirPath(cmd.getOptionValue("i"));
        }
        if (!cmd.hasOption("o")) {
            logger.warn("You must specify a valid output directory !");
            System.exit(-1);
        } else {
            rdfSplitter.setOutputDirPath(cmd.getOptionValue("o"));
        }
        if (cmd.hasOption("p")) {
            rdfSplitter.setInputPredicates(new ArrayList<String>(Arrays.asList(cmd.getOptionValues("p"))));
        }
        if (cmd.hasOption("f")) {
            ArrayList<String> opts = new ArrayList<String>(Arrays.asList(cmd.getOptionValues("f")));
            for (String opt : opts) {
                try {
                    rdfSplitter.getFragList().add(Integer.parseInt(opt));
                } catch (NumberFormatException e) {
                    logger.error(opt + " cannot be pased as an percentage value.");
                    System.exit(-1);
                }
            }
        }
        if (cmd.hasOption("n")) {
            try {
                rdfSplitter.setFragNb(Integer.parseInt(cmd.getOptionValue("n")));
            } catch (NumberFormatException e) {
                logger.error(cmd.getOptionValue("n") + " cannot be pased as an integer value.");
                System.exit(-1);
            }
        }

        File oDir = new File(rdfSplitter.getOutputDirPath());
        if (oDir.exists()) {
            logger.warn(rdfSplitter.getOutputDirPath() + " already exists !");
            oDir = Files.createTempDir();
            logger.warn(oDir.getAbsolutePath() + " created.");
            rdfSplitter.setOutputDirPath(oDir.getAbsolutePath());
        } else {
            if (oDir.mkdir()) {
                logger.info(rdfSplitter.getOutputDirPath() + " created.");
            }
        }

        if (!cmd.hasOption("n") && !cmd.hasOption("f") && !cmd.hasOption("p")) {
            logger.error("You must specify just one fragmentation type through '-n', '-f', or 'p' options");
            for (String arg : args) {
                logger.trace(arg);
            }
            System.exit(-1);
        }

        String fragName = rdfSplitter.getInputDirPath()
                .substring(rdfSplitter.getInputDirPath().lastIndexOf("/") + 1);

        //Input data loading
        Model model = ModelFactory.createDefaultModel();
        File inputDir = new File(rdfSplitter.getInputDirPath());
        if (inputDir.isDirectory()) {
            for (File f : inputDir.listFiles()) {
                logger.info("Loading " + f.getAbsolutePath());
                if (f.isDirectory()) {
                    String directory = f.getAbsolutePath();
                    Dataset dataset = TDBFactory.createDataset(directory);
                    dataset.begin(ReadWrite.READ);
                    // Get model inside the transaction
                    model.add(dataset.getDefaultModel());
                    dataset.end();
                } else {
                    InputStream iS;
                    try {
                        iS = new FileInputStream(f);
                        if (f.getAbsolutePath().endsWith(".n3")) {
                            model.read(iS, null, "N3");
                        } else if (f.getAbsolutePath().endsWith(".nt")) {
                            model.read(iS, null, "N-TRIPLES");
                        } else if (f.getAbsolutePath().endsWith(".rdf")) {
                            model.read(iS, null);
                        }
                    } catch (FileNotFoundException ex) {
                        LogManager.getLogger(RdfSplitter.class.getName()).log(Level.ERROR, "", ex);
                    }
                }
            }
            logger.info("Loaded " + model.size() + " triples");
        } else {
            System.exit(0);
        }

        StopWatch sw = new StopWatch();
        if (cmd.hasOption("n")) {
            sw.start();
            if (cmd.hasOption("tdb")) {
                rdfSplitter.saveFragmentsTDB(rdfSplitter.getFragHoriz(model, rdfSplitter.getFragNb()),
                        "Homog-" + fragName);
            } else {
                rdfSplitter.saveFragmentsRDF(rdfSplitter.getFragHoriz(model, rdfSplitter.getFragNb()),
                        "Homog-" + fragName);
            }
            logger.info("Homog horiz frag in " + sw.getTime() + "ms");
            sw.reset();
        } else if (cmd.hasOption("f")) {
            sw.start();
            if (cmd.hasOption("tdb")) {
                rdfSplitter.saveFragmentsTDB(rdfSplitter.getFragHoriz(model, rdfSplitter.getFragList()),
                        "Inhomog-" + fragName);
            } else {
                rdfSplitter.saveFragmentsRDF(rdfSplitter.getFragHoriz(model, rdfSplitter.getFragList()),
                        "Inhomog-" + fragName);
            }
            logger.info("Inhomog horiz frag in " + sw.getTime() + "ms");
            sw.reset();
        } else if (cmd.hasOption("p")) {
            sw.start();
            if (cmd.hasOption("tdb")) {
                rdfSplitter.saveFragmentsTDB(rdfSplitter.getFragVert(model, rdfSplitter.getInputPredicates()));
            } else {
                rdfSplitter.saveFragmentsRDF(rdfSplitter.getFragVert(model, rdfSplitter.getInputPredicates()));
            }
            logger.info("Vert frag in " + sw.getTime() + "ms");
            sw.reset();
        }

    } catch (ParseException ex) {
        logger.error("Impossible to parse the input command line " + cmd.toString());
    }
}

From source file:ViewImageTest.java

/**
 * Test image(s) (default : JPEG_example_JPG_RIP_100.jpg) are parsed and
 * rendered to an output foler. Result can then be checked with program of
 * your choice./*from  w w w . j a v a 2s  .c  om*/
 * 
 * @param args
 *            may be empty or contain parameters to override defaults :
 *            <ul>
 *            <li>args[0] : input image file URL or folder containing image
 *            files URL. Default :
 *            viewImageTest/test/JPEG_example_JPG_RIP_100.jpg</li>
 *            <li>args[1] : output format name (for example : "jpg") for
 *            rendered image</li>
 *            <li>args[2] : ouput folder URL</li>
 *            <li>args[3] : max width (in pixels) for rendered image.
 *            Default : no value.</li>
 *            <li>args[4] : max height (in pixels) for rendered image.
 *            Default : no value.</li>
 *            </ul>
 * @throws IOException
 *             when a read/write error occured
 */
public static void main(String args[]) throws IOException {
    File inURL = getInputURL(args);
    String ext = getEncodingExt(args);
    File outDir = getOuputDir(args);
    serverObjects post = makePostParams(args);
    outDir.mkdirs();

    File[] inFiles;
    if (inURL.isFile()) {
        inFiles = new File[1];
        inFiles[0] = inURL;
        System.out.println("Testing ViewImage rendering with input file : " + inURL.getAbsolutePath()
                + " encoded To : " + ext);
    } else if (inURL.isDirectory()) {
        FileFilter filter = FileFileFilter.FILE;
        inFiles = inURL.listFiles(filter);
        System.out.println("Testing ViewImage rendering with input files in folder : " + inURL.getAbsolutePath()
                + " encoded To : " + ext);
    } else {
        inFiles = new File[0];
    }
    if (inFiles.length == 0) {
        throw new IllegalArgumentException(inURL.getAbsolutePath() + " is not a valid file or folder url.");
    }
    System.out.println("Rendered images will be written in dir : " + outDir.getAbsolutePath());

    Map<String, Exception> failures = new HashMap<String, Exception>();
    try {
        for (File inFile : inFiles) {
            /* Delete eventual previous result file */
            File outFile = new File(outDir, inFile.getName() + "." + ext);
            if (outFile.exists()) {
                outFile.delete();
            }

            byte[] resourceb = getBytes(inFile);
            String urlString = inFile.getAbsolutePath();
            EncodedImage img = null;
            Exception error = null;
            try {
                img = ViewImage.parseAndScale(post, true, urlString, ext, false, resourceb);
            } catch (Exception e) {
                error = e;
            }

            if (img == null) {
                failures.put(urlString, error);
            } else {
                FileOutputStream outFileStream = null;
                try {
                    outFileStream = new FileOutputStream(outFile);
                    img.getImage().writeTo(outFileStream);
                } finally {
                    if (outFileStream != null) {
                        outFileStream.close();
                    }
                    img.getImage().close();
                }
            }
        }
        displayResults(inFiles, failures);
    } finally {
        ConcurrentLog.shutdown();
    }

}

From source file:ClassFileUtilities.java

/**
 * Program that computes the dependencies between the Batik jars.
 * <p>//from w ww .j  ava2 s.c o m
 *   Run this from the main Batik distribution directory, after building
 *   the jars.  For every jar file in the batik-xxx/ build directory,
 *   it will determine which other jar files it directly depends on.
 *   The output is lines of the form:
 * </p>
 * <pre>  <i>number</i>,<i>from</i>,<i>to</i></pre>
 * <p>
 *   where mean that the <i>from</i> jar has <i>number</i> class files
 *   that depend on class files in the <i>to</i> jar.
 * </p>
 */
public static void main(String[] args) {
    boolean showFiles = false;
    if (args.length == 1 && args[0].equals("-f")) {
        showFiles = true;
    } else if (args.length != 0) {
        System.err.println("usage: ClassFileUtilities [-f]");
        System.err.println();
        System.err.println("  -f    list files that cause each jar file dependency");
        System.exit(1);
    }

    File cwd = new File(".");
    File buildDir = null;
    String[] cwdFiles = cwd.list();
    for (int i = 0; i < cwdFiles.length; i++) {
        if (cwdFiles[i].startsWith("batik-")) {
            buildDir = new File(cwdFiles[i]);
            if (!buildDir.isDirectory()) {
                buildDir = null;
            } else {
                break;
            }
        }
    }
    if (buildDir == null || !buildDir.isDirectory()) {
        System.out.println("Directory 'batik-xxx' not found in current directory!");
        return;
    }

    try {
        Map cs = new HashMap();
        Map js = new HashMap();
        collectJars(buildDir, js, cs);

        Set classpath = new HashSet();
        Iterator i = js.values().iterator();
        while (i.hasNext()) {
            classpath.add(((Jar) i.next()).jarFile);
        }

        i = cs.values().iterator();
        while (i.hasNext()) {
            ClassFile fromFile = (ClassFile) i.next();
            // System.out.println(fromFile.name);
            Set result = getClassDependencies(fromFile.getInputStream(), classpath, false);
            Iterator j = result.iterator();
            while (j.hasNext()) {
                ClassFile toFile = (ClassFile) cs.get(j.next());
                if (fromFile != toFile && toFile != null) {
                    fromFile.deps.add(toFile);
                }
            }
        }

        i = cs.values().iterator();
        while (i.hasNext()) {
            ClassFile fromFile = (ClassFile) i.next();
            Iterator j = fromFile.deps.iterator();
            while (j.hasNext()) {
                ClassFile toFile = (ClassFile) j.next();
                Jar fromJar = fromFile.jar;
                Jar toJar = toFile.jar;
                if (fromFile.name.equals(toFile.name) || toJar == fromJar
                        || fromJar.files.contains(toFile.name)) {
                    continue;
                }
                Integer n = (Integer) fromJar.deps.get(toJar);
                if (n == null) {
                    fromJar.deps.put(toJar, new Integer(1));
                } else {
                    fromJar.deps.put(toJar, new Integer(n.intValue() + 1));
                }
            }
        }

        List triples = new ArrayList(10);
        i = js.values().iterator();
        while (i.hasNext()) {
            Jar fromJar = (Jar) i.next();
            Iterator j = fromJar.deps.keySet().iterator();
            while (j.hasNext()) {
                Jar toJar = (Jar) j.next();
                Triple t = new Triple();
                t.from = fromJar;
                t.to = toJar;
                t.count = ((Integer) fromJar.deps.get(toJar)).intValue();
                triples.add(t);
            }
        }
        Collections.sort(triples);

        i = triples.iterator();
        while (i.hasNext()) {
            Triple t = (Triple) i.next();
            System.out.println(t.count + "," + t.from.name + "," + t.to.name);
            if (showFiles) {
                Iterator j = t.from.files.iterator();
                while (j.hasNext()) {
                    ClassFile fromFile = (ClassFile) j.next();
                    Iterator k = fromFile.deps.iterator();
                    while (k.hasNext()) {
                        ClassFile toFile = (ClassFile) k.next();
                        if (toFile.jar == t.to && !t.from.files.contains(toFile.name)) {
                            System.out.println("\t" + fromFile.name + " --> " + toFile.name);
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.mapr.synth.Synth.java

public static void main(String[] args)
        throws IOException, CmdLineException, InterruptedException, ExecutionException {
    final Options opts = new Options();
    CmdLineParser parser = new CmdLineParser(opts);
    try {//w w  w . j a  v  a2  s . c o  m
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println("Usage: " + "[ -count <number>G|M|K ] " + "-schema schema-file "
                + "[-quote DOUBLE_QUOTE|BACK_SLASH|OPTIMISTIC] " + "[-format JSON|TSV|CSV|XML ] "
                + "[-threads n] " + "[-output output-directory-name] ");
        throw e;
    }
    Preconditions.checkArgument(opts.threads > 0 && opts.threads <= 2000,
            "Must have at least one thread and no more than 2000");

    if (opts.threads > 1) {
        Preconditions.checkArgument(!"-".equals(opts.output),
                "If more than on thread is used, you have to use -output to set the output directory");
    }

    File outputDir = new File(opts.output);
    if (!"-".equals(opts.output)) {
        if (!outputDir.exists()) {
            Preconditions.checkState(outputDir.mkdirs(),
                    String.format("Couldn't create output directory %s", opts.output));
        }
        Preconditions.checkArgument(outputDir.exists() && outputDir.isDirectory(),
                String.format("Couldn't create directory %s", opts.output));
    }

    if (opts.schema == null) {
        throw new IllegalArgumentException("Must specify schema file using [-schema filename] option");
    }
    final SchemaSampler sampler = new SchemaSampler(opts.schema);
    final AtomicLong rowCount = new AtomicLong();

    final List<ReportingWorker> tasks = Lists.newArrayList();
    int limit = (opts.count + opts.threads - 1) / opts.threads;
    int remaining = opts.count;
    for (int i = 0; i < opts.threads; i++) {

        final int count = Math.min(limit, remaining);
        remaining -= count;

        tasks.add(new ReportingWorker(opts, sampler, rowCount, count, i));
    }

    final double t0 = System.nanoTime() * 1e-9;
    ExecutorService pool = Executors.newFixedThreadPool(opts.threads);
    ScheduledExecutorService blinker = Executors.newScheduledThreadPool(1);
    final AtomicBoolean finalRun = new AtomicBoolean(false);

    final PrintStream sideLog = new PrintStream(new FileOutputStream("side-log"));
    Runnable blink = new Runnable() {
        public double oldT;
        private long oldN;

        @Override
        public void run() {
            double t = System.nanoTime() * 1e-9;
            long n = rowCount.get();
            System.err.printf("%s\t%d\t%.1f\t%d\t%.1f\t%.3f\n", finalRun.get() ? "F" : "R", opts.threads,
                    t - t0, n, n / (t - t0), (n - oldN) / (t - oldT));
            for (ReportingWorker task : tasks) {
                ReportingWorker.ThreadReport r = task.report();
                sideLog.printf("\t%d\t%.2f\t%.2f\t%.2f\t%.1f\t%.1f\n", r.fileNumber, r.threadTime, r.userTime,
                        r.wallTime, r.rows / r.threadTime, r.rows / r.wallTime);
            }
            oldN = n;
            oldT = t;
        }
    };
    if (!"-".equals(opts.output)) {
        blinker.scheduleAtFixedRate(blink, 0, 10, TimeUnit.SECONDS);
    }
    List<Future<Integer>> results = pool.invokeAll(tasks);

    int total = 0;
    for (Future<Integer> result : results) {
        total += result.get();
    }
    Preconditions.checkState(total == opts.count, String
            .format("Expected to generate %d lines of output, but actually generated %d", opts.count, total));
    pool.shutdownNow();
    blinker.shutdownNow();
    finalRun.set(true);
    sideLog.close();
    blink.run();
}