Example usage for java.lang System exit

List of usage examples for java.lang System exit

Introduction

In this page you can find the example usage for java.lang System exit.

Prototype

public static void exit(int status) 

Source Link

Document

Terminates the currently running Java Virtual Machine.

Usage

From source file:es.cnio.bioinfo.bicycle.BinomialAnnotator.java

public static void main(String[] args) throws IOException, MathException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    double p = Double.parseDouble(args[0]);
    String line = null;/*  w ww.j a v a 2  s .  c  om*/

    while ((line = in.readLine()) != null) {

        String[] tokens = line.split("\t");
        int reads = Integer.parseInt(tokens[5]);
        int cCount = Integer.parseInt(tokens[4]);
        BinomialDistribution binomial = new BinomialDistributionImpl(reads, p);
        double pval = (reads == 0) ? 1.0d : (1.0d - binomial.cumulativeProbability(cCount - 1));
        if (System.out.checkError()) {
            System.exit(1);
        }
        System.out.println(line + "\t" + pval);

    }
}

From source file:net.orpiske.mdm.broker.main.Main.java

public static void main(String[] args) {
    int ret = 0;//from www . ja  v  a2  s  . c o  m

    if (args.length == 0) {
        help(1);
    }

    try {
        ConfigurationWrapper.initConfiguration(Constants.MDM_BROKER_CONFIG_DIR, Constants.CONFIG_FILE_NAME);
    } catch (ConfigurationException e) {
        System.err.println("Unable to load configuration file " + "'mdm-broker.properties': " + e.getMessage());

        System.exit(-1);
    } catch (FileNotFoundException e) {
        System.err.println("Unable to find configuration file " + "'mdm-broker.properties': " + e.getMessage());

        System.exit(-1);
    }

    String first = args[0];
    String[] newArgs = Arrays.copyOfRange(args, 1, args.length);

    if (first.equals("run")) {
        RunAction runAction = new RunAction(newArgs);

        ret = runAction.run();
        System.exit(ret);
    }

    help(-1);
}

From source file:com.blackberry.logtools.logcat.java

public static void main(String[] argv) throws Exception {
    //Let ToolRunner handle generic command-line options
    int res = ToolRunner.run(new Configuration(), new logcat(), argv);
    System.exit(res);
}

From source file:PKCS12Import.java

public static void main(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("usage: java PKCS12Import {pkcs12file} [newjksfile]");
        System.exit(1);
    }//from  w w w  .ja v a 2s. c o  m

    File fileIn = new File(args[0]);
    File fileOut;
    if (args.length > 1) {
        fileOut = new File(args[1]);
    } else {
        fileOut = new File("newstore.jks");
    }

    if (!fileIn.canRead()) {
        System.err.println("Unable to access input keystore: " + fileIn.getPath());
        System.exit(2);
    }

    if (fileOut.exists() && !fileOut.canWrite()) {
        System.err.println("Output file is not writable: " + fileOut.getPath());
        System.exit(2);
    }

    KeyStore kspkcs12 = KeyStore.getInstance("pkcs12");
    KeyStore ksjks = KeyStore.getInstance("jks");

    System.out.print("Enter input keystore passphrase: ");
    char[] inphrase = readPassphrase();
    System.out.print("Enter output keystore passphrase: ");
    char[] outphrase = readPassphrase();

    kspkcs12.load(new FileInputStream(fileIn), inphrase);

    ksjks.load((fileOut.exists()) ? new FileInputStream(fileOut) : null, outphrase);

    Enumeration eAliases = kspkcs12.aliases();
    int n = 0;
    while (eAliases.hasMoreElements()) {
        String strAlias = (String) eAliases.nextElement();
        System.err.println("Alias " + n++ + ": " + strAlias);

        if (kspkcs12.isKeyEntry(strAlias)) {
            System.err.println("Adding key for alias " + strAlias);
            Key key = kspkcs12.getKey(strAlias, inphrase);

            Certificate[] chain = kspkcs12.getCertificateChain(strAlias);

            ksjks.setKeyEntry(strAlias, key, outphrase, chain);
        }
    }

    OutputStream out = new FileOutputStream(fileOut);
    ksjks.store(out, outphrase);
    out.close();
}

From source file:com.opengamma.integration.tool.marketdata.MarketDataSnapshotImportTool.java

/**
 * Main method to run the tool. No arguments are needed.
 *
 * @param args the arguments, no null//from w ww .j  av  a  2s  .  c  om
 */
public static void main(final String[] args) { // CSIGNORE
    final boolean success = new MarketDataSnapshotImportTool().initAndRun(args, ToolContext.class);
    System.exit(success ? 0 : 1);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;//from   ww  w .j  a v a2 s .  co  m
    }
    SystemTray tray = SystemTray.getSystemTray();

    PropertyChangeListener pcl;
    pcl = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            System.out.println("Property changed = " + pce.getPropertyName());
            TrayIcon[] tia = (TrayIcon[]) pce.getOldValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }
        }
    };
    tray.addPropertyChangeListener("trayIcons", pcl);
    PropertyChangeListener[] listeners = tray.getPropertyChangeListeners("trayIcons");

    Dimension size = tray.getTrayIconSize();
    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);
    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

    Thread.sleep(3000);
    tray.remove(icon);

    Thread.sleep(3000);
    System.exit(0);
}

From source file:FilledGeneralPath.java

public static void main(String s[]) {
    JFrame f = new JFrame("");
    f.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }/*w w w.j a v a  2 s.c  o m*/
    });
    JApplet applet = new FilledGeneralPath();
    f.getContentPane().add("Center", applet);
    applet.init();
    f.pack();
    f.setSize(new Dimension(300, 300));
    f.show();
}

From source file:gis.proj.drivers.SnyderTest.java

public static void main(String... args) {
    SnyderTest sfTest = new SnyderTest();
    JCommander jc = new JCommander(sfTest);

    try {//www .ja  v a 2  s . co  m
        jc.parse(args);
    } catch (Exception e) {
        jc.usage();
        System.exit(-10);
    }

    Snyder.printLicenseInformation("SnyderTest");

    double[][] fVal = null; // forward values
    double[][] iVal = null; // inverse values

    Ellipsoid ellip;
    Datum datum;
    Projection proj;

    ArrayList<Fiducial> testData = null;

    try {
        testData = Snyder.fromJSON(new TypeReference<ArrayList<Fiducial>>() {
        }, sfTest.ifName);
    } catch (Exception e) {
    }

    if (testData != null) {
        for (Fiducial sf : testData) {
            ellip = null;
            datum = null;
            proj = null;

            ellip = EllipsoidFactory.getInstance().getEllipsoid(sf.getEllipsoid());

            datum = new Datum();

            for (Entry<String, String> entry : sf.getDatum().entrySet()) {
                datum.setUserOverrideProperty(entry.getKey(),
                        Snyder.parseDatumVal(entry.getValue().toLowerCase()));
            }

            try {
                Class<?> cls = Class.forName(sf.getProjection());
                proj = (Projection) cls.newInstance();
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            fVal = proj.forward(new double[] { sf.getLon() * SnyderMath.DEG_TO_RAD },
                    new double[] { sf.getLat() * SnyderMath.DEG_TO_RAD }, ellip, datum);

            iVal = proj.inverse(new double[] { fVal[0][0] }, new double[] { fVal[1][0] }, ellip, datum);

            iVal[0][0] *= SnyderMath.RAD_TO_DEG;
            iVal[1][0] *= SnyderMath.RAD_TO_DEG;

            sf.setPassed(fVal[0][0], fVal[1][0], iVal[0][0], iVal[1][0]);
        }

        try {

            if (sfTest.ofName != null)
                sfTest.om.writeValue(new File(sfTest.ofName), testData);

        } catch (Exception e) {
            System.out.println("Couldn't write the fiducial data results, of=" + sfTest.ofName);
            System.exit(-1);
        }

        System.out.print("\n**********************************************************************\n");
        System.out.print("SNYDER TEST SUMMARY");
        System.out.print("\n**********************************************************************\n");
        System.out.println("\n\t  Total test cases : " + testData.size());
    } else {
        System.out.println("Couldn't load the fiducial data, if=" + sfTest.ifName);
        System.exit(-1);
    }
}

From source file:de.hadesrofl.mqtt_client.App.java

public static void main(String[] args) {
    String cf = "";
    if (args.length > 0) {
        cf = args[0];//from   w  w  w .  ja  v  a  2 s. c  om
    } else {
        cf = "config.json";
    }
    JSONObject config = JsonReader.readFile(cf);
    if (config == null)
        System.exit(-1);
    JSONObject broker = config.getJSONObject("broker");
    JSONObject topics = broker.getJSONObject("topics");
    Database db = null;
    try {
        JSONObject database = config.getJSONObject("database");
        db = new Database(database.getString("dbHost"), database.getString("dbPort"),
                database.getString("dbName"), database.getString("dbUser"), database.getString("dbPass"));
    } catch (JSONException e) {
        System.err.println("No database mentioned in config file");
    }
    List<ClientMqtt> clients = new ArrayList<ClientMqtt>();
    List<Thread> clientThreads = new ArrayList<Thread>();
    for (String topic : topics.keySet()) {
        ClientMqtt client = null;
        if (db == null) {
            client = new ClientMqtt(broker.getString("address"), broker.getInt("port"),
                    topics.getString(topic));
        } else {
            client = new ClientMqtt(broker.getString("address"), broker.getInt("port"), topics.getString(topic),
                    db);
        }
        Thread clientThread = new Thread(client);
        client.setSubscriber(broker.getBoolean("subscribe"));
        clients.add(client);
        clientThreads.add(clientThread);
        clientThread.start();
        // Need to wait a bit as the client needs to connect first
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            System.err.println("Thread can't sleep, need to take painkillers");
        }
        client.publishMessage("Ground control to Major Tom", 1);
    }
}

From source file:InsertRowUpdatableResultSet_MySQL.java

public static void main(String[] args) {
    Connection conn = null;/*from www .  jav a  2  s  .  com*/
    Statement stmt = null;
    ResultSet rs = null;
    try {
        conn = getConnection();
        String query = "select id, name from employees";
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        rs = stmt.executeQuery(query);
        while (rs.next()) {
            String id = rs.getString(1);
            String name = rs.getString(2);
            System.out.println("id=" + id + "  name=" + name);
        }
        // Move cursor to the "insert row"
        rs.moveToInsertRow();
        // Set values for the new row.
        rs.updateString("id", "001");
        rs.updateString("name", "newName");
        // Insert the new row
        rs.insertRow();
        // scroll from the top again
        rs.beforeFirst();
        while (rs.next()) {
            String id = rs.getString(1);
            String name = rs.getString(2);
            System.out.println("id=" + id + "  name=" + name);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    } finally {
        // release database resources
        try {
            rs.close();
            stmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}