Example usage for java.io File getPath

List of usage examples for java.io File getPath

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Converts this abstract pathname into a pathname string.

Usage

From source file:edu.harvard.hul.ois.drs.pdfaconvert.PdfaConvert.java

public static void main(String[] args) throws IOException {
    if (logger == null) {
        System.out.println("About to initialize Log4j");
        logger = LogManager.getLogger();
        System.out.println("Finished initializing Log4j");
    }/* www.  j  a  v  a 2s. c o m*/

    logger.debug("Entering main()");

    // WIP: the following command line code was pulled from FITS
    Options options = new Options();
    Option inputFileOption = new Option(PARAM_I, true, "input file");
    options.addOption(inputFileOption);
    options.addOption(PARAM_V, false, "print version information");
    options.addOption(PARAM_H, false, "help information");
    options.addOption(PARAM_O, true, "output sub-directory");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args, true);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }

    // print version info
    if (cmd.hasOption(PARAM_V)) {
        if (StringUtils.isEmpty(applicationVersion)) {
            applicationVersion = "<not set>";
            System.exit(1);
        }
        System.out.println("Version: " + applicationVersion);
        System.exit(0);
    }

    // print help info
    if (cmd.hasOption(PARAM_H)) {
        displayHelp();
        System.exit(0);
    }

    // input parameter
    if (cmd.hasOption(PARAM_I)) {
        String input = cmd.getOptionValue(PARAM_I);
        boolean hasValue = cmd.hasOption(PARAM_I);
        logger.debug("Has option {} value: [{}]", PARAM_I, hasValue);
        String paramVal = cmd.getOptionValue(PARAM_I);
        logger.debug("value of option: [{}] ****", paramVal);

        File inputFile = new File(input);
        if (!inputFile.exists()) {
            logger.warn("{} does not exist or is not readable.", input);
            System.exit(1);
        }

        String subDir = cmd.getOptionValue(PARAM_O);
        PdfaConvert convert;
        if (!StringUtils.isEmpty(subDir)) {
            convert = new PdfaConvert(subDir);
        } else {
            convert = new PdfaConvert();
        }
        if (inputFile.isDirectory()) {
            if (inputFile.listFiles() == null || inputFile.listFiles().length < 1) {
                logger.warn("Input directory is empty, nothing to process.");
                System.exit(1);
            } else {
                logger.debug("Have directory: [{}] with file count: {}", inputFile.getAbsolutePath(),
                        inputFile.listFiles().length);
                DirectoryStream<Path> dirStream = null;
                dirStream = Files.newDirectoryStream(inputFile.toPath());
                for (Path filePath : dirStream) {
                    logger.debug("Have file name: {}", filePath.toString());
                    // Note: only handling files, not recursively going into sub-directories
                    if (filePath.toFile().isFile()) {
                        // Catch possible exception for each file so can handle other files in directory.
                        try {
                            convert.examine(filePath.toFile());
                        } catch (Exception e) {
                            logger.error("Problem processing file: {} -- Error message: {}",
                                    filePath.getFileName(), e.getMessage());
                        }
                    } else {
                        logger.warn("Not a file so not processing: {}", filePath.toString()); // could be a directory but not recursing
                    }
                }
                dirStream.close();
            }
        } else {
            logger.debug("About to process file: {}", inputFile.getPath());
            try {
                convert.examine(inputFile);
            } catch (Exception e) {
                logger.error("Problem processing file: {} -- Error message: {}", inputFile.getName(),
                        e.getMessage());
                logger.debug("Problem processing file: {} -- Error message: {}", inputFile.getName(),
                        e.getMessage(), e);
            }
        }
    } else {
        System.err.println("Missing required option: " + PARAM_I);
        displayHelp();
        System.exit(-1);
    }

    System.exit(0);
}

From source file:edu.oregonstate.eecs.mcplan.abstraction.EvaluateSimilarityFunction.java

/**
 * @param args/*from  w  w  w.ja  va2s . c o  m*/
 * @throws IOException
 * @throws FileNotFoundException
 */
public static void main(final String[] args) throws FileNotFoundException, IOException {
    final String experiment_file = args[0];
    final File root_directory;
    if (args.length > 1) {
        root_directory = new File(args[1]);
    } else {
        root_directory = new File(".");
    }
    final CsvConfigurationParser csv_config = new CsvConfigurationParser(new FileReader(experiment_file));
    final String experiment_name = FilenameUtils.getBaseName(experiment_file);

    final File expr_directory = new File(root_directory, experiment_name);
    expr_directory.mkdirs();

    final Csv.Writer csv = new Csv.Writer(
            new PrintStream(new FileOutputStream(new File(expr_directory, "results.csv"))));
    final String[] parameter_headers = new String[] { "kpca.kernel", "kpca.rbf.sigma",
            "kpca.random_forest.Ntrees", "kpca.random_forest.max_depth", "kpca.Nbases", "multiclass.classifier",
            "multiclass.random_forest.Ntrees", "multiclass.random_forest.max_depth",
            "pairwise_classifier.max_branching", "training.label_noise" };
    csv.cell("domain").cell("abstraction");
    for (final String p : parameter_headers) {
        csv.cell(p);
    }
    csv.cell("Ntrain").cell("Ntest").cell("ami.mean").cell("ami.variance").cell("ami.confidence").newline();

    for (int expr = 0; expr < csv_config.size(); ++expr) {
        try {
            final KeyValueStore expr_config = csv_config.get(expr);
            final Configuration config = new Configuration(root_directory.getPath(), expr_directory.getName(),
                    expr_config);

            System.out.println("[Loading '" + config.training_data_single + "']");
            final Instances single = WekaUtil
                    .readLabeledDataset(new File(root_directory, config.training_data_single + ".arff"));

            final Instances train = new Instances(single, 0);
            final int[] idx = Fn.range(0, single.size());
            int instance_counter = 0;
            Fn.shuffle(config.rng, idx);
            final int Ntrain = config.getInt("Ntrain_games"); // TODO: Rename?
            final double label_noise = config.getDouble("training.label_noise");
            final int Nlabels = train.classAttribute().numValues();
            assert (Nlabels > 0);
            for (int i = 0; i < Ntrain; ++i) {
                final Instance inst = single.get(idx[instance_counter++]);
                if (label_noise > 0 && config.rng.nextDouble() < label_noise) {
                    int noisy_label = 0;
                    do {
                        noisy_label = config.rng.nextInt(Nlabels);
                    } while (noisy_label == (int) inst.classValue());
                    System.out.println("Noisy label (" + inst.classValue() + " -> " + noisy_label + ")");
                    inst.setClassValue(noisy_label);
                }
                train.add(inst);
                inst.setDataset(train);
            }

            final Fn.Function2<Boolean, Instance, Instance> plausible_p = createPlausiblePredicate(config);

            final int Ntest = config.Ntest_games;
            int Ntest_added = 0;
            final ArrayList<Instances> tests = new ArrayList<Instances>();
            while (instance_counter < single.size() && Ntest_added < Ntest) {
                final Instance inst = single.get(idx[instance_counter++]);
                boolean found = false;
                for (final Instances test : tests) {
                    // Note that 'plausible_p' should be transitive
                    if (plausible_p.apply(inst, test.get(0))) {
                        WekaUtil.addInstance(test, inst);
                        if (test.size() == 30) {
                            Ntest_added += test.size();
                        } else if (test.size() > 30) {
                            Ntest_added += 1;
                        }
                        found = true;
                        break;
                    }
                }

                if (!found) {
                    final Instances test = new Instances(single, 0);
                    WekaUtil.addInstance(test, inst);
                    tests.add(test);
                }
            }
            final Iterator<Instances> test_itr = tests.iterator();
            while (test_itr.hasNext()) {
                if (test_itr.next().size() < 30) {
                    test_itr.remove();
                }
            }
            System.out.println("=== tests.size() = " + tests.size());
            System.out.println("=== Ntest_added = " + Ntest_added);

            System.out.println("[Training]");
            final Evaluator evaluator = createEvaluator(config, train);
            //            final Instances transformed_test = evaluator.prepareInstances( test );

            System.out.println("[Evaluating]");

            final int Nxval = evaluator.isSensitiveToOrdering() ? 10 : 1;
            final MeanVarianceAccumulator ami = new MeanVarianceAccumulator();

            final MeanVarianceAccumulator errors = new MeanVarianceAccumulator();
            final MeanVarianceAccumulator relative_error = new MeanVarianceAccumulator();

            int c = 0;
            for (int xval = 0; xval < Nxval; ++xval) {
                for (final Instances test : tests) {
                    // TODO: Debugging
                    WekaUtil.writeDataset(new File(config.root_directory), "test_" + (c++), test);

                    //               transformed_test.randomize( new RandomAdaptor( config.rng ) );
                    //               final ClusterContingencyTable ct = evaluator.evaluate( transformed_test );
                    test.randomize(new RandomAdaptor(config.rng));
                    final ClusterContingencyTable ct = evaluator.evaluate(test);
                    System.out.println(ct);

                    int Nerrors = 0;
                    final MeanVarianceAccumulator mv = new MeanVarianceAccumulator();
                    for (int i = 0; i < ct.R; ++i) {
                        final int max = Fn.max(ct.n[i]);
                        Nerrors += (ct.a[i] - max);
                        mv.add(((double) ct.a[i]) / ct.N * Nerrors / ct.a[i]);
                    }
                    errors.add(Nerrors);
                    relative_error.add(mv.mean());

                    System.out.println("exemplar: " + test.get(0));
                    System.out.println("Nerrors = " + Nerrors);
                    final PrintStream ct_out = new PrintStream(
                            new FileOutputStream(new File(expr_directory, "ct_" + expr + "_" + xval + ".csv")));
                    ct.writeCsv(ct_out);
                    ct_out.close();
                    final double ct_ami = ct.adjustedMutualInformation_max();
                    if (Double.isNaN(ct_ami)) {
                        System.out.println("! ct_ami = NaN");
                    } else {
                        ami.add(ct_ami);
                    }
                    System.out.println();
                }
            }
            System.out.println("errors = " + errors.mean() + " (" + errors.confidence() + ")");
            System.out.println(
                    "relative_error = " + relative_error.mean() + " (" + relative_error.confidence() + ")");
            System.out.println("AMI_max = " + ami.mean() + " (" + ami.confidence() + ")");

            csv.cell(config.domain).cell(config.get("abstraction.discovery"));
            for (final String p : parameter_headers) {
                csv.cell(config.get(p));
            }
            csv.cell(Ntrain).cell(Ntest).cell(ami.mean()).cell(ami.variance()).cell(ami.confidence()).newline();
        } catch (final Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.linkedin.mlease.regression.liblinearfunc.LibLinear.java

/**
 * Command-line tool//from   w  w  w.  jav a 2 s . c  om
 * 
 * <pre>
 * java -cp target/regression-0.1-uber.jar com.linkedin.lab.regression.LibLinear
 * </pre>
 * 
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {

    String cmd = "Input parameters (separated by space): \n"
            + "   run:<command>      (required) train or predict\n"
            + "   ftype:<file_type>  (required) libsvm or json\n"
            + "   data:<file_name>   (required) Input data file of the specified type\n"
            + "   out:<file_name>    (required) Output file\n"
            + "   bias:<bias>        (optional) Set to 0 if you do not want to add an\n"
            + "                                 bias/intercept term\n"
            + "                                 Set to 1 if you want to add a feature with\n"
            + "                                 value 1 to every instance\n"
            + "                                 Default: 0\n"
            + "   param:<file_name>  (optional) for run:train, it specifies the prior mean\n"
            + "                      (required) for run:predict, it specifies the model\n"
            + "                                 File format: <featureName>=<value> per line\n"
            + "   priorVar:<var>     (required) for run:train, <var> is the a number\n"
            + "                      (not used) for run:predict\n"
            + "   init:<file_name>   (optional) for run:train, it specifies the initial value\n"
            + "                                 File format: <featureName>=<value> per line\n"
            + "   posteriorVar:1/0   (optional) Whether to compute posterior variances\n"
            + "                                 Default: 1\n"
            + "   posteriorCov:1/0   (optional) Whether to compute posterior covariances\n"
            + "                                 Default: 0\n"
            + "   binaryFeature:1/0  (optional) Whether all of the input features are binary\n"
            + "   useShort:1/0       (optional) Whether to use short to store feature indices\n"
            + "   option:<options>   (optional) Comma-separated list of options\n"
            + "                                 No space is allowed in <options>\n"
            + "                                 Eg: max_iter=5,epsilon=0.01,positive_weight=2\n"
            + "                      (not used) for run:predict\n";

    if (args.length < 3) {
        System.out.println("\n" + cmd);
        System.exit(0);
    }

    // Read the input parameters
    String run = null;
    String ftype = null;
    File dataFile = null;
    File outFile = null;
    double bias = 0;
    File paramFile = null;
    File initFile = null;
    double priorVar = Double.NaN;
    String option = null;
    boolean binaryFeature = false;
    boolean useShort = false;
    boolean computePostVar = true;
    boolean computePostCov = false;

    for (int i = 0; i < args.length; i++) {
        if (args[i] == null)
            continue;
        String[] token = args[i].split(":");
        if (token.length < 2)
            cmd_line_error("'" + args[i] + "' is not a valid input parameter string!", cmd);
        for (int k = 2; k < token.length; k++)
            token[1] += ":" + token[k];
        if (token[0].equals("run")) {
            run = token[1];
        } else if (token[0].equals("ftype")) {
            ftype = token[1];
        } else if (token[0].equals("data")) {
            dataFile = new File(token[1]);
        } else if (token[0].equals("out")) {
            outFile = new File(token[1]);
        } else if (token[0].equals("bias")) {
            bias = Double.parseDouble(token[1]);
        } else if (token[0].equals("param")) {
            paramFile = new File(token[1]);
        } else if (token[0].equals("init")) {
            initFile = new File(token[1]);
        } else if (token[0].equals("priorVar")) {
            priorVar = Double.parseDouble(token[1]);
        } else if (token[0].equals("option")) {
            option = token[1];
        } else if (token[0].equals("binaryFeature")) {
            binaryFeature = Util.atob(token[1]);
        } else if (token[0].equals("useShort")) {
            useShort = Util.atob(token[1]);
        } else if (token[0].equals("posteriorVar")) {
            computePostVar = Util.atob(token[1]);
        } else if (token[0].equals("posteriorCov")) {
            computePostCov = Util.atob(token[1]);
        } else
            cmd_line_error("'" + args[i] + "' is not a valid input parameter string!", cmd);
    }

    if (run == null)
        cmd_line_error("Please specify run:<command>", cmd);
    if (ftype == null)
        cmd_line_error("Please specify ftype:<file_type>", cmd);
    if (dataFile == null)
        cmd_line_error("Please specify data:<file_name>", cmd);
    if (outFile == null)
        cmd_line_error("Please specify out:<file_name>", cmd);

    if (run.equals(RUN_TRAIN)) {

        Map<String, Double> priorMean = null;
        Map<String, Double> initParam = null;
        if (paramFile != null) {
            if (!paramFile.exists())
                cmd_line_error("Param File '" + paramFile.getPath() + "' does not exist", cmd);
            priorMean = Util.readStringDoubleMap(paramFile, "=");
        }
        if (initFile != null) {
            if (!initFile.exists())
                cmd_line_error("Init File '" + initFile.getPath() + "' does not exist", cmd);
            initParam = Util.readStringDoubleMap(initFile, "=");
        }

        if (priorVar == Double.NaN)
            cmd_line_error("Please specify priorVar:<var>", cmd);

        if (!dataFile.exists())
            cmd_line_error("Data File '" + dataFile.getPath() + "' does not exist", cmd);

        LibLinearDataset dataset;
        if (binaryFeature) {
            dataset = new LibLinearBinaryDataset(bias, useShort);
        } else {
            dataset = new LibLinearDataset(bias);
        }

        if ("libsvm".equals(ftype)) {
            dataset.readFromLibSVM(dataFile);
        }
        //else if ("json".equals(ftype))
        //{
        //  dataset.readFromJSON(dataFile);
        //}
        else
            cmd_line_error("Unknown file type 'ftype:" + ftype + "'", cmd);

        if (computePostCov == true && computePostVar == false)
            cmd_line_error("Cannot compute posterior covariances with posteriorVar:0", cmd);

        LibLinear liblinear = new LibLinear();
        liblinear.setComputeFullPostVar(computePostCov);

        liblinear.train(dataset, initParam, priorMean, null, 0.0, priorVar, option, computePostVar);

        PrintStream out = new PrintStream(outFile);
        Util.printStringDoubleMap(out, liblinear.getParamMap(), "=", true);
        out.close();

        if (computePostVar) {
            out = new PrintStream(outFile + ".var");
            Util.printStringDoubleMap(out, liblinear.getPostVarMap(), "=", true);
            out.close();
            if (computePostCov) {
                out = new PrintStream(outFile + ".cov");
                Util.printStringListDoubleMap(out, liblinear.getPostVarMatrixMap(), "=");
                out.close();
            }
        }
    } else if (run.equals(RUN_PREDICT)) {

        throw new Exception("run:predict is not supported yet :(");

    } else
        cmd_line_error("Unknown run:" + run, cmd);
}

From source file:edu.cuhk.hccl.cmd.AppSearchEngine.java

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

    // Get parameters
    CommandLineParser parser = new BasicParser();
    Options options = createOptions();//  w w  w . j  a  v  a 2s  . c om

    File dataFolder = null;
    String queryStr = null;
    int topK = 0;
    File resultFile = null;
    String queryType = null;
    File similarityFile = null;

    try {
        CommandLine line = parser.parse(options, args);

        dataFolder = new File(line.getOptionValue('d'));
        queryStr = line.getOptionValue('q');
        queryType = line.getOptionValue('t');

        topK = Integer.parseInt(line.getOptionValue('k'));
        resultFile = new File(line.getOptionValue('f'));
        similarityFile = new File(line.getOptionValue('s'));

        if (line.hasOption('m')) {
            String modelPath = line.getOptionValue('m');

            if (queryType.equalsIgnoreCase("WordVector")) {
                expander = new WordVectorExpander(modelPath);
            } else if (queryType.equalsIgnoreCase("WordNet")) {
                expander = new WordNetExpander(modelPath);
            } else {
                System.out.println("Please choose a correct expander: WordNet or WordVector!");
                System.exit(-1);
            }
        }

    } catch (ParseException exp) {
        System.out.println("Error in parameters: \n" + exp.getMessage());
        System.exit(-1);
    }

    // Create Index
    StandardAnalyzer analyzer = new StandardAnalyzer();
    Directory index = createIndex(dataFolder, analyzer);

    // Build query
    Query query = buildQuery(analyzer, queryStr, queryType);

    // Search index for topK hits
    IndexReader reader = DirectoryReader.open(index);
    IndexSearcher searcher = new IndexSearcher(reader);
    TopScoreDocCollector collector = TopScoreDocCollector.create(topK, true);
    searcher.search(query, collector);
    ScoreDoc[] hits = collector.topDocs().scoreDocs;

    // Show search results
    System.out.println("\n[INFO] " + hits.length + " hits were returned:");
    List<String> hitLines = new ArrayList<String>();

    for (int i = 0; i < hits.length; i++) {
        int docId = hits[i].doc;
        Document d = searcher.doc(docId);

        String line = (i + 1) + "\t" + d.get(PATH_FIELD) + "\t" + hits[i].score;

        System.out.println(line);

        hitLines.add(line);
    }

    // Compute cosine similarity between documents
    List<String> simLines = new ArrayList<String>();
    for (int m = 0; m < hits.length; m++) {
        int doc1 = hits[m].doc;
        Terms terms1 = reader.getTermVector(doc1, CONTENT_FIELD);

        for (int n = m + 1; n < hits.length; n++) {
            int doc2 = hits[n].doc;
            Terms terms2 = reader.getTermVector(doc2, CONTENT_FIELD);

            CosineDocumentSimilarity cosine = new CosineDocumentSimilarity(terms1, terms2);
            double similarity = cosine.getCosineSimilarity();
            String line = searcher.doc(doc1).get(PATH_FIELD) + "\t" + searcher.doc(doc2).get(PATH_FIELD) + "\t"
                    + similarity;
            simLines.add(line);
        }
    }

    // Release resources
    reader.close();
    if (expander != null) {
        expander.close();
    }

    // Save search results
    System.out.println("\n[INFO] Search results are saved in file: " + resultFile.getPath());
    FileUtils.writeLines(resultFile, hitLines, false);

    System.out.println("\n[INFO] Cosine similarities are saved in file: " + similarityFile.getPath());
    FileUtils.writeLines(similarityFile, simLines, false);
}

From source file:edu.oregonstate.eecs.mcplan.abstraction.Experiments.java

/**
 * @param args//from   w w w .  ja  v a 2s .  co  m
 * @throws FileNotFoundException
 */
public static void main(final String[] args) throws Exception {
    final String experiment_file = args[0];
    final File root_directory;
    if (args.length > 1) {
        root_directory = new File(args[1]);
    } else {
        root_directory = new File(".");
    }
    final CsvConfigurationParser csv_config = new CsvConfigurationParser(new FileReader(experiment_file));
    final String experiment_name = FilenameUtils.getBaseName(experiment_file);

    final File expr_directory = new File(root_directory, experiment_name);
    expr_directory.mkdirs();

    for (int expr = 0; expr < csv_config.size(); ++expr) {
        final KeyValueStore expr_config = csv_config.get(expr);
        final Configuration config = new Configuration(root_directory.getPath(), experiment_name, expr_config);

        if ("irrelevance".equals(config.domain)) {
            final IrrelevanceDomain domain = new IrrelevanceDomain(config, 10);
            runExperiment(config, domain);
        } else if ("chain_walk".equals(config.domain)) {
            final ChainWalkDomain domain = new ChainWalkDomain(config);
            runExperiment(config, domain);
        } else if ("blackjack".equals(config.domain)) {
            final BlackjackDomain domain = new BlackjackDomain(config);
            runExperiment(config, domain);
        } else if ("taxi".equals(config.domain)) {
            final TaxiDomain domain = new TaxiDomain(config);
            runExperiment(config, domain);
        } else if ("yahtzee".equals(config.domain)) {
            final YahtzeeDomain domain = new YahtzeeDomain(config);
            runExperiment(config, domain);
        } else if ("frogger".equals(config.domain)) {
            final FroggerDomain domain = new FroggerDomain(config);
            runExperiment(config, domain);
        } else if ("racegrid".equals(config.domain)) {
            final RacegridDomain domain = new RacegridDomain(config);
            runExperiment(config, domain);
        } else if ("race_car".equals(config.domain)) {
            final RaceCarDomain domain = new RaceCarDomain(config);
            runExperiment(config, domain);
        } else if ("tamarisk".equals(config.domain)) {
            final TamariskDomain domain = new TamariskDomain(config);
            runExperiment(config, domain);
        } else if ("fuelworld".equals(config.domain)) {
            final FuelWorldDomain domain = new FuelWorldDomain(config);
            runExperiment(config, domain);
        } else if ("cliffworld".equals(config.domain)) {
            final CliffWorldDomain domain = new CliffWorldDomain(config);
            runExperiment(config, domain);
        } else if ("rddl".equals(config.domain)) {
            final RddlDomain domain = new RddlDomain(config);
            runExperiment(config, domain);
        } else {
            throw new IllegalArgumentException("domain = " + config.domain);
        }
    }
}

From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.Rsa2Tg.java

/**
 * Processes an XMI-file to a TG-file as schema or a schema in a grUML
 * graph. For all command line options see
 * {@link Rsa2Tg#processCommandLineOptions(String[])}.
 * /* ww  w. j a v  a2 s .  c  o m*/
 * @param args
 *            {@link String} array of command line options.
 * @throws IOException
 */
public static void main(String[] args) throws IOException {

    System.out.println("RSA to TG");
    System.out.println("=========");
    JGraLab.setLogLevel(Level.OFF);

    // Retrieving all command line options
    CommandLine cli = processCommandLineOptions(args);

    assert cli != null : "No CommandLine object has been generated!";
    // All XMI input files
    File input = new File(cli.getOptionValue('i'));

    Rsa2Tg r = new Rsa2Tg();

    r.setUseFromRole(cli.hasOption(OPTION_USE_ROLE_NAME));
    r.setRemoveUnusedDomains(cli.hasOption(OPTION_REMOVE_UNUSED_DOMAINS));
    r.setKeepEmptyPackages(cli.hasOption(OPTION_KEEP_EMPTY_PACKAGES));
    r.setUseNavigability(cli.hasOption(OPTION_USE_NAVIGABILITY));
    r.setRemoveComments(cli.hasOption(OPTION_REMOVE_COMMENTS));
    r.setIgnoreUnknownStereotypes(cli.hasOption(OPTION_IGNORE_UNKNOWN_STEREOTYPES));

    // apply options
    r.setFilenameSchema(cli.getOptionValue(OPTION_FILENAME_SCHEMA));
    r.setFilenameSchemaGraph(cli.getOptionValue(OPTION_FILENAME_SCHEMA_GRAPH));
    r.setFilenameDot(cli.getOptionValue(OPTION_FILENAME_DOT));
    r.setFilenameValidation(cli.getOptionValue(OPTION_FILENAME_VALIDATION));

    // If no output option is selected, Rsa2Tg will write at least the
    // schema file.
    boolean noOutputOptionSelected = !cli.hasOption(OPTION_FILENAME_SCHEMA)
            && !cli.hasOption(OPTION_FILENAME_SCHEMA_GRAPH) && !cli.hasOption(OPTION_FILENAME_DOT)
            && !cli.hasOption(OPTION_FILENAME_VALIDATION);
    if (noOutputOptionSelected) {
        System.out
                .println("No output option has been selected. " + "A TG-file for the Schema will be written.");

        // filename have to be set
        r.setFilenameSchema(createFilename(input));
    }

    try {
        System.out.println("processing: " + input.getPath() + "\n");
        r.process(input.getPath());
    } catch (Exception e) {
        System.err.println("An Exception occured while processing " + input + ".");
        System.err.println(e.getMessage());
        e.printStackTrace();
    }

    System.out.println("Fini.");
}

From source file:de.uni_koblenz.jgralab.utilities.rsa.Rsa2Tg.java

/**
 * Processes an XMI-file to a TG-file as schema or a schema in a grUML
 * graph. For all command line options see
 * {@link Rsa2Tg#processCommandLineOptions(String[])}.
 * /*from   www . j av a  2 s .  c  o  m*/
 * @param args
 *            {@link String} array of command line options.
 * @throws IOException
 */
public static void main(String[] args) throws IOException {

    System.out.println("RSA to DHHTG");
    System.out.println("=========");
    JGraLab.setLogLevel(Level.OFF);

    // Retrieving all command line options
    CommandLine cli = processCommandLineOptions(args);

    assert cli != null : "No CommandLine object has been generated!";
    // All XMI input files
    File input = new File(cli.getOptionValue('i'));

    Rsa2Tg r = new Rsa2Tg();

    r.setUseFromRole(cli.hasOption(OPTION_USE_ROLE_NAME));
    r.setRemoveUnusedDomains(cli.hasOption(OPTION_REMOVE_UNUSED_DOMAINS));
    r.setKeepEmptyPackages(cli.hasOption(OPTION_KEEP_EMPTY_PACKAGES));
    r.setUseNavigability(cli.hasOption(OPTION_USE_NAVIGABILITY));

    // apply options
    r.setFilenameSchema(cli.getOptionValue(OPTION_FILENAME_SCHEMA));
    r.setFilenameSchemaGraph(cli.getOptionValue(OPTION_FILENAME_SCHEMA_GRAPH));
    r.setFilenameDot(cli.getOptionValue(OPTION_FILENAME_DOT));
    r.setFilenameValidation(cli.getOptionValue(OPTION_FILENAME_VALIDATION));

    // If no output option is selected, Rsa2Tg will write at least the
    // schema file.
    boolean noOutputOptionSelected = !cli.hasOption(OPTION_FILENAME_SCHEMA)
            && !cli.hasOption(OPTION_FILENAME_SCHEMA_GRAPH) && !cli.hasOption(OPTION_FILENAME_DOT)
            && !cli.hasOption(OPTION_FILENAME_VALIDATION);
    if (noOutputOptionSelected) {
        System.out.println(
                "No output option has been selected. " + "A DHHTG-file for the Schema will be written.");

        // filename have to be set
        r.setFilenameSchema(createFilename(input));
    }

    try {
        System.out.println("processing: " + input.getPath() + "\n");
        r.process(input.getPath());
    } catch (Exception e) {
        System.err.println("An Exception occured while processing " + input + ".");
        System.err.println(e.getMessage());
        e.printStackTrace();
    }

    System.out.println("Fini.");
}

From source file:Main.java

private static String getPath(File mediaStorageDir) {
    return mediaStorageDir.getPath() + File.separator;
}

From source file:Main.java

public static String getFrescoLocalFile(File file) {
    return "file://" + file.getPath();
}

From source file:Main.java

public static boolean isAvailableExternalMemory(File paramFile) {
    StatFs localStatFs = new StatFs(paramFile.getPath());
    return (int) (localStatFs.getBlockSize() * localStatFs.getAvailableBlocks() / 1048576L) > 15;
}