List of usage examples for java.lang System exit
public static void exit(int status)
From source file:examples.mail.IMAPMail.java
public static void main(String[] args) { if (args.length < 3) { System.err.println("Usage: IMAPMail <imap server hostname> <username> <password> [TLS]"); System.exit(1); }/*from ww w .j a v a 2s . c om*/ String server = args[0]; String username = args[1]; String password = args[2]; String proto = (args.length > 3) ? args[3] : null; IMAPClient imap; if (proto != null) { System.out.println("Using secure protocol: " + proto); imap = new IMAPSClient(proto, true); // implicit // enable the next line to only check if the server certificate has expired (does not check chain): // ((IMAPSClient) imap).setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager()); // OR enable the next line if the server uses a self-signed certificate (no checks) // ((IMAPSClient) imap).setTrustManager(TrustManagerUtils.getAcceptAllTrustManager()); } else { imap = new IMAPClient(); } System.out.println("Connecting to server " + server + " on " + imap.getDefaultPort()); // We want to timeout if a response takes longer than 60 seconds imap.setDefaultTimeout(60000); // suppress login details imap.addProtocolCommandListener(new PrintCommandListener(System.out, true)); try { imap.connect(server); } catch (IOException e) { throw new RuntimeException("Could not connect to server.", e); } try { if (!imap.login(username, password)) { System.err.println("Could not login to server. Check password."); imap.disconnect(); System.exit(3); } imap.setSoTimeout(6000); imap.capability(); imap.select("inbox"); imap.examine("inbox"); imap.status("inbox", new String[] { "MESSAGES" }); imap.logout(); imap.disconnect(); } catch (IOException e) { System.out.println(imap.getReplyString()); e.printStackTrace(); System.exit(10); return; } }
From source file:RegExTest.java
public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter pattern: "); String patternString = in.nextLine(); Pattern pattern = null;/*from w ww . j a v a 2 s . c om*/ try { pattern = Pattern.compile(patternString); } catch (PatternSyntaxException e) { System.out.println("Pattern syntax error"); System.exit(1); } while (true) { System.out.println("Enter string to match: "); String input = in.nextLine(); if (input == null || input.equals("")) return; Matcher matcher = pattern.matcher(input); if (matcher.matches()) { System.out.println("Match"); int g = matcher.groupCount(); if (g > 0) { for (int i = 0; i < input.length(); i++) { for (int j = 1; j <= g; j++) if (i == matcher.start(j)) System.out.print('('); System.out.print(input.charAt(i)); for (int j = 1; j <= g; j++) if (i + 1 == matcher.end(j)) System.out.print(')'); } System.out.println(); } } else System.out.println("No match"); } }
From source file:org.alfresco.util.xml.SchemaHelper.java
public static void main(String... args) { if (args.length < 2 || !args[0].startsWith("--compile-xsd=") && !args[1].startsWith("--output-dir=")) { System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>"); System.exit(1); }//ww w .jav a 2 s . c o m final String urlStr = args[0].substring(14); if (urlStr.length() == 0) { System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>"); System.exit(1); } final String dirStr = args[1].substring(13); if (dirStr.length() == 0) { System.out.println("Usage: SchemaHelper --compile-xsd=<URL> --output-dir=<directory>"); System.exit(1); } try { URL url = ResourceUtils.getURL(urlStr); File dir = new File(dirStr); if (!dir.exists() || !dir.isDirectory()) { System.out.println("Output directory not found: " + dirStr); System.exit(1); } ErrorListener errorListener = new ErrorListener() { public void warning(SAXParseException e) { System.out.println("WARNING: " + e.getMessage()); } public void info(SAXParseException e) { System.out.println("INFO: " + e.getMessage()); } public void fatalError(SAXParseException e) { handleException(urlStr, e); } public void error(SAXParseException e) { handleException(urlStr, e); } }; SchemaCompiler compiler = XJC.createSchemaCompiler(); compiler.setErrorListener(errorListener); compiler.parseSchema(new InputSource(url.toExternalForm())); S2JJAXBModel model = compiler.bind(); if (model == null) { System.out.println("Failed to produce binding model for URL " + urlStr); System.exit(1); } JCodeModel codeModel = model.generateCode(null, errorListener); codeModel.build(dir); } catch (Throwable e) { handleException(urlStr, e); System.exit(1); } }
From source file:eu.optimis.elasticityengine.EETester.java
public static void main(String[] args) throws IOException, InterruptedException { if (args.length != 1) { printUsage();/*from w ww . j a v a 2s .c o m*/ System.exit(-1); } Logger log = Logger.getLogger(ElasticityEngineImpl.class); System.out.println("Testing Elasticity Engine"); System.out.println("One instance per 100 users expected, starting at 1"); ElasticityEngine eEngine = new ElasticityEngineImpl(); String manifest = Util.getManifest(args[0]); String serviceID = "EETester"; // TODO parse somehow? String sp = "SP_Add"; boolean LowRiskMode; ElasticityCallback callback = new CallbackPrinter(); if ("true".equals(System.getProperty("lowrisk"))) { System.out.println("USING Low Risk Mode"); LowRiskMode = true; } else { System.out.println("USING Low cost Mode"); LowRiskMode = false; } eEngine.startElasticity(serviceID, manifest, LowRiskMode, sp); //Call a test-specific method which only returns when we got the -2 recommendation, and the test should then be done. ((CallbackPrinter) callback).awaitLoad(1); System.out.println("\nTest done, exiting"); Thread.sleep(500); }
From source file:gov.va.vinci.leo.tools.GenerateDescriptors.java
/** * Main method for running from the command line. * @param args command line arguements.// w w w.j ava 2s .c o m */ public static void main(String[] args) { if (args.length != 2) { System.out.println( "Usage: GenerateDescriptors <annotator class name> <root directory to write files to>"); System.exit(1); } String annotatorClassName = args[0]; String outputRootPath = args[1]; try { GenerateDescriptors.generate(annotatorClassName, outputRootPath); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. System.exit(2); } System.exit(0); }
From source file:org.apache.niolex.config.main.ConfigServerMain.java
public static void main(String[] args) throws Exception { ApplicationContext ctx = new FileSystemXmlApplicationContext("conf/spring.xml"); ConfigServer cServer = ctx.getBean(ConfigServer.class); if (!cServer.start()) { System.out.println("Failed to start Config Server, system will exit..."); System.exit(-1); }/* w w w . ja v a2 s.co m*/ ConnectionWorker.setAuthInfo("d178b4c149"); BeanServer beanS = new BeanServer(); beanS.putIfAbsent("os", new OSInfo()); beanS.putIfAbsent("conf", ctx.getBean(MemoryStorage.class)); beanS.putIfAbsent("dispatch", ctx.getBean(ConfigEventDispatcher.class)); beanS.putIfAbsent("server", cServer); if (!beanS.start()) { System.out.println("Failed to start Bean Server, system will exit..."); System.exit(-1); } }
From source file:bixo.tools.RunUrlNormalizerTool.java
/** * @param args/* w w w . j a v a2s . c om*/ */ public static void main(String[] args) { String curUrl = null; try { List<String> lines = FileUtils.readLines(new File(args[0])); BaseUrlNormalizer urlNormalizer = new SimpleUrlNormalizer(); for (String url : lines) { curUrl = url; String normalized = urlNormalizer.normalize(curUrl); if (!normalized.equalsIgnoreCase(curUrl)) { System.out.println(curUrl + " ==> " + normalized); } } } catch (Throwable t) { System.err.println("Exception while processing URLs: " + t.getMessage()); System.err.println("Current url: " + curUrl); t.printStackTrace(System.err); System.exit(-1); } }
From source file:Hex.java
public static void main(String[] args) { if (args.length != 3) { System.out.println("Usage: HexStrToBin enc/dec <infileName> <outfilename>"); System.exit(1); }// w w w. j av a2 s .c o m try { ByteArrayOutputStream os = new ByteArrayOutputStream(); InputStream in = new FileInputStream(args[1]); int len = 0; byte buf[] = new byte[1024]; while ((len = in.read(buf)) > 0) os.write(buf, 0, len); in.close(); os.close(); byte[] data = null; if (args[0].equals("dec")) data = decode(os.toString()); else { String strData = encode(os.toByteArray()); data = strData.getBytes(); } FileOutputStream fos = new FileOutputStream(args[2]); fos.write(data); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:ProducerAndConsumerTool.java
public static void main(String[] args) { ConsumerTool consumerTool = new ConsumerTool(); String[] unknown = CommandLineSupport.setOptions(consumerTool, args); HashSet<String> set1 = new HashSet<String>(Arrays.asList(unknown)); ProducerTool producerTool = new ProducerTool(); unknown = CommandLineSupport.setOptions(producerTool, args); HashSet<String> set2 = new HashSet<String>(Arrays.asList(unknown)); set1.retainAll(set2);/*from www. j ava2s . c o m*/ if (set1.size() > 0) { System.out.println("Unknown options: " + set1); System.exit(-1); } consumerTool.run(); producerTool.run(); }
From source file:cs.rsa.ts14.manual.Timesag.java
public static void main(String[] args) throws IOException { // Validate arguments if (args.length != 2) { System.err.println("Usage: Timesag [type] [timesag file]"); System.err.println(" type must be one of (W, C, T)."); System.err.println(" timesag file must obey the specified format."); System.exit(-1); }// ww w . j a va 2 s . co m File file = new File(args[1]); // Configure the Timesag processor based upon report type string. ReportBuilder builder; if (args[0].equals("C")) { builder = new BravoCategoryOverviewBuilder(); // bravo } else if (args[0].equals("W")) { builder = new WeeklyOverviewReportBuilder(); // charlie } else { builder = new TransportReportBuilder(); // delta } LineSequenceState sequenceState = new InitialState(); TimesagLineProcessor tlp = new StandardTimesagLineProcessor(new BravoLineTypeClassifierStrategy(), builder, sequenceState); TimesagEngine engine = new TimesagEngine(); System.out.print(engine.getTimesagReport(file, tlp)); }