Example usage for java.io File getAbsolutePath

List of usage examples for java.io File getAbsolutePath

Introduction

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

Prototype

public String getAbsolutePath() 

Source Link

Document

Returns the absolute pathname string of this abstract pathname.

Usage

From source file:es.eucm.ead.exporter.ExporterMain.java

@SuppressWarnings("all")
public static void main(String args[]) {

    Options options = new Options();

    Option help = new Option("h", "help", false, "print this message");
    Option quiet = new Option("q", "quiet", false, "be extra quiet");
    Option verbose = new Option("v", "verbose", false, "be extra verbose");

    Option legacy = OptionBuilder.withArgName("s> <t").hasArgs(3)
            .withDescription(/* www. j  ava 2s . com*/
                    "source is a version 1.x game; must specify\n" + "<simplify> if 'true', simplifies result\n"
                            + "<translate> if 'true', enables translation")
            .withLongOpt("import").create("i");

    Option war = OptionBuilder.withArgName("web-base").hasArg()
            .withDescription("WAR packaging (web app); " + "must specify\n<web-base> the base WAR directory")
            .withLongOpt("war").create("w");

    Option jar = OptionBuilder.withDescription("JAR packaging (desktop)").withLongOpt("jar").create("j");

    Option apk = OptionBuilder.withArgName("props> <adk> <d").hasArgs(3)
            .withDescription("APK packaging (android); must specify \n" + "<props> (a properties file) \n"
                    + "<adk> (location of the ADK to use) \n" + "<deploy> ('true' to install & deploy)")
            .withLongOpt("apk").create("a");

    // EAD option
    Option ead = OptionBuilder.withDescription("EAD packaging (eAdventure)").withLongOpt("ead").create("e");

    options.addOption(legacy);
    options.addOption(help);
    options.addOption(quiet);
    options.addOption(verbose);
    options.addOption(jar);
    options.addOption(war);
    options.addOption(apk);
    options.addOption(ead);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException pe) {
        System.err.println("Error parsing command-line: " + pe.getMessage());
        showHelp(options);
        return;
    }

    // general options

    String[] extras = cmd.getArgs();

    if (cmd.hasOption(help.getOpt()) || extras.length < 2) {
        showHelp(options);
        return;
    }
    if (cmd.hasOption(verbose.getOpt())) {
        verbosity = Verbose;
    }
    if (cmd.hasOption(quiet.getOpt())) {
        verbosity = Quiet;
    }

    // import

    String source = extras[0];

    // optional import step
    if (cmd.hasOption(legacy.getOpt())) {
        String[] values = cmd.getOptionValues(legacy.getOpt());

        AdventureConverter converter = new AdventureConverter();
        if (values.length > 0 && values[0].equalsIgnoreCase("true")) {
            converter.setEnableSimplifications(true);
        }
        if (values.length > 1 && values[1].equalsIgnoreCase("true")) {
            converter.setEnableTranslations(true);
        }

        // set source for next steps to import-target
        source = converter.convert(source, null);
    }

    if (cmd.hasOption(jar.getOpt())) {
        if (checkFilesExist(cmd, options, source)) {
            JarExporter e = new JarExporter();
            e.export(source, extras[1], verbosity.equals(Quiet) ? new QuietStream() : System.err);
        }
    } else if (cmd.hasOption(apk.getOpt())) {
        String[] values = cmd.getOptionValues(apk.getOpt());
        if (checkFilesExist(cmd, options, values[0], values[1], source)) {
            AndroidExporter e = new AndroidExporter();
            Properties props = new Properties();
            File propsFile = new File(values[0]);
            try {
                props.load(new FileReader(propsFile));
                props.setProperty(AndroidExporter.SDK_HOME,
                        props.getProperty(AndroidExporter.SDK_HOME, values[1]));
            } catch (IOException ioe) {
                System.err.println("Could not load properties from " + propsFile.getAbsolutePath());
                return;
            }
            e.export(source, extras[1], props, values.length > 2 && values[2].equalsIgnoreCase("true"));
        }
    } else if (cmd.hasOption(war.getOpt())) {
        if (checkFilesExist(cmd, options, extras[0])) {
            WarExporter e = new WarExporter();
            e.setWarPath(cmd.getOptionValue(war.getOpt()));
            e.export(source, extras[1]);
        }
    } else if (cmd.hasOption(ead.getOpt())) {
        String destiny = extras[1];
        if (!destiny.endsWith(".ead")) {
            destiny += ".ead";
        }
        FileUtils.zip(new File(destiny), new File(source));
    } else {
        showHelp(options);
    }
}

From source file:appmain.AppMain.java

public static void main(String[] args) {

    try {/*from   ww w  . j av  a 2 s  .  c  o m*/
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        UIManager.put("OptionPane.yesButtonText", "Igen");
        UIManager.put("OptionPane.noButtonText", "Nem");
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {

        AppMain app = new AppMain();
        app.init();

        File importFolder = new File(DEFAULT_IMPORT_FOLDER);
        if (!importFolder.isDirectory() || !importFolder.exists()) {
            JOptionPane.showMessageDialog(null,
                    "Az IMPORT mappa nem elrhet!\n"
                            + "Ellenrizze az elrsi utat s a jogosultsgokat!\n" + "Mappa: "
                            + importFolder.getAbsolutePath(),
                    "Informci", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        File exportFolder = new File(DEFAULT_EXPORT_FOLDER);
        if (!exportFolder.isDirectory() || !exportFolder.exists()) {
            JOptionPane.showMessageDialog(null,
                    "Az EXPORT mappa nem elrhet!\n"
                            + "Ellenrizze az elrsi utat s a jogosultsgokat!\n" + "Mappa: "
                            + exportFolder.getAbsolutePath(),
                    "Informci", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        List<File> xmlFiles = app.getXMLFiles(importFolder);
        if (xmlFiles == null || xmlFiles.isEmpty()) {
            JOptionPane.showMessageDialog(null,
                    "Nincs beolvasand XML fjl!\n" + "Mappa: " + importFolder.getAbsolutePath(),
                    "Informci", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        StringBuilder fileList = new StringBuilder();
        xmlFiles.stream().forEach(xml -> fileList.append("\n").append(xml.getName()));
        int ret = JOptionPane.showConfirmDialog(null,
                "Beolvassra elksztett fjlok:\n" + fileList + "\n\nIndulhat a feldolgozs?",
                "Megtallt XML fjlok", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

        if (ret == JOptionPane.OK_OPTION) {
            String csvName = "tranzakcio_lista_" + df.format(new Date()) + "_" + System.currentTimeMillis()
                    + ".csv";
            File csv = new File(DEFAULT_EXPORT_FOLDER + "/" + csvName);
            app.writeCSV(csv, Arrays.asList(app.getHeaderLine()));
            xmlFiles.stream().forEach(xml -> {
                List<String> lines = app.readXMLData(xml);
                if (lines != null)
                    app.writeCSV(csv, lines);
            });
            if (csv.isFile() && csv.exists()) {
                JOptionPane.showMessageDialog(null,
                        "A CSV fjl sikeresen elllt!\n" + "Fjl: " + csv.getAbsolutePath(),
                        "Informci", JOptionPane.INFORMATION_MESSAGE);
                app.openFile(csv);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Feldolgozs megszaktva!", "Informci",
                    JOptionPane.INFORMATION_MESSAGE);
        }

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Nem kezelt kivtel!\n" + ExceptionUtils.getStackTrace(ex), "Hiba",
                JOptionPane.ERROR_MESSAGE);
    }

}

From source file:de.peran.DependencyReadingStarter.java

public static void main(final String[] args) throws ParseException, FileNotFoundException {
    final Options options = OptionConstants.createOptions(OptionConstants.FOLDER, OptionConstants.STARTVERSION,
            OptionConstants.ENDVERSION, OptionConstants.OUT);

    final CommandLineParser parser = new DefaultParser();
    final CommandLine line = parser.parse(options, args);

    final File projectFolder = new File(line.getOptionValue(OptionConstants.FOLDER.getName()));

    final File dependencyFile;
    if (line.hasOption(OptionConstants.OUT.getName())) {
        dependencyFile = new File(line.getOptionValue(OptionConstants.OUT.getName()));
    } else {//  ww  w. j  a v a  2s .c om
        dependencyFile = new File("dependencies.xml");
    }

    File outputFile = projectFolder.getParentFile();
    if (outputFile.isDirectory()) {
        outputFile = new File(projectFolder.getParentFile(), "ausgabe.txt");
    }

    LOG.debug("Lese {}", projectFolder.getAbsolutePath());
    final VersionControlSystem vcs = VersionControlSystem.getVersionControlSystem(projectFolder);

    System.setOut(new PrintStream(outputFile));
    // System.setErr(new PrintStream(outputFile));

    final DependencyReader reader;
    if (vcs.equals(VersionControlSystem.SVN)) {
        final String url = SVNUtils.getInstance().getWCURL(projectFolder);
        final List<SVNLogEntry> entries = getSVNCommits(line, url);
        LOG.debug("SVN commits: "
                + entries.stream().map(entry -> entry.getRevision()).collect(Collectors.toList()));
        reader = new DependencyReader(projectFolder, url, dependencyFile, entries);
    } else if (vcs.equals(VersionControlSystem.GIT)) {
        final List<GitCommit> commits = getGitCommits(line, projectFolder);
        reader = new DependencyReader(projectFolder, dependencyFile, commits);
        LOG.debug("Reader initalized");
    } else {
        throw new RuntimeException("Unknown version control system");
    }
    reader.readDependencies();
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step3AddRawDocumentsFromClueWeb.java

public static void main(String[] args) throws IOException {
    // input dir - list of xml query containers
    // step2a-retrieved-results
    File inputDir = new File(args[0]);

    // warc.bz file containing all required documents according to ClueWeb IDs
    // ltr-50queries-100docs-clueweb-export.warc.gz
    File warc = new File(args[1]);

    // output dir
    File outputDir = new File(args[2]);
    if (!outputDir.exists()) {
        outputDir.mkdirs();/*from w w  w . java  2 s.  c o m*/
    }

    // iterate over query containers
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));

        // iterate over warc for each query
        WARCFileReader reader = new WARCFileReader(new Configuration(), new Path(warc.getAbsolutePath()));
        try {
            while (true) {
                WARCRecord read = reader.read();
                String trecId = read.getHeader().getField("WARC-TREC-ID");

                // now iterate over retrieved results for the query and find matching IDs
                for (QueryResultContainer.SingleRankedResult rankedResults : queryResultContainer.rankedResults) {
                    if (rankedResults.clueWebID.equals(trecId)) {
                        // add the raw html content
                        String fullHTTPResponse = new String(read.getContent(), "utf-8");
                        // TODO fix coding?

                        String html = removeHTTPHeaders(fullHTTPResponse);

                        rankedResults.originalHtml = sanitizeXmlChars(html.trim());
                    }
                }
            }
        } catch (EOFException e) {
            // end of file
        }

        // check if all results have filled html
        for (QueryResultContainer.SingleRankedResult rankedResults : queryResultContainer.rankedResults) {
            if (rankedResults.originalHtml == null) {
                System.err.println("Missing original html for\t" + rankedResults.clueWebID
                        + ", setting relevance to false");
                rankedResults.relevant = Boolean.FALSE.toString();
            }
        }

        // and save the query to output dir
        File outputFile = new File(outputDir, queryResultContainer.qID + ".xml");
        FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8");
        System.out.println("Finished " + outputFile);
    }

}

From source file:gobblin.compaction.CompactionRunner.java

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

    if (args.length != 1) {
        LOG.info("Proper usage: java -jar compaction.jar <global-config-file>\n" + "or\n"
                + "hadoop jar compaction.jar <global-config-file>\n" + "or\n"
                + "yarn jar compaction.jar <global-config-file>\n");
        System.exit(1);/*w  w  w  . j av a2s .c o m*/
    }

    Configuration globalConfig = new PropertiesConfiguration(args[0]);
    properties = ConfigurationConverter.getProperties(globalConfig);

    File compactionConfigDir = new File(properties.getProperty(COMPACTION_CONFIG_DIR));
    File[] listOfFiles = compactionConfigDir.listFiles();
    if (listOfFiles == null || listOfFiles.length == 0) {
        System.err.println("No compaction configuration files found under " + compactionConfigDir);
        System.exit(1);
    }

    int numOfJobs = 0;
    for (File file : listOfFiles) {
        if (file.isFile() && !file.getName().startsWith(".")) {
            numOfJobs++;
        }
    }
    LOG.info("Found " + numOfJobs + " compaction tasks.");
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(
            new FileOutputStream(properties.getProperty(TIMING_FILE, TIMING_FILE_DEFAULT)),
            Charset.forName("UTF-8")));

    for (File file : listOfFiles) {
        if (file.isFile() && !file.getName().startsWith(".")) {
            Configuration jobConfig = new PropertiesConfiguration(file.getAbsolutePath());
            jobProperties = ConfigurationConverter.getProperties(jobConfig);
            long startTime = System.nanoTime();
            compact();
            long endTime = System.nanoTime();
            long elapsedTime = endTime - startTime;
            double seconds = TimeUnit.NANOSECONDS.toSeconds(elapsedTime);
            pw.printf("%s: %f%n", file.getAbsolutePath(), seconds);
        }
    }

    pw.close();
}

From source file:marytts.tools.voiceimport.DatabaseImportMain.java

public static void main(String[] args) throws Exception {
    File voiceDir = determineVoiceBuildingDir(args);
    if (voiceDir == null) {
        throw new IllegalArgumentException("Cannot determine voice building directory.");
    }/* w w  w  . j a  va  2  s .  co m*/
    File wavDir = new File(voiceDir, "wav");
    //System.out.println(System.getProperty("user.dir")+System.getProperty("file.separator")+"wav");
    assert wavDir.exists() : "no wav dir at " + wavDir.getAbsolutePath();

    /* Read the list of components */
    File importMainConfigFile = new File(voiceDir, "importMain.config");
    if (!importMainConfigFile.exists()) {
        FileUtils.copyInputStreamToFile(DatabaseImportMain.class.getResourceAsStream("importMain.config"),
                importMainConfigFile);
    }
    assert importMainConfigFile.exists();

    String[][] groups2comps = readComponentList(new FileInputStream(importMainConfigFile));

    VoiceImportComponent[] components = createComponents(groups2comps);

    /* Load DatabaseLayout */
    File configFile = new File(voiceDir, "database.config");

    DatabaseLayout db = new DatabaseLayout(configFile, components);
    if (!db.isInitialized())
        return;

    if (args.length > 0) { // non-gui mode: arguments are expected to be component names, in order or application
        for (String compName : args) {
            VoiceImportComponent component = null;
            for (VoiceImportComponent comp : components) {
                if (comp.getName().equals(compName)) {
                    component = comp;
                    break;
                }
            }
            if (component != null) {
                System.out.println("Running " + compName);
                component.compute();
            } else {
                throw new IllegalArgumentException("No such voice import component: " + compName);
            }

        }
    } else {
        /* Display GUI */
        String voicename = db.getProp(db.VOICENAME);
        DatabaseImportMain importer = new DatabaseImportMain("Database import: " + voicename, components, db,
                groups2comps);
        importer.pack();
        // Center window on screen:
        importer.setLocationRelativeTo(null);
        importer.setVisible(true);
    }

}

From source file:gobblin.compaction.hive.CompactionRunner.java

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

    properties = CliOptions.parseArgs(MRCompactionRunner.class, args);

    File compactionConfigDir = new File(properties.getProperty(COMPACTION_CONFIG_DIR));
    File[] listOfFiles = compactionConfigDir.listFiles();
    if (listOfFiles == null || listOfFiles.length == 0) {
        System.err.println("No compaction configuration files found under " + compactionConfigDir);
        System.exit(1);/* www  .  ja  v a  2s.c o  m*/
    }

    int numOfJobs = 0;
    for (File file : listOfFiles) {
        if (file.isFile() && !file.getName().startsWith(".")) {
            numOfJobs++;
        }
    }
    LOG.info("Found " + numOfJobs + " compaction tasks.");
    try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(
            new FileOutputStream(properties.getProperty(TIMING_FILE, TIMING_FILE_DEFAULT)),
            Charset.forName("UTF-8")))) {

        for (File file : listOfFiles) {
            if (file.isFile() && !file.getName().startsWith(".")) {
                Configuration jobConfig = new PropertiesConfiguration(file.getAbsolutePath());
                jobProperties = ConfigurationConverter.getProperties(jobConfig);
                long startTime = System.nanoTime();
                compact();
                long endTime = System.nanoTime();
                long elapsedTime = endTime - startTime;
                double seconds = TimeUnit.NANOSECONDS.toSeconds(elapsedTime);
                pw.printf("%s: %f%n", file.getAbsolutePath(), seconds);
            }
        }
    }
}

From source file:co.cask.cdap.etl.tool.UpgradeTool.java

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

    Options options = new Options().addOption(new Option("h", "help", false, "Print this usage message."))
            .addOption(new Option("u", "uri", true,
                    "CDAP instance URI to interact with in the format "
                            + "[http[s]://]<hostname>:<port>. Defaults to localhost:10000."))
            .addOption(new Option("a", "accesstoken", true,
                    "File containing the access token to use when interacting "
                            + "with a secure CDAP instance."))
            .addOption(new Option("t", "timeout", true,
                    "Timeout in milliseconds to use when interacting with the "
                            + "CDAP RESTful APIs. Defaults to " + DEFAULT_READ_TIMEOUT_MILLIS + "."))
            .addOption(new Option("n", "namespace", true,
                    "Namespace to perform the upgrade in. If none is given, "
                            + "pipelines in all namespaces will be upgraded."))
            .addOption(new Option("p", "pipeline", true,
                    "Name of the pipeline to upgrade. If specified, a namespace " + "must also be given."))
            .addOption(new Option("f", "configfile", true, "File containing old application details to update. "
                    + "The file contents are expected to be in the same format as the request body for creating an "
                    + "ETL application from one of the etl artifacts. "
                    + "It is expected to be a JSON Object containing 'artifact' and 'config' fields."
                    + "The value for 'artifact' must be a JSON Object that specifies the artifact scope, name, and version. "
                    + "The value for 'config' must be a JSON Object specifies the source, transforms, and sinks of the pipeline, "
                    + "as expected by older versions of the etl artifacts."))
            .addOption(new Option("o", "outputfile", true,
                    "File to write the converted application details provided in "
                            + "the configfile option. If none is given, results will be written to the input file + '.converted'. "
                            + "The contents of this file can be sent directly to CDAP to update or create an application."))
            .addOption(new Option("e", "errorDir", true,
                    "Optional directory to write any upgraded pipeline configs that "
                            + "failed to upgrade. The problematic configs can then be manually edited and upgraded separately. "
                            + "Upgrade errors may happen for pipelines that use plugins that are not backwards compatible. "
                            + "This directory must be writable by the user that is running this tool."));

    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = parser.parse(options, args);
    String[] commandArgs = commandLine.getArgs();

    // if help is an option, or if there isn't a single 'upgrade' command, print usage and exit.
    if (commandLine.hasOption("h") || commandArgs.length != 1 || !"upgrade".equalsIgnoreCase(commandArgs[0])) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(UpgradeTool.class.getName() + " upgrade",
                "Upgrades Hydrator pipelines created for 3.2.x versions"
                        + "of the cdap-etl-batch and cdap-etl-realtime artifacts into pipelines compatible with 3.3.x versions of "
                        + "cdap-etl-batch and cdap-etl-realtime. Connects to an instance of CDAP to find any 3.2.x pipelines, then "
                        + "upgrades those pipelines.",
                options, "");
        System.exit(0);//from   w w  w  .  j  a  v a  2 s . co  m
    }

    ClientConfig clientConfig = getClientConfig(commandLine);

    if (commandLine.hasOption("f")) {
        String inputFilePath = commandLine.getOptionValue("f");
        String outputFilePath = commandLine.hasOption("o") ? commandLine.getOptionValue("o")
                : inputFilePath + ".new";
        convertFile(inputFilePath, outputFilePath, new ArtifactClient(clientConfig));
        System.exit(0);
    }

    File errorDir = commandLine.hasOption("e") ? new File(commandLine.getOptionValue("e")) : null;
    if (errorDir != null) {
        if (!errorDir.exists()) {
            if (!errorDir.mkdirs()) {
                LOG.error("Unable to create error directory {}.", errorDir.getAbsolutePath());
                System.exit(1);
            }
        } else if (!errorDir.isDirectory()) {
            LOG.error("{} is not a directory.", errorDir.getAbsolutePath());
            System.exit(1);
        } else if (!errorDir.canWrite()) {
            LOG.error("Unable to write to error directory {}.", errorDir.getAbsolutePath());
            System.exit(1);
        }
    }
    UpgradeTool upgradeTool = new UpgradeTool(clientConfig, errorDir);

    String namespace = commandLine.getOptionValue("n");
    String pipelineName = commandLine.getOptionValue("p");

    if (pipelineName != null) {
        if (namespace == null) {
            throw new IllegalArgumentException("Must specify a namespace when specifying a pipeline.");
        }
        Id.Application appId = Id.Application.from(namespace, pipelineName);
        if (upgradeTool.upgrade(appId)) {
            LOG.info("Successfully upgraded {}.", appId);
        } else {
            LOG.info("{} did not need to be upgraded.", appId);
        }
        System.exit(0);
    }

    if (namespace != null) {
        printUpgraded(upgradeTool.upgrade(Id.Namespace.from(namespace)));
        System.exit(0);
    }

    printUpgraded(upgradeTool.upgrade());
}

From source file:eu.fbk.dkm.sectionextractor.pantheon.WikipediaGoodTextExtractor.java

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

    CommandLineWithLogger commandLineWithLogger = new CommandLineWithLogger();
    commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg()
            .withDescription("wikipedia xml dump file").isRequired().withLongOpt("wikipedia-dump").create("d"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("dir").hasArg()
            .withDescription("output directory in which to store output files").isRequired()
            .withLongOpt("output-dir").create("o"));
    commandLineWithLogger//from  ww w. j  ava 2  s .c om
            .addOption(OptionBuilder.withDescription("use NAF format").withLongOpt("naf").create("n"));
    commandLineWithLogger.addOption(OptionBuilder.withDescription("tokenize and ssplit with Stanford")
            .withLongOpt("stanford").create("s"));

    commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("Filter file")
            .withLongOpt("filter").create("f"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg()
            .withDescription("ID and category file").withLongOpt("idcat").create("i"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("Redirect file")
            .withLongOpt("redirect").create("r"));

    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription(
                    "number of threads (default " + AbstractWikipediaXmlDumpParser.DEFAULT_THREADS_NUMBER + ")")
            .withLongOpt("num-threads").create("t"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription("number of pages to process (default all)").withLongOpt("num-pages").create("p"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription("receive notification every n pages (default "
                    + AbstractWikipediaExtractor.DEFAULT_NOTIFICATION_POINT + ")")
            .withLongOpt("notification-point").create("b"));
    commandLineWithLogger.addOption(new Option("n", "NAF format"));

    CommandLine commandLine = null;
    try {
        commandLine = commandLineWithLogger.getCommandLine(args);
        PropertyConfigurator.configure(commandLineWithLogger.getLoggerProps());
    } catch (Exception e) {
        System.exit(1);
    }

    int numThreads = Integer.parseInt(commandLine.getOptionValue("num-threads",
            Integer.toString(AbstractWikipediaXmlDumpParser.DEFAULT_THREADS_NUMBER)));
    int numPages = Integer.parseInt(commandLine.getOptionValue("num-pages",
            Integer.toString(AbstractWikipediaExtractor.DEFAULT_NUM_PAGES)));
    int notificationPoint = Integer.parseInt(commandLine.getOptionValue("notification-point",
            Integer.toString(AbstractWikipediaExtractor.DEFAULT_NOTIFICATION_POINT)));

    boolean nafFormat = commandLine.hasOption("n");
    boolean useStanford = commandLine.hasOption("s");

    HashMap<Integer, String> idCategory = new HashMap<>();
    String idcatFileName = commandLine.getOptionValue("idcat");
    if (idcatFileName != null) {
        logger.info("Loading categories");
        File idcatFile = new File(idcatFileName);
        if (idcatFile.exists()) {
            List<String> lines = Files.readLines(idcatFile, Charsets.UTF_8);
            for (String line : lines) {
                line = line.trim();
                if (line.length() == 0) {
                    continue;
                }

                String[] parts = line.split("\\s+");
                if (parts.length < 3) {
                    continue;
                }

                idCategory.put(Integer.parseInt(parts[1]), parts[2]);
            }
        }
    }

    HashMap<String, String> redirects = new HashMap<>();
    String redirectFileName = commandLine.getOptionValue("redirect");
    if (redirectFileName != null) {
        logger.info("Loading redirects");
        File redirectFile = new File(redirectFileName);
        if (redirectFile.exists()) {
            List<String> lines = Files.readLines(redirectFile, Charsets.UTF_8);
            for (String line : lines) {
                line = line.trim();
                if (line.length() == 0) {
                    continue;
                }

                String[] parts = line.split("\\t+");
                if (parts.length < 2) {
                    continue;
                }

                redirects.put(parts[0], parts[1]);
            }
        }
    }

    HashSet<String> pagesToConsider = null;
    String filterFileName = commandLine.getOptionValue("filter");
    if (filterFileName != null) {
        logger.info("Loading file list");
        File filterFile = new File(filterFileName);
        if (filterFile.exists()) {
            pagesToConsider = new HashSet<>();
            List<String> lines = Files.readLines(filterFile, Charsets.UTF_8);
            for (String line : lines) {
                line = line.trim();
                if (line.length() == 0) {
                    continue;
                }

                line = line.replaceAll("\\s+", "_");

                pagesToConsider.add(line);

                addRedirects(pagesToConsider, redirects, line, 0);
            }
        }
    }

    ExtractorParameters extractorParameters = new ExtractorParameters(
            commandLine.getOptionValue("wikipedia-dump"), commandLine.getOptionValue("output-dir"));

    File outputFolder = new File(commandLine.getOptionValue("output-dir"));
    if (!outputFolder.exists()) {
        boolean mkdirs = outputFolder.mkdirs();
        if (!mkdirs) {
            throw new IOException("Unable to create folder " + outputFolder.getAbsolutePath());
        }
    }

    WikipediaExtractor wikipediaPageParser = new WikipediaGoodTextExtractor(numThreads, numPages,
            extractorParameters.getLocale(), outputFolder, nafFormat, pagesToConsider, useStanford, idCategory);
    wikipediaPageParser.setNotificationPoint(notificationPoint);
    wikipediaPageParser.start(extractorParameters);

    logger.info("extraction ended " + new Date());

}

From source file:main.java.RMDupper.java

public static void main(String[] args) throws IOException {
    System.err.println("DeDup v" + VERSION);
    // the command line parameters
    Options helpOptions = new Options();
    helpOptions.addOption("h", "help", false, "show this help page");
    Options options = new Options();
    options.addOption("h", "help", false, "show this help page");
    options.addOption("i", "input", true,
            "the input file if this option is not specified,\nthe input is expected to be piped in");
    options.addOption("o", "output", true, "the output folder. Has to be specified if input is set.");
    options.addOption("m", "merged", false,
            "the input only contains merged reads.\n If this option is specified read names are not examined for prefixes.\n Both the start and end of the aligment are considered for all reads.");
    options.addOption("v", "version", false, "the version of DeDup.");
    HelpFormatter helpformatter = new HelpFormatter();
    CommandLineParser parser = new BasicParser();
    try {/*from   www.  j  a  v a  2  s  . c o m*/
        CommandLine cmd = parser.parse(helpOptions, args);
        if (cmd.hasOption('h')) {
            helpformatter.printHelp(CLASS_NAME, options);
            System.exit(0);
        }
    } catch (ParseException e1) {
    }

    String input = "";
    String outputpath = "";
    Boolean merged = Boolean.FALSE;
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption('i')) {
            input = cmd.getOptionValue('i');
            piped = false;
        }
        if (cmd.hasOption('o')) {
            outputpath = cmd.getOptionValue('o');
        }
        if (cmd.hasOption('m')) {
            merged = Boolean.TRUE;
        }
        if (cmd.hasOption('v')) {
            System.out.println("DeDup v" + VERSION);
            System.exit(0);
        }
    } catch (ParseException e) {
        helpformatter.printHelp(CLASS_NAME, options);
        System.err.println(e.getMessage());
        System.exit(0);
    }
    DecimalFormat df = new DecimalFormat("##.##");

    if (piped) {
        RMDupper rmdup = new RMDupper(System.in, System.out, merged);
        rmdup.readSAMFile();

        System.err.println("We are in piping mode!");
        System.err.println("Total reads: " + rmdup.dupStats.total + "\n");
        System.err.println("Reverse removed: " + rmdup.dupStats.removed_reverse + "\n");
        System.err.println("Forward removed: " + rmdup.dupStats.removed_forward + "\n");
        System.err.println("Merged removed: " + rmdup.dupStats.removed_merged + "\n");
        System.err.println("Total removed: " + (rmdup.dupStats.removed_forward + rmdup.dupStats.removed_merged
                + rmdup.dupStats.removed_reverse) + "\n");
        if (rmdup.dupStats.removed_merged + rmdup.dupStats.removed_forward
                + rmdup.dupStats.removed_reverse == 0) {
            System.err.println("Duplication Rate: " + df.format(0.00));
        } else {
            System.err.println("Duplication Rate: "
                    + df.format((double) (rmdup.dupStats.removed_merged + rmdup.dupStats.removed_reverse
                            + rmdup.dupStats.removed_forward) / (double) rmdup.dupStats.total));
        }

    } else {
        if (outputpath.length() == 0) {
            System.err.println("The output folder has to be specified");
            helpformatter.printHelp(CLASS_NAME, options);
            System.exit(0);
        }

        //Check whether we have a directory as output path, else produce error message and quit!

        File f = new File(outputpath);
        if (!f.isDirectory()) {
            System.err.println("The output folder should be a folder and not a file!");
            System.exit(0);
        }

        File inputFile = new File(input);
        File outputFile = new File(
                outputpath + "/" + Files.getNameWithoutExtension(inputFile.getAbsolutePath()) + "_rmdup.bam");
        File outputlog = new File(
                outputpath + "/" + Files.getNameWithoutExtension(inputFile.getAbsolutePath()) + ".log");
        File outputhist = new File(
                outputpath + "/" + Files.getNameWithoutExtension(inputFile.getAbsolutePath()) + ".hist");

        try {
            FileWriter fw = new FileWriter(outputlog);
            FileWriter histfw = new FileWriter(outputhist);
            BufferedWriter bfw = new BufferedWriter(fw);
            BufferedWriter histbfw = new BufferedWriter(histfw);

            RMDupper rmdup = new RMDupper(inputFile, outputFile, merged);
            rmdup.readSAMFile();
            rmdup.inputSam.close();
            rmdup.outputSam.close();

            bfw.write("Total reads: " + rmdup.dupStats.total + "\n");
            bfw.write("Reverse removed: " + rmdup.dupStats.removed_reverse + "\n");
            bfw.write("Forward removed: " + rmdup.dupStats.removed_forward + "\n");
            bfw.write("Merged removed: " + rmdup.dupStats.removed_merged + "\n");
            bfw.write("Total removed: " + (rmdup.dupStats.removed_forward + rmdup.dupStats.removed_merged
                    + rmdup.dupStats.removed_reverse) + "\n");
            bfw.write("Duplication Rate: "
                    + df.format((double) (rmdup.dupStats.removed_merged + rmdup.dupStats.removed_reverse
                            + rmdup.dupStats.removed_forward) / (double) rmdup.dupStats.total));
            bfw.flush();
            bfw.close();

            histbfw.write(rmdup.oc.getHistogram());
            histbfw.flush();
            histbfw.close();

            System.out.println("Total reads: " + rmdup.dupStats.total + "\n");
            System.out.println("Unmerged removed: "
                    + (rmdup.dupStats.removed_forward + rmdup.dupStats.removed_reverse) + "\n");
            System.out.println("Merged removed: " + rmdup.dupStats.removed_merged + "\n");
            System.out.println("Total removed: " + (rmdup.dupStats.removed_forward
                    + rmdup.dupStats.removed_merged + rmdup.dupStats.removed_reverse) + "\n");
            if (rmdup.dupStats.removed_merged + rmdup.dupStats.removed_forward
                    + rmdup.dupStats.removed_reverse == 0) {
                System.out.println("Duplication Rate: " + df.format(0.00));
            } else {
                System.out.println("Duplication Rate: "
                        + df.format((double) (rmdup.dupStats.removed_merged + rmdup.dupStats.removed_reverse
                                + rmdup.dupStats.removed_forward) / (double) rmdup.dupStats.total));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}