List of usage examples for java.lang System exit
public static void exit(int status)
From source file:examples.fwhois.java
public static final void main(String[] args) { int index;/*from ww w . j a v a 2 s . c om*/ String handle, host; InetAddress address = null; WhoisClient whois; if (args.length != 1) { System.err.println("usage: fwhois handle[@<server>]"); System.exit(1); } index = args[0].lastIndexOf("@"); whois = new WhoisClient(); // We want to timeout if a response takes longer than 60 seconds whois.setDefaultTimeout(60000); if (index == -1) { handle = args[0]; host = WhoisClient.DEFAULT_HOST; } else { handle = args[0].substring(0, index); host = args[0].substring(index + 1); } try { address = InetAddress.getByName(host); } catch (UnknownHostException e) { System.err.println("Error unknown host: " + e.getMessage()); System.exit(1); } System.out.println("[" + address.getHostName() + "]"); try { whois.connect(address); System.out.print(whois.query(handle)); whois.disconnect(); } catch (IOException e) { System.err.println("Error I/O exception: " + e.getMessage()); System.exit(1); } }
From source file:example.Example.java
public static void main(String[] args) { if (args.length == 0) { System.err.println("Usage: Example username:password ... [-f twitter_id ...] [-t keyword]"); System.exit(1); }/* w w w .j a v a2 s. c o m*/ Collection<String> credentials = new ArrayList<String>(); Collection<String> followIds = null; Collection<String> trackKeywords = null; Collection<String> list = credentials; for (int i = 0; i < args.length; i++) { String arg = args[i]; if (arg.equals("-f")) { followIds = new ArrayList<String>(); list = followIds; } else if (arg.equals("-t")) { trackKeywords = new ArrayList<String>(); list = trackKeywords; } else { list.add(arg); } } final Collection<String> finalFollowIds = followIds; final Collection<String> finalTrackKeywords = trackKeywords; FilterParameterFetcher filterParameterFetcher = new FilterParameterFetcher() { public Collection<String> getFollowIds() { return finalFollowIds; } public Collection<String> getTrackKeywords() { return finalTrackKeywords; } }; new TwitterClient(filterParameterFetcher, new ExampleTwitterStreamProcessor(), "http://stream.twitter.com/1/statuses/filter.json", 200, 10, credentials, 60 * 1000L).execute(); }
From source file:Main.java
public static void main(String[] args) { JFrame parentFrame = new JFrame(); parentFrame.setSize(500, 150);/*from w ww . j av a 2 s. c o m*/ JLabel jl = new JLabel(); jl.setText("Count : 0"); parentFrame.add(BorderLayout.CENTER, jl); parentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); parentFrame.setVisible(true); final JDialog dlg = new JDialog(parentFrame, "Progress Dialog", true); JProgressBar dpb = new JProgressBar(0, 500); dlg.add(BorderLayout.CENTER, dpb); dlg.add(BorderLayout.NORTH, new JLabel("Progress...")); dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dlg.setSize(300, 75); dlg.setLocationRelativeTo(parentFrame); Thread t = new Thread(new Runnable() { public void run() { dlg.setVisible(true); } }); t.start(); for (int i = 0; i <= 500; i++) { jl.setText("Count : " + i); dpb.setValue(i); if (dpb.getValue() == 500) { dlg.setVisible(false); System.exit(0); } try { Thread.sleep(25); } catch (InterruptedException e) { e.printStackTrace(); } } dlg.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); conn.setAutoCommit(false);// w w w.ja va 2 s . com Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int, name VARCHAR(30) );"); String INSERT_RECORD = "insert into survey(id, name) values(?,?)"; PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD); pstmt.setString(1, "1"); pstmt.setString(2, "name1"); pstmt.addBatch(); pstmt.setString(1, "2"); pstmt.setString(2, "name2"); pstmt.addBatch(); try { // execute the batch int[] updateCounts = pstmt.executeBatch(); } catch (BatchUpdateException e) { int[] updateCounts = e.getUpdateCounts(); checkUpdateCounts(updateCounts); try { conn.rollback(); } catch (Exception e2) { e.printStackTrace(); System.exit(1); } } // since there were no errors, commit conn.commit(); ResultSet rs = st.executeQuery("SELECT * FROM survey"); outputResultSet(rs); rs.close(); st.close(); conn.close(); }
From source file:TestSupportsTransactions.java
public static void main(String[] args) throws Exception { Connection conn = getOracleConnection(); try {/*from w w w .j ava 2s. c om*/ System.out.println("conn=" + conn); System.out.println("Transaction Support:" + supportsTransactions(conn)); } catch (Exception e) { e.printStackTrace(); System.exit(1); } finally { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:org.ala.lucene.OptimizeIndex.java
public static void main(String[] args) throws Exception { ApplicationContext context = SpringUtils.getContext(); SolrUtils solrUtils = (SolrUtils) context.getBean(SolrUtils.class); solrUtils.getSolrServer().optimize(); System.exit(0); }
From source file:DOMImport.java
static public void main(String[] arg) { if (arg.length != 3) { System.err.println("Usage: DOMImport <infile1> <infile2> <outfile>"); System.exit(1); }/*from w w w .j av a 2 s.c o m*/ DOMImport dc = new DOMImport(); dc.inandout(arg[0], arg[1], arg[2]); }
From source file:com.mycompany.test.Jaroop.java
/** * This is the main program which will receive the request, calls required methods * and processes the response./*www. j a va 2 s . c o m*/ * @param args * @throws IOException */ public static void main(String[] args) throws IOException { Scanner scannedInput = new Scanner(System.in); String in = ""; if (args.length == 0) { System.out.println("Enter the query"); in = scannedInput.nextLine(); } else { in = args[0]; } in = in.toLowerCase().replaceAll("\\s+", "_"); int httpStatus = checkInvalidInput(in); if (httpStatus == 0) { System.out.print("Not found"); System.exit(0); } String url = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=" + in; HttpURLConnection connection = getConnection(url); BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream())); String request = ""; StringBuilder response = new StringBuilder(); while ((request = input.readLine()) != null) { //only appending what ever is required for JSON parsing and ignoring the rest response.append("{"); //appending the key "extract" to the string so that the JSON parser can parse it's value, //also we don't need last 3 paranthesis in the response, excluding them as well. response.append(request.substring(request.indexOf("\"extract"), request.length() - 3)); } parseJSON(response.toString()); }
From source file:ColorAction.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setTitle("SeparateGUITest"); frame.setSize(300, 200);/*from w w w .java2 s .c o m*/ frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); JPanel panel = new JPanel(); Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.blue, panel); Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.yellow, panel); Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.red, panel); panel.add(new JButton(yellowAction)); panel.add(new JButton(blueAction)); panel.add(new JButton(redAction)); panel.registerKeyboardAction(yellowAction, KeyStroke.getKeyStroke(KeyEvent.VK_Y, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); panel.registerKeyboardAction(blueAction, KeyStroke.getKeyStroke(KeyEvent.VK_B, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); panel.registerKeyboardAction(redAction, KeyStroke.getKeyStroke(KeyEvent.VK_R, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); Container contentPane = frame.getContentPane(); contentPane.add(panel); JMenu m = new JMenu("Color"); m.add(yellowAction); m.add(blueAction); m.add(redAction); JMenuBar mbar = new JMenuBar(); mbar.add(m); frame.setJMenuBar(mbar); frame.show(); }
From source file:com.manning.blogapps.chapter10.examples.AuthPut.java
public static void main(String[] args) throws Exception { if (args.length < 4) { System.out.println("USAGE: authput <username> <password> <filepath> <url>"); System.exit(-1); }//from www .j a v a 2 s . c o m String credentials = args[0] + ":" + args[1]; String filepath = args[2]; String url = args[3]; HttpClient httpClient = new HttpClient(); EntityEnclosingMethod method = new PutMethod(url); method.setRequestHeader("Authorization", "Basic " + new String(Base64.encodeBase64(credentials.getBytes()))); File upload = new File(filepath); method.setRequestHeader("name", upload.getName()); String contentType = "application/atom+xml; charset=utf8"; if (filepath.endsWith(".gif")) contentType = "image/gif"; else if (filepath.endsWith(".jpg")) contentType = "image/jpg"; method.setRequestHeader("Content-type", contentType); method.setRequestBody(new FileInputStream(filepath)); httpClient.executeMethod(method); System.out.println(method.getResponseBodyAsString()); }