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:hd3gtv.tools.Hexview.java

public static void main(String[] args) throws IOException {
    if (args.length == 0) {
        System.err.println("Usage file1.ext file2.ext ...");
        System.exit(1);
    }/* w  w  w. ja  va  2  s. c o m*/

    Arrays.asList(args).forEach(f -> {
        try {
            File file = new File(f);

            InputStream in = new BufferedInputStream(new FileInputStream(file), 0xFFFF);

            byte[] buffer = new byte[COLS * ROWS];
            int len;
            Hexview hv = null;

            while ((len = in.read(buffer)) != -1) {
                if (hv == null) {
                    hv = new Hexview(buffer, 0, len);
                    hv.setSize(file.length());
                } else {
                    hv.update(buffer, 0, len);
                }
                System.out.println(hv.getView());
            }

            IOUtils.closeQuietly(in);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(2);
        }
    });
}

From source file:net.ontopia.persistence.rdbms.DDLWriter.java

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

    // Initialize logging
    CmdlineUtils.initializeLogging();//from  w  w w  .j ava  2  s . com

    // Initialize command line option parser and listeners
    CmdlineOptions options = new CmdlineOptions("DDLWriter", argv);

    // Register logging options
    CmdlineUtils.registerLoggingOptions(options);

    // Parse command line options
    try {
        options.parse();
    } catch (CmdlineOptions.OptionsException e) {
        System.err.println("Error: " + e.getMessage());
        System.exit(1);
    }

    // Get command line arguments
    String[] args = options.getArguments();
    if (args.length < 3) {
        System.err.println("Error: need exactly two files as arguments.");
        usage();
        System.exit(1);
    }

    String schema = args[0];
    String dbtype = args[1];
    String[] platforms = StringUtils.split(args[2], ",");
    String createfile = args[3];
    String dropfile = args[4];

    Project project = DatabaseProjectReader.loadProject(schema);

    GenericSQLProducer producer;
    switch (dbtype) {
    case "postgresql":
        producer = new PostgreSQLProducer(project, platforms);
        break;
    case "oracle":
        producer = new OracleSQLProducer(project, platforms);
        break;
    case "sqlserver":
        producer = new SQLServerSQLProducer(project, platforms);
        break;
    case "mysql":
        producer = new MySqlSQLProducer(project, platforms);
        break;
    case "db2":
        producer = new DB2SQLProducer(project, platforms);
        break;
    case "firebird":
        producer = new FirebirdSQLProducer(project, platforms);
        break;
    default:
        producer = new GenericSQLProducer(project, platforms);
        break;
    }

    // Generate create file
    Writer cwriter = new FileWriter(createfile);
    producer.writeCreate(cwriter);
    cwriter.close();

    // Generate create file
    Writer dwriter = new FileWriter(dropfile);
    producer.writeDrop(dwriter);
    dwriter.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;//from  w w w. j  av  a 2 s  .c  o 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);

    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:com.discursive.jccook.cmdline.CliBasicExample.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new BasicParser();

    Options options = new Options();
    options.addOption("h", "help", false, "Print this usage information");
    options.addOption("v", "verbose", false, "Print out VERBOSE debugging information");
    options.addOption("f", "file", true, "File to save program output to");

    CommandLine commandLine = parser.parse(options, args);

    boolean verbose = false;
    String file = "";

    if (commandLine.hasOption('h')) {
        System.out.println("Help Message");
        System.exit(0);
    }/*from   w w  w.ja  v  a 2s .c  o m*/

    if (commandLine.hasOption('v')) {
        verbose = true;
    }

    if (commandLine.hasOption('f')) {
        file = commandLine.getOptionValue('f');
    }

    System.exit(0);
}

From source file:deck36.storm.plan9.php.KittenRobbersTopology.java

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

    String env = null;//from   w ww  . j  av a2  s. c o  m

    if (args != null && args.length > 0) {
        env = args[0];
    }

    if (!"dev".equals(env))
        if (!"prod".equals(env)) {
            System.out.println("Usage: $0 (dev|prod)\n");
            System.exit(1);
        }

    // Topology config
    Config conf = new Config();

    // Load parameters and add them to the Config
    Map configMap = YamlLoader.loadYamlFromResource("config_" + env + ".yml");

    conf.putAll(configMap);

    log.info(JSONValue.toJSONString((conf)));

    // Set topology loglevel to DEBUG
    conf.put(Config.TOPOLOGY_DEBUG, JsonPath.read(conf, "$.deck36_storm.debug"));

    // Create Topology builder
    TopologyBuilder builder = new TopologyBuilder();

    // if there are not special reasons, start with parallelism hint of 1
    // and multiple tasks. By that, you can scale dynamically later on.
    int parallelism_hint = JsonPath.read(conf, "$.deck36_storm.default_parallelism_hint");
    int num_tasks = JsonPath.read(conf, "$.deck36_storm.default_num_tasks");

    String badgeName = KittenRobbersTopology.class.getSimpleName();

    // construct command to invoke the external bolt implementation
    ArrayList<String> command = new ArrayList(15);

    // Add main execution program (php, hhvm, zend, ..) and parameters
    command.add((String) JsonPath.read(conf, "$.deck36_storm.php.executor"));
    command.addAll((List<String>) JsonPath.read(conf, "$.deck36_storm.php.executor_params"));

    // Add main command to be executed (app/console, the phar file, etc.) and global context parameters (environment etc.)
    command.add((String) JsonPath.read(conf, "$.deck36_storm.php.main"));
    command.addAll((List<String>) JsonPath.read(conf, "$.deck36_storm.php.main_params"));

    // Add main route to be invoked and its parameters
    command.add((String) JsonPath.read(conf, "$.deck36_storm.KittenRobbersFromOuterSpaceBolt.main"));
    List boltParams = (List<String>) JsonPath.read(conf,
            "$.deck36_storm.KittenRobbersFromOuterSpaceBolt.params");
    if (boltParams != null)
        command.addAll(boltParams);

    // Log the final command
    log.info("Command to start bolt for KittenRobbersFromOuterSpace: " + Arrays.toString(command.toArray()));

    // Add constructed external bolt command to topology using MultilangAdapterBolt
    builder.setBolt("badge", new MultilangAdapterTickTupleBolt(command,
            (Integer) JsonPath.read(conf, "$.deck36_storm.KittenRobbersFromOuterSpaceBolt.robber_frequency"),
            "badge"), parallelism_hint).setNumTasks(num_tasks);

    builder.setBolt("rabbitmq_router",
            new Plan9RabbitMQRouterBolt(
                    (String) JsonPath.read(conf,
                            "$.deck36_storm.KittenRobbersFromOuterSpaceBolt.rabbitmq.target_exchange"),
                    "KittenRobbers" // RabbitMQ routing key
            ), parallelism_hint).setNumTasks(num_tasks).shuffleGrouping("badge");

    builder.setBolt("rabbitmq_producer", new Plan9RabbitMQPushBolt(), parallelism_hint).setNumTasks(num_tasks)
            .shuffleGrouping("rabbitmq_router");

    if ("dev".equals(env)) {
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology(badgeName + System.currentTimeMillis(), conf, builder.createTopology());
        Thread.sleep(2000000);
    }

    if ("prod".equals(env)) {
        StormSubmitter.submitTopology(badgeName + "-" + System.currentTimeMillis(), conf,
                builder.createTopology());
    }

}

From source file:me.ryandowling.TwitchTools.java

public static void main(String[] args) {
    loadSettings();//from ww  w.j  a va2 s.c om

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            saveSettings();
        }
    });

    if (args.length == 0) {
        System.err.println("Invalid number of arguments specified!");
        System.exit(1);
    } else if (args.length >= 1 && args.length <= 4) {
        switch (args[0]) {
        case "Followers":
            if (args.length == 4) {
                new Followers(args[1], Integer.parseInt(args[2]), Boolean.parseBoolean(args[3])).run();
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.exit(1);
            }
            break;
        case "MicrophoneStatus":
            if (args.length == 3) {
                final int delay = Integer.parseInt(args[1]);
                final boolean guiDisplay = Boolean.parseBoolean(args[2]);

                new MicrophoneStatus(delay, guiDisplay);
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.err.println("Arguments are: [delay in ms for updates] [if the gui should show]!");
                System.err.println("For example: [100] [true]!");
                System.exit(1);
            }
            break;
        case "NowPlayingConverter":
            if (args.length == 2) {
                final int delay = Integer.parseInt(args[1]);
                new NowPlayingConverter(delay).run();
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.err.println("Arguments are: [delay in ms for updates]!");
                System.err.println("For example: [100]!");
                System.exit(1);
            }
            break;
        case "MusicCreditsGenerator":
            if (args.length == 2) {
                final String type = args[1];

                if (type.equalsIgnoreCase("html") || type.equalsIgnoreCase("october")
                        || type.equalsIgnoreCase("markdown")) {
                    new MusicCreditsGenerator(type).run();
                } else {
                    System.err.println("Invalid type argument specified!");
                    System.err.println("Arguments are: [type of output to generate (html|markdown|october)]!");
                    System.err.println("For example: [html]!");
                    System.exit(1);
                }
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.err.println("Arguments are: [delay in ms for updates]!");
                System.err.println("For example: [100]!");
                System.exit(1);
            }
            break;
        case "SteamGamesGenerator":
            if (args.length == 2) {
                final String type = args[1];

                if (type.equalsIgnoreCase("october")) {
                    new SteamGamesGenerator(type).run();
                } else {
                    System.err.println("Invalid type argument specified!");
                    System.err.println("Arguments are: [type of output to generate (october)]!");
                    System.err.println("For example: [october]!");
                    System.exit(1);
                }
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.err.println("Arguments are: [delay in ms for updates]!");
                System.err.println("For example: [100]!");
                System.exit(1);
            }
            break;
        case "FoobarControls":
            if (args.length == 1) {
                new FoobarControls().run();
            } else {
                System.err.println("Invalid number of arguments specified!");
                System.err.println("There are no arguments to provide!");
                System.exit(1);
            }
            break;
        default:
            System.err.println("Invalid tool name specified!");
            System.exit(1);
        }
    }
}

From source file:SketchPanel.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("Sketch");
    frame.setSize(300, 200);/*from   www.j a v  a 2 s .  co m*/
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    Container contentPane = frame.getContentPane();
    contentPane.add(new SketchPanel());

    frame.show();
}

From source file:examples.weatherTelnet.java

public final static void main(String[] args) {
    TelnetClient telnet;//from ww w  .  jav a2s  . c  om

    telnet = new TelnetClient();

    try {
        telnet.connect("rainmaker.wunderground.com", 3000);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(), System.in, System.out);

    try {
        telnet.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    System.exit(0);
}

From source file:dk.teachus.backend.database.SchemaExport.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext(
            new String[] { "/dk/teachus/backend/applicationContext.xml",
                    "/dk/teachus/backend/database/applicationContext-schemaExport.xml", });

    LocalSessionFactoryBean sessionFactory = (LocalSessionFactoryBean) context.getBean("&sessionFactory");

    org.hibernate.tool.hbm2ddl.SchemaExport export = new org.hibernate.tool.hbm2ddl.SchemaExport(
            sessionFactory.getConfiguration());
    export.setOutputFile("target/schema.sql");
    export.execute(false, false, false, true);

    System.exit(0);
}

From source file:fm.last.irccat.IRCCat.java

public static void main(String[] args) throws Exception {
    try {//from  ww w .j a  v  a2s .c  o  m
        if (args.length == 0) {
            System.out.println("first param should be config file");
            System.exit(-1);
        }
        XMLConfiguration c = null;
        try {
            c = new XMLConfiguration(args[0]);
        } catch (ConfigurationException cex) {
            System.err.println("Configuration error, check config file");
            cex.printStackTrace();
            System.exit(1);
        }

        IRCCat bot = new IRCCat(c);

        // listen for stuff and send it to irc:
        ServerSocket serverSocket = null;
        InetAddress inet = null;
        try {
            if (bot.getCatIP() != null)
                inet = InetAddress.getByName(bot.getCatIP());
        } catch (UnknownHostException ex) {
            System.out.println("Could not resolve config cat.ip, fix your config");
            ex.printStackTrace();
            System.exit(2);
        }

        try {
            serverSocket = new ServerSocket(bot.getCatPort(), 0, inet);
        } catch (IOException e) {
            System.err.println("Could not listen on port: " + bot.getCatPort());
            System.exit(1);
        }

        System.out.println("Listening on " + bot.getCatIP() + " : " + bot.getCatPort());

        while (true) {
            try {
                Socket clientSocket = serverSocket.accept();
                // System.out.println("Connection on catport from: "
                // + clientSocket.getInetAddress().toString());
                CatHandler handler = new CatHandler(clientSocket, bot);
                handler.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}