List of usage examples for java.lang System exit
public static void exit(int status)
From source file:com.netsteadfast.greenstep.tools.BusinessProcessManagementDeleteTools.java
public static void main(String args[]) { if (args == null || args.length < 1) { printDetails();/* w ww. j av a2s . com*/ System.exit(1); } boolean force = false; String resourceId = args[1]; String forceStr = StringUtils.defaultString(args[0]).trim().toLowerCase(); if ("true".equals(forceStr)) { force = true; } try { BackgroundProgramUserUtils.login(); BusinessProcessManagementUtils.deleteDeployment(resourceId, force); } catch (Exception e) { e.printStackTrace(); } finally { try { BackgroundProgramUserUtils.logout(); } catch (Exception e) { e.printStackTrace(); } } System.exit(1); }
From source file:net.cyllene.hackerrank.downloader.HackerrankDownloader.java
public static void main(String[] args) { // Parse arguments and set up the defaults DownloaderSettings.cmd = parseArguments(args); if (DownloaderSettings.cmd.hasOption("help")) { printHelp();//ww w.ja va 2 s . c o m System.exit(0); } if (DownloaderSettings.cmd.hasOption("verbose")) { DownloaderSettings.beVerbose = true; } /** * Output directory logic: * 1) if directory exists, ask for -f option to overwrite, quit with message * 2) if -f flag is set, check if user has access to a parent directory * 3) if no access, quit with error * 4) if everything is OK, remember the path */ String sDesiredPath = DownloaderSettings.outputDir; if (DownloaderSettings.cmd.hasOption("directory")) { sDesiredPath = DownloaderSettings.cmd.getOptionValue("d", DownloaderSettings.outputDir); } if (DownloaderSettings.beVerbose) { System.out.println("Checking output dir: " + sDesiredPath); } Path desiredPath = Paths.get(sDesiredPath); if (Files.exists(desiredPath) && Files.isDirectory(desiredPath)) { if (!DownloaderSettings.cmd.hasOption("f")) { System.out.println("I wouldn't like to overwrite existing directory: " + sDesiredPath + ", set the --force flag if you are sure. May lead to data loss, be careful."); System.exit(0); } else { System.out.println( "WARNING!" + System.lineSeparator() + "--force flag is set. Overwriting directory: " + sDesiredPath + System.lineSeparator() + "WARNING!"); } } if ((Files.exists(desiredPath) && !Files.isWritable(desiredPath)) || !Files.isWritable(desiredPath.getParent())) { System.err .println("Fatal error: " + sDesiredPath + " cannot be created or modified. Check permissions."); // TODO: use Exceptions instead of system.exit System.exit(1); } DownloaderSettings.outputDir = sDesiredPath; Integer limit = DownloaderSettings.ITEMS_TO_DOWNLOAD; if (DownloaderSettings.cmd.hasOption("limit")) { try { limit = ((Number) DownloaderSettings.cmd.getParsedOptionValue("l")).intValue(); } catch (ParseException e) { System.out.println("Incorrect limit: " + e.getMessage() + System.lineSeparator() + "Using default value: " + limit); } } Integer offset = DownloaderSettings.ITEMS_TO_SKIP; if (DownloaderSettings.cmd.hasOption("offset")) { try { offset = ((Number) DownloaderSettings.cmd.getParsedOptionValue("o")).intValue(); } catch (ParseException e) { System.out.println("Incorrect offset: " + e.getMessage() + " Using default value: " + offset); } } DownloaderCore dc = DownloaderCore.INSTANCE; List<HRChallenge> challenges = new LinkedList<>(); // Download everything first Map<String, List<Integer>> structure = null; try { structure = dc.getStructure(offset, limit); } catch (IOException e) { System.err.println("Fatal Error: could not get data structure."); e.printStackTrace(); System.exit(1); } challengesLoop: for (Map.Entry<String, List<Integer>> entry : structure.entrySet()) { String challengeSlug = entry.getKey(); HRChallenge currentChallenge = null; try { currentChallenge = dc.getChallengeDetails(challengeSlug); } catch (IOException e) { System.err.println("Error: could not get challenge info for: " + challengeSlug); if (DownloaderSettings.beVerbose) { e.printStackTrace(); } continue challengesLoop; } submissionsLoop: for (Integer submissionId : entry.getValue()) { HRSubmission submission = null; try { submission = dc.getSubmissionDetails(submissionId); } catch (IOException e) { System.err.println("Error: could not get submission info for: " + submissionId); if (DownloaderSettings.beVerbose) { e.printStackTrace(); } continue submissionsLoop; } // TODO: probably should move filtering logic elsewhere(getStructure, maybe) if (submission.getStatus().equalsIgnoreCase("Accepted")) { currentChallenge.getSubmissions().add(submission); } } challenges.add(currentChallenge); } // Now dump all data to disk try { for (HRChallenge currentChallenge : challenges) { if (currentChallenge.getSubmissions().isEmpty()) continue; final String sChallengePath = DownloaderSettings.outputDir + "/" + currentChallenge.getSlug(); final String sSolutionPath = sChallengePath + "/accepted_solutions"; final String sDescriptionPath = sChallengePath + "/problem_description"; Files.createDirectories(Paths.get(sDescriptionPath)); Files.createDirectories(Paths.get(sSolutionPath)); // FIXME: this should be done the other way String plainBody = currentChallenge.getDescriptions().get(0).getBody(); String sFname; if (!plainBody.equals("null")) { sFname = sDescriptionPath + "/english.txt"; if (DownloaderSettings.beVerbose) { System.out.println("Writing to: " + sFname); } Files.write(Paths.get(sFname), plainBody.getBytes(StandardCharsets.UTF_8.name())); } String htmlBody = currentChallenge.getDescriptions().get(0).getBodyHTML(); String temporaryHtmlTemplate = "<html></body>" + htmlBody + "</body></html>"; sFname = sDescriptionPath + "/english.html"; if (DownloaderSettings.beVerbose) { System.out.println("Writing to: " + sFname); } Files.write(Paths.get(sFname), temporaryHtmlTemplate.getBytes(StandardCharsets.UTF_8.name())); for (HRSubmission submission : currentChallenge.getSubmissions()) { sFname = String.format("%s/%d.%s", sSolutionPath, submission.getId(), submission.getLanguage()); if (DownloaderSettings.beVerbose) { System.out.println("Writing to: " + sFname); } Files.write(Paths.get(sFname), submission.getSourceCode().getBytes(StandardCharsets.UTF_8.name())); } } } catch (IOException e) { System.err.println("Fatal Error: couldn't dump data to disk."); System.exit(1); } }
From source file:com.thoughtworks.go.server.util.GoLauncher.java
public static void main(String[] args) { assertVMVersion();//from w w w . j a v a 2 s . c om SystemEnvironment systemEnvironment = new SystemEnvironment(); systemEnvironment.setProperty(GoConstants.USE_COMPRESSED_JAVASCRIPT, Boolean.toString(true)); LogConfigurator logConfigurator = new LogConfigurator(DEFAULT_LOGBACK_CONFIGURATION_FILE); logConfigurator.initialize(); try { cleanupTempFiles(); new GoServer().go(); } catch (Exception e) { System.err.println("ERROR: Failed to start GoCD server. Please check the logs."); e.printStackTrace(); System.exit(1); } }
From source file:bdsup2sub.BDSup2Sub.java
public static void main(String[] args) { try {/* w ww .j av a2s.c o m*/ new BDSup2Sub().run(args); } catch (Exception e) { fatalError(e.getMessage()); System.exit(1); } }
From source file:com.congiu.load.csv.Main.java
public static void main(String[] args) { Options opts = buildCommandLineOptions(); Configuration conf = new Configuration(); try {// w w w . j a v a 2 s .c om CommandLine cmd = processArguments(opts, args); if (cmd.hasOption(OPT_HELP[0])) { printUsage(opts, new PrintWriter(System.out)); System.exit(0); } // all unprocessed arguments are files. // let's first check if they all exist for (String s : cmd.getArgs()) { if (!FSUtils.fileExists(conf, s)) { throw new Exception("File " + s + " does not exist."); } } CSVConverter converter = getCSVConverter(cmd); for (String s : cmd.getArgs()) { } } catch (Exception ex) { System.err.println("There was a problem parsing your arguments."); System.err.println(ex); printUsage(opts, new PrintWriter(System.err)); System.exit(-1); } }
From source file:it.geosolutions.utils.db.Gml2shp.java
/** * @param args// ww w .j a v a 2s . co m */ public static void main(String[] args) { Gml2shp g2s = new Gml2shp(); if (!g2s.parseArgs(args)) { System.exit(1); } try { g2s.importGmlIntoShp(new File(gmlfile), new File(shpfile)); } catch (Exception e) { e.printStackTrace(); } }
From source file:Bounce.java
/** * The main method./*from w w w . j a v a 2 s . c o m*/ */ public static void main(String[] args) { if (args.length < 3) { printUsage(); System.exit(1); } int localPort; try { localPort = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.err.println("Bad local port value: " + args[0]); printUsage(); System.exit(2); return; } String hostname = args[1]; int remotePort; try { remotePort = Integer.parseInt(args[2]); } catch (NumberFormatException e) { System.err.println("Bad remote port value: " + args[2]); printUsage(); System.exit(3); return; } boolean shouldLog = args.length > 3 ? Boolean.valueOf(args[3]).booleanValue() : false; int numConnections = 0; try { ServerSocket ssock = new ServerSocket(localPort); while (true) { Socket incomingSock = ssock.accept(); Socket outgoingSock = new Socket(hostname, remotePort); numConnections++; InputStream incomingIn = incomingSock.getInputStream(); InputStream outgoingIn = outgoingSock.getInputStream(); OutputStream incomingOut = incomingSock.getOutputStream(); OutputStream outgoingOut = outgoingSock.getOutputStream(); if (shouldLog) { String incomingLogName = "in-log-" + incomingSock.getInetAddress().getHostName() + "(" + localPort + ")-" + numConnections + ".dat"; String outgoingLogName = "out-log-" + hostname + "(" + remotePort + ")-" + numConnections + ".dat"; OutputStream incomingLog = new FileOutputStream(incomingLogName); incomingOut = new MultiOutputStream(incomingOut, incomingLog); OutputStream outgoingLog = new FileOutputStream(outgoingLogName); outgoingOut = new MultiOutputStream(outgoingOut, outgoingLog); } PumpThread t1 = new PumpThread(incomingIn, outgoingOut); PumpThread t2 = new PumpThread(outgoingIn, incomingOut); t1.start(); t2.start(); } } catch (IOException e) { e.printStackTrace(); System.exit(3); } }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/*from w w w . j a v a 2 s . c om*/ } 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); tray.removePropertyChangeListener("trayIcons", pcl); Thread.sleep(3000); System.exit(0); }
From source file:com.github.braully.graph.UtilResultCompare.java
public static void main(String... args) throws Exception { Options options = new Options(); Option input = new Option("i", "input", true, "input file path"); input.setRequired(false);/*from w ww . j a v a2s . c o m*/ options.addOption(input); Option output = new Option("o", "output", true, "output file"); output.setRequired(false); options.addOption(output); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("UtilResult", options); System.exit(1); return; } String inputFilePath = cmd.getOptionValue("input"); if (inputFilePath == null) { inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-quartic-ht.txt"; // inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-mft-parcial-ht.txt"; // inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-highlyirregular-ht.txt"; // inputFilePath = "/home/strike/Documentos/grafos-processados/mtf/resultado-ht.txt"; // inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-hypo-parcial-ht.txt"; // inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-eul-ht.txt"; // inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-almhypo-ht.txt"; // inputFilePath = "/home/strike/Dropbox/documentos/mestrado/resultado-processamento-grafos/resultado-Almost_hypohamiltonian_graphs_cubic-parcial-ht.txt"; } if (inputFilePath != null) { if (inputFilePath.toLowerCase().endsWith(".txt")) { processFileTxt(inputFilePath); } else if (inputFilePath.toLowerCase().endsWith(".json")) { processFileJson(inputFilePath); } } }
From source file:com.espertech.esperio.regression.adapter.SupportJMSSender.java
public static void main(String[] args) throws JMSException { SupportJMSSender sender = new SupportJMSSender(); //sender.sendSerializable("hello"); Map<String, Object> values = new HashMap<String, Object>(); values.put("prop1", "a"); sender.sendMap(values);/* w ww .jav a2 s . c o m*/ sender.destroy(); System.exit(1); }