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:DataLoader.java
public static void main(String[] args) throws IOException, ValidationException, LicenseException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException { System.out.println(/*from w w w . j av a2 s . c o m*/ "System is initialising. Please wait for a few seconds then type your queries below once you see the prompt (->)"); C24.init().withLicence("/biz/c24/api/license-ads.dat"); // Create our application context - assumes the Spring configuration is in the classpath in a file called spring-config.xml ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml"); // ======================================================================== // DEMO // A simple command-line interface to allow us to query the GemFire regions // ======================================================================== GemfireTemplate template = context.getBean(GemfireTemplate.class); BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in)); boolean writePrompt = true; try { while (true) { if (writePrompt) { System.out.print("-> "); System.out.flush(); writePrompt = false; } if (br.ready()) { try { String request = br.readLine(); System.out.println("Running: " + request); SelectResults<Object> results = template.find(request); System.out.println(); System.out.println("Result:"); for (Object result : results.asList()) { System.out.println(result.toString()); } } catch (Exception ex) { System.out.println("Error executing last command " + ex.getMessage()); //ex.printStackTrace(); } writePrompt = true; } else { // Wait for a second and try again try { Thread.sleep(1000); } catch (InterruptedException ioEx) { break; } } } } catch (IOException ioe) { // Write any exceptions to stderr System.err.print(ioe); } }
From source file:com.trifork.batchcopy.client.Main.java
public static void main(String[] args) throws Exception { DOMConfigurator.configure("log4j.xml"); AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( AppConfig.class); BatchCopyClient client = applicationContext.getBean(BatchCopyClient.class); String lastToken = null;/*from w w w .j a v a 2 s .c o m*/ do { lastToken = client.performRequest("doseringsforslag", "dosageunit", lastToken); System.out.println("Press enter to read another record"); System.in.read(); } while (true); }
From source file:examples.mail.java
public final static void main(String[] args) { String sender, recipient, subject, filename, server, cc; Vector ccList = new Vector(); BufferedReader stdin;//from w w w . j a v a 2s . c o m FileReader fileReader = null; Writer writer; SimpleSMTPHeader header; SMTPClient client; Enumeration en; if (args.length < 1) { System.err.println("Usage: mail smtpserver"); System.exit(1); } server = args[0]; stdin = new BufferedReader(new InputStreamReader(System.in)); try { System.out.print("From: "); System.out.flush(); sender = stdin.readLine(); System.out.print("To: "); System.out.flush(); recipient = stdin.readLine(); System.out.print("Subject: "); System.out.flush(); subject = stdin.readLine(); header = new SimpleSMTPHeader(sender, recipient, subject); while (true) { System.out.print("CC <enter one address per line, hit enter to end>: "); System.out.flush(); // Of course you don't want to do this because readLine() may be null cc = stdin.readLine().trim(); if (cc.length() == 0) break; header.addCC(cc); ccList.addElement(cc); } System.out.print("Filename: "); System.out.flush(); filename = stdin.readLine(); try { fileReader = new FileReader(filename); } catch (FileNotFoundException e) { System.err.println("File not found. " + e.getMessage()); } client = new SMTPClient(); client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); client.connect(server); if (!SMTPReply.isPositiveCompletion(client.getReplyCode())) { client.disconnect(); System.err.println("SMTP server refused connection."); System.exit(1); } client.login(); client.setSender(sender); client.addRecipient(recipient); en = ccList.elements(); while (en.hasMoreElements()) client.addRecipient((String) en.nextElement()); writer = client.sendMessageData(); if (writer != null) { writer.write(header.toString()); Util.copyReader(fileReader, writer); writer.close(); client.completePendingCommand(); } fileReader.close(); client.logout(); client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } }
From source file:cz.pecina.bin.bitwriter.BitWriter.java
/** * The main method./*w w w . j a va 2 s . c o m*/ * * @param args command-line arguments */ public static void main(final String args[]) { log.fine("Application started"); final int exitCode = process(args, System.in, System.out, System.err); log.fine("Application terminated with exit code: " + exitCode); System.exit(exitCode); }
From source file:top.zhacker.ms.reactor.spring.function.Server.java
public static void main(String[] args) throws Exception { Server server = new Server(); server.startReactorServer();/* w w w .j a v a 2 s . co m*/ // server.startTomcatServer(); System.out.println("Press ENTER to exit."); System.in.read(); }
From source file:de.zib.vold.userInterface.ABI.java
public static void main(String[] args) { ABI abi = new ABI(); while (true) { try {//from w w w. j a v a 2s . c o m InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); System.out.print("#: "); String s = br.readLine(); if (null == s) break; String[] a = s.split("\\s+"); if (a.length < 1) { System.out.println("ERROR: The following commands are valid:"); System.out.println("ERROR: insert <source> <scope> <type> <keyname> {<value> }*"); System.out.println("ERROR: lookup <scope> <type> <keyname>"); System.out.println("ERROR: exit"); continue; } else if (a[0].equals("lookup") || a[0].equals("l")) { if (a.length < 4) { System.out.println("ERROR: Syntax for lookup is:"); System.out.println("ERROR: lookup <scope> <type> <keyname>"); continue; } Map<Key, Set<String>> result; try { result = abi.frontend.lookup(new Key(a[1], a[2], a[3])); } catch (VoldException e) { System.out.println( "An internal error occured: " + e.getClass().getName() + ": " + e.getMessage()); continue; } for (Map.Entry<Key, Set<String>> entry : result.entrySet()) { Key k = entry.getKey(); System.out.println("+Found ('" + k.get_scope() + "', '" + k.get_type() + "', '" + k.get_keyname() + "')"); for (String v : entry.getValue()) { System.out.println("-" + v); } } } else if (a[0].equals("insert") || a[0].equals("i")) { if (a.length < 5) { System.out.println("ERROR: Syntax for insert is:"); System.out.println("ERROR: insert <source> <scope> <type> <keyname> {<value> }*"); continue; } Key k = new Key(a[2], a[3], a[4]); Set<String> values = new HashSet<String>(); for (int i = 5; i < a.length; ++i) { values.add(a[i]); } try { abi.frontend.insert(a[1], k, values, DateTime.now().getMillis()); } catch (VoldException e) { System.out.println( "An internal error occured: " + e.getClass().getName() + ": " + e.getMessage()); continue; } } else if (a[0].equals("exit") || a[0].equals("x")) { break; } else { System.out.println("ERROR: Unknown command!"); System.out.println("ERROR: The following commands are valid:"); System.out.println("ERROR: insert <source> <scope> <type> <keyname> {<value> }*"); System.out.println("ERROR: lookup <scope> <type> <keyname>"); System.out.println("ERROR: exit"); } } catch (IOException e) { e.printStackTrace(); } } System.exit(0); }
From source file:GenericClient.java
public static void main(String[] args) throws IOException { try {//from w w w .ja v a 2s. com // Check the number of arguments if (args.length != 2) throw new IllegalArgumentException("Wrong number of args"); // Parse the host and port specifications String host = args[0]; int port = Integer.parseInt(args[1]); // Connect to the specified host and port Socket s = new Socket(host, port); // Set up streams for reading from and writing to the server. // The from_server stream is final for use in the inner class below final Reader from_server = new InputStreamReader(s.getInputStream()); PrintWriter to_server = new PrintWriter(s.getOutputStream()); // Set up streams for reading from and writing to the console // The to_user stream is final for use in the anonymous class below BufferedReader from_user = new BufferedReader(new InputStreamReader(System.in)); // Pass true for auto-flush on println() final PrintWriter to_user = new PrintWriter(System.out, true); // Tell the user that we've connected to_user.println("Connected to " + s.getInetAddress() + ":" + s.getPort()); // Create a thread that gets output from the server and displays // it to the user. We use a separate thread for this so that we // can receive asynchronous output Thread t = new Thread() { public void run() { char[] buffer = new char[1024]; int chars_read; try { // Read characters from the server until the // stream closes, and write them to the console while ((chars_read = from_server.read(buffer)) != -1) { to_user.write(buffer, 0, chars_read); to_user.flush(); } } catch (IOException e) { to_user.println(e); } // When the server closes the connection, the loop above // will end. Tell the user what happened, and call // System.exit(), causing the main thread to exit along // with this one. to_user.println("Connection closed by server."); System.exit(0); } }; // Now start the server-to-user thread t.start(); // In parallel, read the user's input and pass it on to the server. String line; while ((line = from_user.readLine()) != null) { to_server.print(line + "\r\n"); to_server.flush(); } // If the user types a Ctrl-D (Unix) or Ctrl-Z (Windows) to end // their input, we'll get an EOF, and the loop above will exit. // When this happens, we stop the server-to-user thread and close // the socket. s.close(); to_user.println("Connection closed by client."); System.exit(0); } // If anything goes wrong, print an error message catch (Exception e) { System.err.println(e); System.err.println("Usage: java GenericClient <hostname> <port>"); } }
From source file:hello.CrawlerApp.java
public static void main(String[] args) throws Exception { ApplicationContext ctx = SpringApplication.run(CrawlerApp.class, args); System.in.read(); Runtime.getRuntime().exit(SpringApplication.exit(ctx)); }
From source file:com.sap.core.odata.fit.mapping.MappingTest.java
public static void main(final String[] args) { final TestServer server = new TestServer(); try {// w ww. j a va 2 s.c o m server.startServer(MapFactory.class); System.out.println("Press any key to exit"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } catch (final IOException e) { e.printStackTrace(System.err); } finally { server.stopServer(); } }
From source file:de.dakror.scpuller.SCPuller.java
public static void main(String[] args) { new File(System.getProperty("user.home") + "/.dakror/SCPuller").mkdirs(); new File(System.getProperty("user.home") + "/.dakror/SCPuller/download").mkdir(); Scanner scanner = new Scanner(System.in); loadDownloadedSongs();//from w w w . j a v a2 s.co m try { while (true) { String line = scanner.nextLine().trim(); download(line); saveDownloadedSongs(); } } finally { scanner.close(); } }