List of usage examples for java.lang System exit
public static void exit(int status)
From source file:fsm.test.TestDao.java
public static void main(String args[]) throws Exception { testAgentProductDao(); System.exit(0); }
From source file:GradientPaintDemo.java
public static void main(String s[]) { JFrame f = new JFrame(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); }//from w w w . j ava2 s . c om }); GradientPaintDemo p = new GradientPaintDemo(); f.getContentPane().add("Center", p); p.init(); f.pack(); f.setSize(new Dimension(250, 250)); f.show(); }
From source file:MainClass.java
public static void main(String[] args) { int count = 100; long[] numbers = new long[count]; for (int i = 0; i < numbers.length; i++) { numbers[i] = i;//from w ww. j a v a 2 s .co m } File aFile = new File("data.bin"); FileOutputStream outputFile = null; try { outputFile = new FileOutputStream(aFile); } catch (FileNotFoundException e) { e.printStackTrace(System.err); System.exit(1); } FileChannel file = outputFile.getChannel(); final int BUFFERSIZE = 100; ByteBuffer buf = ByteBuffer.allocate(BUFFERSIZE); LongBuffer longBuf = buf.asLongBuffer(); int numberWritten = 0; while (numberWritten < numbers.length) { longBuf.put(numbers, numberWritten, min(longBuf.capacity(), numbers.length - numberWritten)); buf.limit(8 * longBuf.position()); try { file.write(buf); numberWritten += longBuf.position(); } catch (IOException e) { e.printStackTrace(System.err); System.exit(1); } longBuf.clear(); buf.clear(); } try { System.out.println("File written is " + file.size() + " bytes."); outputFile.close(); } catch (IOException e) { e.printStackTrace(System.err); System.exit(1); } }
From source file:MainClass.java
public static void main(String[] argv) { JFrame frame = new MainClass(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); }// w w w . j a v a 2 s.c o m }); frame.pack(); frame.setVisible(true); }
From source file:MulticastSniffer.java
public static void main(String[] args) { InetAddress ia = null;//from w w w . jav a 2 s .com byte[] buffer = new byte[65509]; DatagramPacket dp = new DatagramPacket(buffer, buffer.length); int port = 0; try { try { ia = InetAddress.getByName(args[0]); } catch (UnknownHostException e) { // } port = Integer.parseInt(args[1]); } // end try catch (Exception e) { System.err.println(e); System.err.println("Usage: java MulticastSniffer MulticastAddress port"); System.exit(1); } try { MulticastSocket ms = new MulticastSocket(port); ms.joinGroup(ia); while (true) { ms.receive(dp); String s = new String(dp.getData(), 0, 0, dp.getLength()); System.out.println(s); } } catch (SocketException se) { System.err.println(se); } catch (IOException ie) { System.err.println(ie); } }
From source file:RandomFileTest.java
public static void main(String[] args) { Employee[] staff = new Employee[3]; staff[0] = new Employee("Harry Hacker", 35000); staff[1] = new Employee("Carl Cracker", 75000); staff[2] = new Employee("Tony Tester", 38000); try {/*from w w w .j a va 2s. c o m*/ DataOutputStream out = new DataOutputStream(new FileOutputStream("employee.dat")); for (int i = 0; i < staff.length; i++) staff[i].writeData(out); out.close(); } catch (IOException e) { System.out.print("Error: " + e); System.exit(1); } try { RandomAccessFile in = new RandomAccessFile("employee.dat", "r"); int count = (int) (in.length() / Employee.RECORD_SIZE); Employee[] newStaff = new Employee[count]; for (int i = count - 1; i >= 0; i--) { newStaff[i] = new Employee(); in.seek(i * Employee.RECORD_SIZE); newStaff[i].readData(in); } for (int i = 0; i < newStaff.length; i++) newStaff[i].print(); } catch (IOException e) { System.out.print("Error: " + e); System.exit(1); } }
From source file:ShowMethods.java
public static void main(String[] args) { if (args.length < 1) { System.out.println(usage); System.exit(0); }/*from w w w. j a va 2s. c om*/ int lines = 0; try { Class c = Class.forName(args[0]); Method[] m = c.getMethods(); Constructor[] ctor = c.getConstructors(); if (args.length == 1) { for (int i = 0; i < m.length; i++) System.out.println(p.matcher(m[i].toString()).replaceAll("")); for (int i = 0; i < ctor.length; i++) System.out.println(p.matcher(ctor[i].toString()).replaceAll("")); lines = m.length + ctor.length; } else { for (int i = 0; i < m.length; i++) if (m[i].toString().indexOf(args[1]) != -1) { System.out.println(p.matcher(m[i].toString()).replaceAll("")); lines++; } for (int i = 0; i < ctor.length; i++) if (ctor[i].toString().indexOf(args[1]) != -1) { System.out.println(p.matcher(ctor[i].toString()).replaceAll("")); lines++; } } } catch (ClassNotFoundException e) { System.out.println("No such class: " + e); } }
From source file:NameLister.java
public static void main(String args[]) { if (args.length != 1) { System.err.println("Usage: java NameLister xmlfile.xml"); System.exit(-1); }//w w w . j av a 2 s .co m try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new DefaultHandler() { boolean name = false; public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equalsIgnoreCase("NAME")) { name = true; } } public void characters(char ch[], int start, int length) throws SAXException { if (name) { System.out.println("Name: " + new String(ch, start, length)); name = false; } } }; saxParser.parse(args[0], handler); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.threerings.getdown.tools.AppletParamSigner.java
public static void main(String[] args) { try {// w w w . j a va 2 s . c o m if (args.length != 7) { System.err .println("AppletParamSigner keystore storepass alias keypass " + "appbase appname imgpath"); System.exit(255); } String keystore = args[0]; String storepass = args[1]; String alias = args[2]; String keypass = args[3]; String appbase = args[4]; String appname = args[5]; String imgpath = args[6]; String params = appbase + appname + imgpath; KeyStore store = KeyStore.getInstance("JKS"); store.load(new BufferedInputStream(new FileInputStream(keystore)), storepass.toCharArray()); PrivateKey key = (PrivateKey) store.getKey(alias, keypass.toCharArray()); Signature sig = Signature.getInstance("SHA1withRSA"); sig.initSign(key); sig.update(params.getBytes()); String signed = new String(Base64.encodeBase64(sig.sign())); System.out.println("<param name=\"appbase\" value=\"" + appbase + "\" />"); System.out.println("<param name=\"appname\" value=\"" + appname + "\" />"); System.out.println("<param name=\"bgimage\" value=\"" + imgpath + "\" />"); System.out.println("<param name=\"signature\" value=\"" + signed + "\" />"); } catch (Exception e) { System.err.println("Failed to produce signature."); e.printStackTrace(); } }
From source file:DataFileTest.java
public static void main(String[] args) { Employee staff = new Employee("Java Source", 35500); staff.raiseSalary(5.25);// ww w . j a v a 2s . c o m try { PrintWriter out = new PrintWriter(new FileWriter("employee.dat")); writeData(staff, out); out.close(); } catch (IOException e) { System.out.print("Error: " + e); System.exit(1); } try { BufferedReader in = new BufferedReader(new FileReader("employee.dat")); Employee e = readData(in); e.print(); in.close(); } catch (IOException e) { System.out.print("Error: " + e); System.exit(1); } }