List of usage examples for java.lang System in
InputStream in
To view the source code for java.lang System in.
Click Source Link
From source file:com.alibaba.dubbo.examples.generic.GenericConsumer.java
public static void main(String[] args) throws Exception { String config = GenericConsumer.class.getPackage().getName().replace('.', '/') + "/generic-consumer.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config); context.start();//from w w w. ja v a 2 s . co m IUserService userservice = (IUserService) context.getBean("userservice"); User user = userservice.get(new Params("a=b")); System.out.println(user); System.in.read(); }
From source file:edu.harvard.med.iccbl.dev.HibernateConsole.java
public static void main(String[] args) { BufferedReader br = null;/*from w w w.j av a 2 s . co m*/ try { CommandLineApplication app = new CommandLineApplication(args); app.processOptions(true, false); br = new BufferedReader(new InputStreamReader(System.in)); EntityManagerFactory emf = (EntityManagerFactory) app.getSpringBean("entityManagerFactory"); EntityManager em = emf.createEntityManager(); do { System.out.println("Enter HQL query (blank to quit): "); String input = br.readLine(); if (input.length() == 0) { System.out.println("Goodbye!"); System.exit(0); } try { List list = ((Session) em.getDelegate()).createQuery(input).list(); // note: this uses the Hibernate Session object, to allow HQL (and JPQL) // List list = em.createQuery(input).getResultList(); // note: this JPA method supports JPQL System.out.println("Result:"); for (Iterator iter = list.iterator(); iter.hasNext();) { Object item = iter.next(); // format output from multi-item selects ("select a, b, c, ... from ...") if (item instanceof Object[]) { List<Object> fields = Arrays.asList((Object[]) item); System.out.println(StringUtils.makeListString(fields, ", ")); } // format output from single-item selected ("select a from ..." or "from ...") else { System.out.println("[" + item.getClass().getName() + "]: " + item); } } System.out.println("(" + list.size() + " rows)\n"); } catch (Exception e) { System.out.println("Hibernate Error: " + e.getMessage()); log.error("Hibernate error", e); } System.out.println(); } while (true); } catch (Exception e) { System.err.println("Fatal Error: " + e.getMessage()); e.printStackTrace(); } finally { IOUtils.closeQuietly(br); } }
From source file:test.node.TestNodeWorker.java
public static void main(String[] args) { try {// ww w.ja v a 2 s .co m log.info("GridNode Starting..."); StopWatch sw = new StopWatch(); sw.start(); // Start Grid Node GridNode node = Grid.startGridNode(); sw.stop(); log.info("GridNode Started Up. [" + sw.getLastTaskTimeMillis() + " ms]"); log.info("GridNode ID : " + node.getId()); log.debug("Press any key to unregister GridNode and terminate"); System.in.read(); node.getNodeRegistrationService().unregister(); log.info("Unregistered, Terminating..."); System.exit(0); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.bitcoinrt.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w w w . ja va 2 s . co m */ public static void main(final String... args) { final Scanner scanner = new Scanner(System.in); System.out.println("\n=========================================================" + "\n " + "\n Welcome to the Spring Integration Bitcoin-rt Sample! " + "\n " + "\n========================================================="); System.out.println("Which WebSocket Client would you like to use? <enter>: "); System.out.println("\t1. Use Sonatype's Async HTTP Client implementation"); System.out.println("\t2. Use Jetty's WebSocket client implementation"); System.out.println("\t3. Use a Dummy client"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); while (true) { final String input = scanner.nextLine(); if ("1".equals(input.trim())) { context.getEnvironment().setActiveProfiles("default"); break; } else if ("2".equals(input.trim())) { context.getEnvironment().setActiveProfiles("jetty"); break; } else if ("3".equals(input.trim())) { context.getEnvironment().setActiveProfiles("dummy"); break; } else if ("q".equals(input.trim())) { System.out.println("Exiting application...bye."); System.exit(0); } else { System.out.println("Invalid choice\n\n"); System.out.print("Enter you choice: "); } } context.load("classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); context.refresh(); final ConnectionBroker connectionBroker = context.getBean(ConnectionBroker.class); if (LOGGER.isInfoEnabled()) { LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n For statistical information press 'i + Enter'. " + "\n " + "\n In your browser open: " + "\n file:///.../src/main/webapp/index.html " + "\n========================================================="); } while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } else if ("i".equals(input.trim())) { LOGGER.info("\n=========================================================" + "\n " + "\n Number of connected clients: " + connectionBroker.connectedClients() + "\n " + "\n========================================================="); } } if (LOGGER.isInfoEnabled()) { LOGGER.info("Exiting application...bye."); } context.close(); System.exit(0); }
From source file:com.hsbc.srbp.commonMsg.test.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//w w w. j a va 2s . c o m */ public static void main(final String... args) { final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "jdbcInboundApplicationContext.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); final CommonMessageService commonMessageService = context.getBean(CommonMessageService.class); System.out.println("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.println("Please enter a choice and press <enter>: "); System.out.println("\t1. Create a new message detail"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); while (true) { final String input = scanner.nextLine(); if ("1".equals(input.trim())) { createMessageDetails(scanner, commonMessageService, context); } else if ("q".equals(input.trim())) { break; } else { System.out.println("Invalid choice\n\n"); } System.out.println("Please enter a choice and press <enter>: "); System.out.println("\t1. Create a new message detail"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); } System.out.println("Exiting application...."); System.exit(0); }
From source file:com.fileanalyzer.main.Main.java
public static void main(String[] args) throws IOException { FileAnalyzer fl = null;//from w w w . ja v a 2 s .c om try { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml"); Configuration conf = (Configuration) ctx.getBean("configuration"); fl = (FileAnalyzer) ctx.getBean("fileAnalyzer"); if (args.length == 3 && args[1].equalsIgnoreCase("s")) { log.info("Added file id: " + fl.analizeString(args[0], args[2])); } else if (args.length == 2 && args[1].equalsIgnoreCase("a")) { fl.analizeFile(args[0], true); } else if (args.length == 1) fl.analizeFile(args[0], false); else { log.info(conf.getWrongParams()); Thread.sleep(3000); System.exit(1); } log.info("Press any key to exit..."); System.in.read(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (fl != null) { fl.shutDown(); } System.exit(0); } }
From source file:StringTaggerDemo.java
public static void main(String args[]) { try {/*w ww . j a va2 s . co m*/ System.setProperty("sen.home", "../Sen1221/senhome-ipadic"); System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "FATAL"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please input Japanese sentence:"); StringTagger tagger = StringTagger.getInstance(); // You can also get StringTagger instance by following code: // // String confPath = System.getProperty("sen.home") // + System.getProperty("file.separator") + "conf/sen.xml"; // tagger = StringTagger.getInstance(confPath); String s; while ((s = br.readLine()) != null) { System.out.println(s); Token[] token = tagger.analyze(s); if (token != null) { for (int i = 0; i < token.length; i++) { System.out.println(token[i].toString() + "\t(" + token[i].getBasicString() + ")" + "\t" + token[i].getPos() + "(" + token[i].start() + "," + token[i].end() + "," + token[i].length() + ")\t" + token[i].getReading() + "\t" + token[i].getPronunciation()); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:io.s4.util.AvroSchemaSupplementer.java
public static void main(String args[]) { if (args.length < 1) { System.err.println("No schema filename specified"); System.exit(1);//from ww w .ja v a 2 s . co m } String filename = args[0]; FileReader fr = null; BufferedReader br = null; InputStreamReader isr = null; try { if (filename == "-") { isr = new InputStreamReader(System.in); br = new BufferedReader(isr); } else { fr = new FileReader(filename); br = new BufferedReader(fr); } String inputLine = ""; StringBuffer jsonBuffer = new StringBuffer(); while ((inputLine = br.readLine()) != null) { jsonBuffer.append(inputLine); } JSONObject jsonRecord = new JSONObject(jsonBuffer.toString()); JSONObject keyPathElementSchema = new JSONObject(); keyPathElementSchema.put("name", "KeyPathElement"); keyPathElementSchema.put("type", "record"); JSONArray fieldsArray = new JSONArray(); JSONObject fieldRecord = new JSONObject(); fieldRecord.put("name", "index"); JSONArray typeArray = new JSONArray("[\"int\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "keyName"); typeArray = new JSONArray("[\"string\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); keyPathElementSchema.put("fields", fieldsArray); JSONObject keyInfoSchema = new JSONObject(); keyInfoSchema.put("name", "KeyInfo"); keyInfoSchema.put("type", "record"); fieldsArray = new JSONArray(); fieldRecord = new JSONObject(); fieldRecord.put("name", "keyPath"); typeArray = new JSONArray("[\"string\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "fullKeyPath"); typeArray = new JSONArray("[\"string\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "keyPathElementList"); JSONObject typeRecord = new JSONObject(); typeRecord.put("type", "array"); typeRecord.put("items", keyPathElementSchema); fieldRecord.put("type", typeRecord); fieldsArray.put(fieldRecord); keyInfoSchema.put("fields", fieldsArray); JSONObject partitionInfoSchema = new JSONObject(); partitionInfoSchema.put("name", "PartitionInfo"); partitionInfoSchema.put("type", "record"); fieldsArray = new JSONArray(); fieldRecord = new JSONObject(); fieldRecord.put("name", "partitionId"); typeArray = new JSONArray("[\"int\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "compoundKey"); typeArray = new JSONArray("[\"string\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "compoundValue"); typeArray = new JSONArray("[\"string\", \"null\"]"); fieldRecord.put("type", typeArray); fieldsArray.put(fieldRecord); fieldRecord = new JSONObject(); fieldRecord.put("name", "keyInfoList"); typeRecord = new JSONObject(); typeRecord.put("type", "array"); typeRecord.put("items", keyInfoSchema); fieldRecord.put("type", typeRecord); fieldsArray.put(fieldRecord); partitionInfoSchema.put("fields", fieldsArray); fieldRecord = new JSONObject(); fieldRecord.put("name", "S4__PartitionInfo"); typeRecord = new JSONObject(); typeRecord.put("type", "array"); typeRecord.put("items", partitionInfoSchema); fieldRecord.put("type", typeRecord); fieldsArray = jsonRecord.getJSONArray("fields"); fieldsArray.put(fieldRecord); System.out.println(jsonRecord.toString(3)); } catch (Exception ioe) { throw new RuntimeException(ioe); } finally { if (br != null) try { br.close(); } catch (Exception e) { } if (isr != null) try { isr.close(); } catch (Exception e) { } if (fr != null) try { fr.close(); } catch (Exception e) { } } }
From source file:GenericReflectionTest.java
public static void main(String[] args) { // read class name from command line args or user input String name;/*from w w w .j a v a 2s .c o m*/ if (args.length > 0) name = args[0]; else { Scanner in = new Scanner(System.in); System.out.println("Enter class name (e.g. java.util.Collections): "); name = in.next(); } try { // print generic info for class and public methods Class<?> cl = Class.forName(name); printClass(cl); for (Method m : cl.getDeclaredMethods()) printMethod(m); } catch (ClassNotFoundException e) { e.printStackTrace(); } }
From source file:com.envirover.spl.SPLGroundControl.java
public static void main(String[] args) { try {// w w w . ja va2 s. co m SPLDaemon daemon = new SPLDaemon(); daemon.init(new SPLDaemonContext(args)); daemon.start(); System.out.println("Enter 'stop' to exit the program."); Scanner scanner = new Scanner(System.in); String str; while (!(str = scanner.next()).equalsIgnoreCase("stop")) { //Just echo the user input for now. System.out.println(str); } System.out.println("Exiting..."); scanner.close(); daemon.stop(); daemon.destroy(); System.out.println("Done."); System.exit(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } }