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:com.aliyun.odps.mapred.cli.Cli.java

public static void main(String[] args) {
    SessionState ss = SessionState.get();
    OptionParser parser = new OptionParser(ss);
    try {//from w w w.  j  a va  2 s. c  o  m
        parser.parse(args);
    } catch (FileNotFoundException e) {
        System.err.println(e.getMessage());
        System.exit(-1);
    } catch (ClassNotFoundException e) {
        System.err.println("Class not found:" + e.getMessage());
        System.exit(-1);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        parser.usage();
        System.exit(-1);
    } catch (OdpsException e) {
        System.err.println(e.getMessage());
        System.exit(-1);
    }

    try {
        Method main = parser.getMainClass().getMethod("main", String[].class);
        main.invoke(null, (Object) parser.getArguments());
    } catch (InvocationTargetException e) {
        Throwable t = e.getCause();
        if (t != null && t instanceof OdpsException) {
            OdpsException ex = (OdpsException) t;
            System.err.println(ex.getErrorCode() + ":" + ex.getMessage());
            System.exit(-1);
        } else {
            throw new RuntimeException("Unknown error", e);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.asual.summer.onejar.OneJarServer.java

public static void main(String[] args) throws Exception {
    Server server = new Server(Integer.valueOf(System.getProperty("server.port", "8080")));
    server.setHandler(new WebAppContext(getCurrentWarFile(), System.getProperty("server.contextPath", "/")));
    try {//from w  w  w  . ja v a 2s.  c  o m
        server.start();
    } catch (Exception e) {
        server.stop();
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:ClipTest.java

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

    // specify the sound to play
    // (assuming the sound can be played by the audio system)
    File soundFile = new File("../sounds/voice.wav");
    AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile);

    // load the sound into memory (a Clip)
    DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());
    Clip clip = (Clip) AudioSystem.getLine(info);
    clip.open(sound);/*from  w w w. j a  v  a2 s  . c om*/

    // due to bug in Java Sound, explicitly exit the VM when
    // the sound has stopped.
    clip.addLineListener(new LineListener() {
        public void update(LineEvent event) {
            if (event.getType() == LineEvent.Type.STOP) {
                event.getLine().close();
                System.exit(0);
            }
        }
    });

    // play the sound clip
    clip.start();
}

From source file:edu.cuhk.hccl.SequenceFileWriter.java

public static void main(String[] args) throws IOException {
    // Check parameters
    if (args.length < 3) {
        System.out.print("Please specify three parameters!");
        System.exit(-1);
    }//from  w  w  w .  j  a  v a  2  s . c om

    File filesDir = new File(args[0]);
    String targetDir = args[1];
    final int NUM_SPLITS = Integer.parseInt(args[2]);

    // Remove old target directory first
    FileUtils.deleteQuietly(new File(targetDir));

    File[] dataFiles = filesDir.listFiles();

    int total = dataFiles.length;
    int range = (int) Math.round(total / NUM_SPLITS + 0.5);
    System.out.printf("[INFO] The number of total files is %d \n.", total);

    for (int i = 1; i <= NUM_SPLITS; i++) {
        int start = (i - 1) * range;
        int end = Math.min(start + range, total);
        File[] subFiles = Arrays.copyOfRange(dataFiles, start, end);
        createSeqFile(subFiles, FilenameUtils.normalize(targetDir + "/" + i + ".seq"));
    }

    System.out.println("[INFO] All files have been successfully processed!");
}

From source file:gov.nih.nci.caintegrator.heatmap.invokeCBS2HeatMap.java

public static void main(String[] args) {
    HeatMapArgs hma = new HeatMapArgs();
    ReadOptions(args, hma);/* w  ww  .  j  ava2  s . c  om*/

    if ((hma.getGenomeOutFile() == null) && (hma.getGeneOutFile() == null)) {
        System.out.println("must specify at least one (gene or genome) output file");
        System.exit(-1);
    }
    if (hma.getBigBinFile() == null) {
        System.out.println("must specify big bin file");
        System.exit(-1);
    }
    if (hma.getSmallBinFile() == null) {
        System.out.println("must specify small bin file");
        System.exit(-1);
    }
    if (hma.getSegmentFile() == null) {
        System.out.println("must specify segmented data file");
        System.exit(-1);
    }
    if (hma.getRefGenesFile() == null) {
        System.out.println("must specify RefSeq gene flat file");
        System.exit(-1);
    }
    CBSToHeatmap CBS2HM = new CBS2HeatMap();
    try {
        CBS2HM.runCBSToHeatmap(hma);
        System.out.println("Completed successfully, the output file(s) are here: " + hma.getGeneOutFile() + ", "
                + hma.getGenomeOutFile());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.gnizr.core.delicious.DeliciousImportApp.java

/**
 * @param args/*from w  ww. ja  va  2s .c o m*/
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.out.println("Missing required arguments.");
        System.exit(1);
    }
    Properties prpt = new Properties();
    prpt.load(new FileInputStream(args[0]));
    String dbdrv = prpt.getProperty("gnizr.db.driver");
    String dbUrl = prpt.getProperty("gnizr.db.url");
    String dbUser = prpt.getProperty("gnizr.db.username");
    String dbPass = prpt.getProperty("gnizr.db.password");
    String gnizrUser = prpt.getProperty("gnizr.import.user");
    String gnizrPassword = prpt.getProperty("gnizr.import.password");
    String gnizrEmail = prpt.getProperty("gnizr.import.email");
    String gnizrFullname = prpt.getProperty("gnizr.import.fullname");
    String deliUser = prpt.getProperty("gnizr.import.delicious.user");
    String deliPassword = prpt.getProperty("gnizr.import.delicious.password");

    BasicDataSource datasource = new BasicDataSource();
    datasource.setDriverClassName(dbdrv);
    datasource.setUrl(dbUrl);
    datasource.setUsername(dbUser);
    datasource.setPassword(dbPass);

    GnizrDao gnizrDao = GnizrDao.getInstance(datasource);

    UserManager userManager = new UserManager(gnizrDao);
    BookmarkManager bookmarkManager = new BookmarkManager(gnizrDao);
    FolderManager folderManager = new FolderManager(gnizrDao);

    User gUser = new User();
    gUser.setUsername(gnizrUser);
    gUser.setPassword(gnizrPassword);
    gUser.setFullname(gnizrFullname);
    gUser.setEmail(gnizrEmail);
    gUser.setAccountStatus(AccountStatus.ACTIVE);
    gUser.setCreatedOn(GnizrDaoUtil.getNow());

    DeliciousImport deliciousImport = new DeliciousImport(deliUser, deliPassword, gUser, userManager,
            bookmarkManager, folderManager, true);
    ImportStatus status = deliciousImport.doImport();
    System.out.println("Del.icio.us Import Status: ");
    System.out.println("- total number: " + status.getTotalNumber());
    System.out.println("- number added: " + status.getNumberAdded());
    System.out.println("- number updated: " + status.getNumberUpdated());
    System.out.println("- number failed: " + status.getNumberError());
}

From source file:SAXCheck.java

static public void main(String[] arg) {
    String filename = null;/*from   w  ww  .j  av a 2  s  . c  om*/
    boolean validate = false;

    if (arg.length == 1) {
        filename = arg[0];
    } else if (arg.length == 2) {
        if (!arg[0].equals("-v"))
            usage();
        validate = true;
        filename = arg[1];
    } else {
        usage();
    }

    // Create a new factory to create parsers that will
    // validate or not, according to the flag setting.
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(validate);

    // Create the XMLReader to be used to check for errors.
    XMLReader reader = null;
    try {
        SAXParser parser = spf.newSAXParser();
        reader = parser.getXMLReader();
    } catch (Exception e) {
        System.err.println(e);
        System.exit(1);
    }

    // Install an error handler in the reader.
    reader.setErrorHandler(new MyErrorHandler());
    // Use the XMLReader to parse the entire file.
    try {
        InputSource is = new InputSource(filename);
        reader.parse(is);
    } catch (SAXException e) {
        System.exit(1);
    } catch (IOException e) {
        System.err.println(e);
        System.exit(1);
    }
}

From source file:examples.unix.fwhois.java

public static void main(String[] args) {
    int index;//from w  ww.  j a  va2 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);
        System.out.println("[" + address.getHostName() + "]");
    } catch (UnknownHostException e) {
        System.err.println("Error unknown host: " + e.getMessage());
        System.exit(1);
    }

    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:com.sonatype.nexus.perftest.PerformanceTestRunner.java

public static void main(String[] args) throws Exception {
    final Nexus nexus = new Nexus();
    ObjectMapper mapper = new XmlMapper();
    mapper.setInjectableValues(new InjectableValues() {
        @Override/*from   w  w w .j  av a  2 s.  c om*/
        public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty,
                Object beanInstance) {
            if (Nexus.class.getName().equals(valueId)) {
                return nexus;
            }
            return null;
        }
    });
    File src = new File(args[0]).getCanonicalFile();
    System.out.format("Using test configuration %s\n", src);
    PerformanceTest test = mapper.readValue(src, PerformanceTest.class);
    test.run();
    System.out.println("Exit");
    System.exit(0);
}

From source file:Redirect.java

public static void main(String args[]) throws Exception {
    PrintStream origOut = System.out;
    PrintStream origErr = System.err;

    InputStream stdin = null;//from   www  . ja v  a 2s .  c  o  m
    stdin = new FileInputStream("Redirect.in");
    PrintStream stdout = null;
    stdout = new PrintStream(new FileOutputStream("Redirect.out"));
    PrintStream stderr = null;
    stderr = new PrintStream(new FileOutputStream("Redirect.err"));
    origOut.println("1");
    System.out.println("2");
    origOut.println("3");
    System.err.println("4");
    origErr.println("5");

    System.setIn(stdin);
    System.setOut(stdout);
    System.setErr(stderr);

    origOut.println("\nR");
    System.out.println("T");
    origOut.println("Tq");
    System.err.println("Tqw");
    origErr.println("Test");

    origOut.println("\nRedirect:  Round #3");
    int inChar = 0;
    while (-1 != inChar) {
        try {
            inChar = System.in.read();
        } catch (Exception e) {
            // Clean up the output and bail.
            origOut.print("\n");
            break;
        }
        origOut.write(inChar);
    }

    stdin.close();
    stdout.close();
    stderr.close();

    System.exit(0);
}