Example usage for java.lang Integer parseInt

List of usage examples for java.lang Integer parseInt

Introduction

In this page you can find the example usage for java.lang Integer parseInt.

Prototype

public static int parseInt(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal integer.

Usage

From source file:com.opensoc.json.serialization.JSONKafkaSerializer.java

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

    //String Input = "/home/kiran/git/opensoc-streaming/OpenSOC-Common/BroExampleOutput";
    String Input = "/tmp/test";

    BufferedReader reader = new BufferedReader(new FileReader(Input));

    // String jsonString =
    // "{\"dns\":{\"ts\":[14.0,12,\"kiran\"],\"uid\":\"abullis@mail.csuchico.edu\",\"id.orig_h\":\"10.122.196.204\", \"endval\":null}}";
    String jsonString = "";// reader.readLine();
    JSONParser parser = new JSONParser();
    JSONObject json = null;// ww  w.j a  va2  s . c  o  m
    int count = 1;

    if (args.length > 0)
        count = Integer.parseInt(args[0]);

    //while ((jsonString = reader.readLine()) != null) 
    jsonString = reader.readLine();
    {
        try {
            json = (JSONObject) parser.parse(jsonString);
            System.out.println(json);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String jsonString2 = null;

        JSONKafkaSerializer ser = new JSONKafkaSerializer();

        for (int i = 0; i < count; i++) {
            byte[] bytes = ser.toBytes(json);

            jsonString2 = ((JSONObject) ser.fromBytes(bytes)).toJSONString();
        }
        System.out.println((jsonString2));
        System.out.println(jsonString2.equalsIgnoreCase(json.toJSONString()));
    }

}

From source file:name.martingeisse.ecotools.simulator.ui.Main.java

/**
 * The main method.// www.  ja v  a2s  .c om
 * @param args command-line arguments
 * @throws Exception Any exceptions are passed to the environment.
 */
public static void main(String[] args) throws Exception {

    /** define command-line options **/
    Options options = new Options();
    options.addOption("i", false, "interactive mode (do not start simulation automatically)");
    options.addOption("l", true, "load program");
    options.addOption("r", true, "load ROM contents");
    options.addOption("d", true, "enable disk simulation with the specified disk image file");
    options.addOption("t", true, "enable terminal simulation with the specified number of terminals (0..2)");
    options.addOption("g", false, "enable graphics controller simulation");
    options.addOption("c", false, "enable console simulation");
    options.addOption("C", false, "enable block console simulation");
    options.addOption("o", true, "enable output device simulation and write output to the specified file");
    options.addOption("s", false, "enable null sound device");

    /** print help for the empty command line **/
    if (args.length == 0) {
        showUsgeAndExit(options);
    }

    /** parse the command line **/
    CommandLineParser commandLineParser = new PosixParser();
    CommandLine commandLine;
    try {
        commandLine = commandLineParser.parse(options, args);
    } catch (UnrecognizedOptionException e) {
        System.out.println("unrecognized option: " + e.getOption());
        showUsgeAndExit(options);
        return;
    }

    /** build the simulator configuration **/
    SimulatorConfiguration configuration = new SimulatorConfiguration();

    /** load configuration files **/
    for (String arg : commandLine.getArgs()) {
        configuration.loadConfigurationFile(arg);
    }

    /** interpret the options **/

    if (commandLine.hasOption("l")) {
        configuration.setProgramFilename(commandLine.getOptionValue("l"));
    }

    if (commandLine.hasOption("r")) {
        configuration.setRomFilename(commandLine.getOptionValue("r"));
    }

    if (commandLine.hasOption("d")) {
        configuration.setDiskFilename(commandLine.getOptionValue("d"));
    }

    if (commandLine.hasOption("t")) {
        String terminalCountSpecification = commandLine.getOptionValue("t");
        try {
            configuration.setTerminalCount(
                    (terminalCountSpecification == null) ? 0 : Integer.parseInt(terminalCountSpecification));
        } catch (NumberFormatException e) {
            System.out.println("number format error in number of terminals: " + terminalCountSpecification);
        }
    }

    if (commandLine.hasOption("i")) {
        configuration.setInteractive(true);
    }

    if (commandLine.hasOption("g")) {
        configuration.setGraphics(true);
    }

    if (commandLine.hasOption("c")) {
        configuration.setConsole(true);
    }

    if (commandLine.hasOption("C")) {
        configuration.setBlockConsole(true);
    }

    if (commandLine.hasOption("o")) {
        configuration.setOutputFilename(commandLine.getOptionValue("o"));
    }

    if (commandLine.hasOption("s")) {
        configuration.setSound(true);
    }

    configuration.checkConsistency();
    configuration.deriveSettings();

    /** setup simulation framework and run **/
    EcoSimulatorFramework framework = new EcoSimulatorFramework();
    configuration.applyPreCreate(framework);
    framework.create();
    configuration.applyPostCreate(framework);
    framework.open();
    framework.mainLoop();
    framework.dispose();
    framework.exit();

}

From source file:it.tizianofagni.sparkboost.MPBoostLearnerExe.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption("b", "binaryProblem", false,
            "Indicate if the input dataset contains a binary problem and not a multilabel one");
    options.addOption("z", "labels0based", false,
            "Indicate if the labels IDs in the dataset to classifyLibSvmWithResults are already assigned in the range [0, numLabels-1] included");
    options.addOption("l", "enableSparkLogging", false, "Enable logging messages of Spark");
    options.addOption("w", "windowsLocalModeFix", true,
            "Set the directory containing the winutils.exe command");
    options.addOption("dp", "documentPartitions", true, "The number of document partitions");
    options.addOption("fp", "featurePartitions", true, "The number of feature partitions");
    options.addOption("lp", "labelPartitions", true, "The number of label partitions");

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;//w  w w .  ja  v  a 2  s.  c  om
    String[] remainingArgs = null;
    try {
        cmd = parser.parse(options, args);
        remainingArgs = cmd.getArgs();
        if (remainingArgs.length != 3)
            throw new ParseException("You need to specify all mandatory parameters");
    } catch (ParseException e) {
        System.out.println("Parsing failed.  Reason: " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(
                MPBoostLearnerExe.class.getSimpleName() + " [OPTIONS] <inputFile> <outputFile> <numIterations>",
                options);
        System.exit(-1);
    }

    boolean binaryProblem = false;
    if (cmd.hasOption("b"))
        binaryProblem = true;
    boolean labels0Based = false;
    if (cmd.hasOption("z"))
        labels0Based = true;
    boolean enablingSparkLogging = false;
    if (cmd.hasOption("l"))
        enablingSparkLogging = true;

    if (cmd.hasOption("w")) {
        System.setProperty("hadoop.home.dir", cmd.getOptionValue("w"));
    }

    String inputFile = remainingArgs[0];
    String outputFile = remainingArgs[1];
    int numIterations = Integer.parseInt(remainingArgs[2]);

    long startTime = System.currentTimeMillis();

    // Disable Spark logging.
    if (!enablingSparkLogging) {
        Logger.getLogger("org").setLevel(Level.OFF);
        Logger.getLogger("akka").setLevel(Level.OFF);
    }

    // Create and configure Spark context.
    SparkConf conf = new SparkConf().setAppName("Spark MPBoost learner");
    JavaSparkContext sc = new JavaSparkContext(conf);

    // Create and configure learner.
    MpBoostLearner learner = new MpBoostLearner(sc);
    learner.setNumIterations(numIterations);

    if (cmd.hasOption("dp")) {
        learner.setNumDocumentsPartitions(Integer.parseInt(cmd.getOptionValue("dp")));
    }
    if (cmd.hasOption("fp")) {
        learner.setNumFeaturesPartitions(Integer.parseInt(cmd.getOptionValue("fp")));
    }
    if (cmd.hasOption("lp")) {
        learner.setNumLabelsPartitions(Integer.parseInt(cmd.getOptionValue("lp")));
    }

    // Build classifier with MPBoost learner.
    BoostClassifier classifier = learner.buildModel(inputFile, labels0Based, binaryProblem);

    // Save classifier to disk.
    DataUtils.saveModel(sc, classifier, outputFile);

    long endTime = System.currentTimeMillis();
    System.out.println("Execution time: " + (endTime - startTime) + " milliseconds.");
}

From source file:com.mmounirou.spotirss.SpotiRss.java

/**
 * @param args//from  w  w w .  ja va  2s . c  om
 * @throws IOException 
 * @throws ClassNotFoundException 
 * @throws IllegalAccessException 
 * @throws InstantiationException 
 * @throws SpotifyClientException 
 * @throws ChartRssException 
 * @throws SpotifyException 
 */
public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException,
        ClassNotFoundException, SpotifyClientException {
    if (args.length == 0) {
        System.err.println("usage : java -jar spotiboard.jar <charts-folder>");
        return;
    }

    Properties connProperties = new Properties();
    InputStream inStream = SpotiRss.class.getResourceAsStream("/spotify-server.properties");
    try {
        connProperties.load(inStream);
    } finally {
        IOUtils.closeQuietly(inStream);
    }

    String host = connProperties.getProperty("host");
    int port = Integer.parseInt(connProperties.getProperty("port"));
    String user = connProperties.getProperty("user");

    final SpotifyClient spotifyClient = new SpotifyClient(host, port, user);
    final Map<String, Playlist> playlistsByTitle = getPlaylistsByTitle(spotifyClient);

    final File outputDir = new File(args[0]);
    outputDir.mkdirs();
    TrackCache cache = new TrackCache();
    try {

        for (String strProvider : PROVIDERS) {
            String providerClassName = EntryToTrackConverter.class.getPackage().getName() + "."
                    + StringUtils.capitalize(strProvider);
            final EntryToTrackConverter converter = (EntryToTrackConverter) SpotiRss.class.getClassLoader()
                    .loadClass(providerClassName).newInstance();
            Iterable<String> chartsRss = getCharts(strProvider);
            final File resultDir = new File(outputDir, strProvider);
            resultDir.mkdir();

            final SpotifyHrefQuery hrefQuery = new SpotifyHrefQuery(cache);
            Iterable<String> results = FluentIterable.from(chartsRss).transform(new Function<String, String>() {

                @Override
                @Nullable
                public String apply(@Nullable String chartRss) {

                    try {

                        long begin = System.currentTimeMillis();
                        ChartRss bilboardChartRss = ChartRss.getInstance(chartRss, converter);
                        Map<Track, String> trackHrefs = hrefQuery.getTrackHrefs(bilboardChartRss.getSongs());

                        String strTitle = bilboardChartRss.getTitle();
                        File resultFile = new File(resultDir, strTitle);
                        List<String> lines = Lists.newLinkedList(FluentIterable.from(trackHrefs.keySet())
                                .transform(Functions.toStringFunction()));
                        lines.addAll(trackHrefs.values());
                        FileUtils.writeLines(resultFile, Charsets.UTF_8.displayName(), lines);

                        Playlist playlist = playlistsByTitle.get(strTitle);
                        if (playlist != null) {
                            playlist.getTracks().clear();
                            playlist.getTracks().addAll(trackHrefs.values());
                            spotifyClient.patch(playlist);
                            LOGGER.info(String.format("%s chart exported patched", strTitle));
                        }

                        LOGGER.info(String.format("%s chart exported in %s in %d s", strTitle,
                                resultFile.getAbsolutePath(),
                                (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - begin)));

                    } catch (Exception e) {
                        LOGGER.error(String.format("fail to export %s charts", chartRss), e);
                    }

                    return "";
                }
            });

            // consume iterables
            Iterables.size(results);

        }

    } finally {
        cache.close();
    }

}

From source file:com.github.sdnwiselab.sdnwise.mote.standalone.Loader.java

/**
 * @param args the command line arguments
 *//*from   w w  w .  java 2 s . co m*/
public static void main(final String[] args) {
    Options options = new Options();
    options.addOption(Option.builder("n").argName("net").hasArg().required().desc("Network ID of the node")
            .numberOfArgs(1).build());
    options.addOption(Option.builder("a").argName("address").hasArg().required()
            .desc("Address of the node <0-65535>").numberOfArgs(1).build());
    options.addOption(Option.builder("p").argName("port").hasArg().required().desc("Listening UDP port")
            .numberOfArgs(1).build());
    options.addOption(Option.builder("t").argName("filename").hasArg().required()
            .desc("Use given file for neighbors discovery").numberOfArgs(1).build());
    options.addOption(Option.builder("c").argName("ip:port").hasArg()
            .desc("IP address and TCP port of the controller. (SINK ONLY)").numberOfArgs(1).build());
    options.addOption(Option.builder("sp").argName("port").hasArg()
            .desc("Port number of the switch. (SINK ONLY)").numberOfArgs(1).build());
    options.addOption(Option.builder("sm").argName("mac").hasArg()
            .desc("MAC address of the switch. Example: <00:00:00:00:00:00>." + " (SINK ONLY)").numberOfArgs(1)
            .build());
    options.addOption(Option.builder("sd").argName("dpid").hasArg().desc("DPID of the switch (SINK ONLY)")
            .numberOfArgs(1).build());
    options.addOption(Option.builder("l").argName("level").hasArg()
            .desc("Use given log level. Values: SEVERE, WARNING, INFO, " + "CONFIG, FINE, FINER, FINEST.")
            .numberOfArgs(1).optionalArg(true).build());

    // create the parser
    CommandLineParser parser = new DefaultParser();
    try {
        CommandLine line = parser.parse(options, args);
        Thread th;

        byte cmdNet = (byte) Integer.parseInt(line.getOptionValue("n"));
        NodeAddress cmdAddress = new NodeAddress(Integer.parseInt(line.getOptionValue("a")));
        int cmdPort = Integer.parseInt(line.getOptionValue("p"));
        String cmdTopo = line.getOptionValue("t");

        String cmdLevel;

        if (!line.hasOption("l")) {
            cmdLevel = "SEVERE";
        } else {
            cmdLevel = line.getOptionValue("l");
        }

        if (line.hasOption("c")) {

            if (!line.hasOption("sd")) {
                throw new ParseException("-sd option missing");
            }
            if (!line.hasOption("sp")) {
                throw new ParseException("-sp option missing");
            }
            if (!line.hasOption("sm")) {
                throw new ParseException("-sm option missing");
            }

            String cmdSDpid = line.getOptionValue("sd");
            String cmdSMac = line.getOptionValue("sm");
            long cmdSPort = Long.parseLong(line.getOptionValue("sp"));
            String[] ipport = line.getOptionValue("c").split(":");
            th = new Thread(new Sink(cmdNet, cmdAddress, cmdPort,
                    new InetSocketAddress(ipport[0], Integer.parseInt(ipport[1])), cmdTopo, cmdLevel, cmdSDpid,
                    cmdSMac, cmdSPort));
        } else {
            th = new Thread(new Mote(cmdNet, cmdAddress, cmdPort, cmdTopo, cmdLevel));
        }
        th.start();
        th.join();
    } catch (InterruptedException | ParseException ex) {
        System.out.println("Parsing failed.  Reason: " + ex.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("sdn-wise-data -n id -a address -p port"
                + " -t filename [-l level] [-sd dpid -sm mac -sp port]", options);
    }
}

From source file:ca.uwaterloo.cpami.mahout.matrix.utils.GramSchmidt.java

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

    //final Configuration conf = new Configuration();
    //final FileSystem fs = FileSystem.get(conf);
    //final SequenceFile.Reader reader = new SequenceFile.Reader(fs,
    //   new Path("R1.dat"), conf);
    //IntWritable key = new IntWritable();
    //VectorWritable vec = new VectorWritable();
    Matrix mat = new SparseMatrix(1500, 100);
    //SparseRealMatrix mat2 = new OpenMapRealMatrix(12419,1500 );
    BufferedReader reader = new BufferedReader(new FileReader("R.3.csv"));
    String line = null;//  ww w. ja  v a  2  s  .  com
    while ((line = reader.readLine()) != null) {
        String[] parts = line.split(",");

        mat.set(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Double.parseDouble(parts[2]));
        /*
        Vector v = vec.get();
        int i=0;
        Iterator<Vector.Element> itr = v.iterateNonZero();
        while(itr.hasNext()){
           double elem = itr.next().get();
           if(elem !=0)
              mat2.setEntry(i, key.get(), elem);
           i++;
        }
        */
    }

    //mat = mat.transpose();
    System.out.println(mat.viewColumn(0).isDense());
    System.out.println(mat.viewRow(0).isDense());
    mat = mat.transpose();
    GramSchmidt.orthonormalizeColumns(mat);
    /*
    System.out.println("started QR");
    System.out.println(Runtime.getRuntime().maxMemory());
    System.out.println(Runtime.getRuntime().maxMemory()-Runtime.getRuntime().freeMemory());
    QRDecomposition qr = new QRDecomposition(mat2);
    System.out.println(qr.getQ().getColumnDimension());
    System.out.println(qr.getQ().getRowDimension());
    */
    //mat = mat.transpose();
    //storeSparseColumns(mat);
    //for (int i = 0; i < 10; i++) {
    //   System.out.println(mat.viewRow(i).getNumNondefaultElements());
    //}

}

From source file:eu.annocultor.converters.europeana.EuropeanaSolrDocumentTagger.java

public static void main(String... commandLine) throws Exception {

    if (commandLine.length != 4) {
        System.err.println("Expected: solrServerFrom solrServerTo query start");
    } else {/*from  www  . jav  a2s .com*/
        String solrServerFrom = commandLine[0];
        String solrServerTo = commandLine[1];
        String query = commandLine[2];
        int start = Integer.parseInt(commandLine[3]);

        start(solrServerFrom, solrServerTo, query, start);
    }
}

From source file:com.iflytek.spider.parse.ParseText.java

public static void main(String argv[]) throws Exception {
    String usage = "ParseText (-local | -dfs <namenode:port>) recno segment";

    if (argv.length < 3) {
        System.out.println("usage:" + usage);
        return;/*w  w  w .  ja  va 2s  .c  o  m*/
    }
    Options opts = new Options();
    Configuration conf = SpiderConfiguration.create();

    GenericOptionsParser parser = new GenericOptionsParser(conf, opts, argv);

    String[] remainingArgs = parser.getRemainingArgs();

    FileSystem fs = FileSystem.get(conf);
    try {
        int recno = Integer.parseInt(remainingArgs[0]);
        String segment = remainingArgs[1];
        String filename = new Path(segment, ParseText.DIR_NAME).toString();

        ParseText parseText = new ParseText();
        ArrayFile.Reader parseTexts = new ArrayFile.Reader(fs, filename, conf);

        parseTexts.get(recno, parseText);
        System.out.println("Retrieved " + recno + " from file " + filename);
        System.out.println(parseText);
        parseTexts.close();
    } finally {
        fs.close();
    }
}

From source file:com.jolbox.benchmark.BenchmarkLaunch.java

/**
 * @param args//from ww w . ja  v  a  2s  .c o  m
 * @throws ClassNotFoundException 
 * @throws PropertyVetoException 
 * @throws SQLException 
 * @throws NoSuchMethodException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 * @throws InterruptedException 
 * @throws SecurityException 
 * @throws IllegalArgumentException 
 * @throws NamingException 
 * @throws ParseException 
 * @throws IOException 
 */
public static void main(String[] args) throws ClassNotFoundException, SQLException, PropertyVetoException,
        IllegalArgumentException, SecurityException, InterruptedException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException, NamingException, ParseException, IOException {

    Options options = new Options();
    options.addOption("t", "threads", true, "Max number of threads");
    options.addOption("s", "stepping", true, "Stepping of threads");
    options.addOption("p", "poolsize", true, "Pool size");
    options.addOption("h", "help", false, "Help");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("benchmark.jar", options);
        System.exit(1);
    }

    BenchmarkTests.threads = 400;
    BenchmarkTests.stepping = 5;
    BenchmarkTests.pool_size = 200;
    if (cmd.hasOption("t")) {
        BenchmarkTests.threads = Integer.parseInt(cmd.getOptionValue("t", "400"));
    }
    if (cmd.hasOption("s")) {
        BenchmarkTests.stepping = Integer.parseInt(cmd.getOptionValue("s", "20"));
    }
    if (cmd.hasOption("p")) {
        BenchmarkTests.pool_size = Integer.parseInt(cmd.getOptionValue("p", "200"));
    }

    System.out.println("Starting benchmark tests with " + BenchmarkTests.threads + " threads (stepping "
            + BenchmarkTests.stepping + ") using pool size of " + BenchmarkTests.pool_size + " connections");

    new MockJDBCDriver();
    BenchmarkTests tests = new BenchmarkTests();

    plotLineGraph(tests.testMultiThreadedConstantDelay(0), 0, false);
    plotLineGraph(tests.testMultiThreadedConstantDelay(10), 10, false);
    plotLineGraph(tests.testMultiThreadedConstantDelay(25), 25, false);
    plotLineGraph(tests.testMultiThreadedConstantDelay(50), 50, false);
    plotLineGraph(tests.testMultiThreadedConstantDelay(75), 75, false);

    plotBarGraph("Single Thread", "bonecp-singlethread-poolsize-" + BenchmarkTests.pool_size + "-threads-"
            + BenchmarkTests.threads + ".png", tests.testSingleThread());
    plotBarGraph(
            "Prepared Statement\nSingle Threaded", "bonecp-preparedstatement-single-poolsize-"
                    + BenchmarkTests.pool_size + "-threads-" + BenchmarkTests.threads + ".png",
            tests.testPreparedStatementSingleThread());
    plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(0), 0, true);
    plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(10), 10, true);
    plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(25), 25, true);
    plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(50), 50, true);
    plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(75), 75, true);

}

From source file:DokeosConverter.java

public static void main(String[] arguments) throws Exception {
    CommandLineParser commandLineParser = new PosixParser();
    CommandLine commandLine = commandLineParser.parse(OPTIONS, arguments);

    int port = SocketOpenOfficeConnection.DEFAULT_PORT;
    if (commandLine.hasOption(OPTION_PORT.getOpt())) {
        port = Integer.parseInt(commandLine.getOptionValue(OPTION_PORT.getOpt()));
    }//from w  ww  .  ja va 2  s  .c o  m

    String outputFormat = null;
    if (commandLine.hasOption(OPTION_OUTPUT_FORMAT.getOpt())) {
        outputFormat = commandLine.getOptionValue(OPTION_OUTPUT_FORMAT.getOpt());
    }

    boolean verbose = false;
    if (commandLine.hasOption(OPTION_VERBOSE.getOpt())) {
        verbose = true;
    }

    String dokeosMode = "woogie";
    if (commandLine.hasOption(OPTION_DOKEOS_MODE.getOpt())) {
        dokeosMode = commandLine.getOptionValue(OPTION_DOKEOS_MODE.getOpt());
    }
    int width = 800;
    if (commandLine.hasOption(OPTION_WIDTH.getOpt())) {
        width = Integer.parseInt(commandLine.getOptionValue(OPTION_WIDTH.getOpt()));
    }

    int height = 600;
    if (commandLine.hasOption(OPTION_HEIGHT.getOpt())) {
        height = Integer.parseInt(commandLine.getOptionValue(OPTION_HEIGHT.getOpt()));
    }

    String[] fileNames = commandLine.getArgs();
    if ((outputFormat == null && fileNames.length != 2 && dokeosMode != null) || fileNames.length < 1) {
        String syntax = "convert [options] input-file output-file; or\n"
                + "[options] -f output-format input-file [input-file...]";
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp(syntax, OPTIONS);
        System.exit(EXIT_CODE_TOO_FEW_ARGS);
    }

    OpenOfficeConnection connection = new DokeosSocketOfficeConnection(port);
    try {
        if (verbose) {
            System.out.println("-- connecting to OpenOffice.org on port " + port);
        }
        connection.connect();
    } catch (ConnectException officeNotRunning) {
        System.err.println(
                "ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port "
                        + port + ".");
        System.exit(EXIT_CODE_CONNECTION_FAILED);
    }
    try {

        // choose the good constructor to deal with the conversion
        DocumentConverter converter;
        if (dokeosMode.equals("oogie")) {
            converter = new OogieDocumentConverter(connection, new DokeosDocumentFormatRegistry(), width,
                    height);
        } else if (dokeosMode.equals("woogie")) {
            converter = new WoogieDocumentConverter(connection, new DokeosDocumentFormatRegistry(), width,
                    height);
        } else {
            converter = new OpenOfficeDocumentConverter(connection);
        }

        if (outputFormat == null) {
            File inputFile = new File(fileNames[0]);
            File outputFile = new File(fileNames[1]);
            convertOne(converter, inputFile, outputFile, verbose);
        } else {
            for (int i = 0; i < fileNames.length; i++) {
                File inputFile = new File(fileNames[i]);
                File outputFile = new File(FilenameUtils.getFullPath(fileNames[i])
                        + FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat);
                convertOne(converter, inputFile, outputFile, verbose);
            }
        }
    } catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) {
        connection.disconnect();
        System.err.println("ERROR: conversion failed.");
        System.exit(EXIT_CODE_CONVERSION_FAILED);
    } finally {
        if (verbose) {
            System.out.println("-- disconnecting");
        }
        connection.disconnect();
    }
}