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:Grep1.java
/** Main will make a Grep object for the pattern, and run it * on all input files listed in argv./*w w w. java 2s . c o m*/ */ public static void main(String[] argv) throws Exception { if (argv.length < 1) { System.err.println("Usage: Grep1 pattern [filename]"); System.exit(1); } Grep1 pg = new Grep1(argv[0]); if (argv.length == 1) pg.process(new BufferedReader(new InputStreamReader(System.in)), "(standard input)", false); else for (int i = 1; i < argv.length; i++) { pg.process(new BufferedReader(new FileReader(argv[i])), argv[i], true); } }
From source file:io.milton.grizzly.GrizzlyLoadBalancer.java
public static void main(String[] args) throws IOException, InterruptedException { int port = 8080; if (args.length > 0) { port = Integer.parseInt(args[0]); }/*from w ww .j ava2s . c o m*/ Integer sslPort = null; if (args.length > 1) { sslPort = Integer.parseInt(args[1]); } GrizzlyLoadBalancer k = new GrizzlyLoadBalancer(); k.start(); System.out.println("Press any key to stop the server..."); System.in.read(); }
From source file:msgsend.java
public static void main(String[] argv) { String to, subject = null, from = null, cc = null, bcc = null, url = null; String mailhost = null;/*www.j a va 2 s . c o m*/ String mailer = "msgsend"; String file = null; String protocol = null, host = null, user = null, password = null; String record = null; // name of folder in which to record mail boolean debug = false; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int optind; /* * Process command line arguments. */ for (optind = 0; optind < argv.length; optind++) { if (argv[optind].equals("-T")) { protocol = argv[++optind]; } else if (argv[optind].equals("-H")) { host = argv[++optind]; } else if (argv[optind].equals("-U")) { user = argv[++optind]; } else if (argv[optind].equals("-P")) { password = argv[++optind]; } else if (argv[optind].equals("-M")) { mailhost = argv[++optind]; } else if (argv[optind].equals("-f")) { record = argv[++optind]; } else if (argv[optind].equals("-a")) { file = argv[++optind]; } else if (argv[optind].equals("-s")) { subject = argv[++optind]; } else if (argv[optind].equals("-o")) { // originator from = argv[++optind]; } else if (argv[optind].equals("-c")) { cc = argv[++optind]; } else if (argv[optind].equals("-b")) { bcc = argv[++optind]; } else if (argv[optind].equals("-L")) { url = argv[++optind]; } else if (argv[optind].equals("-d")) { debug = true; } else if (argv[optind].equals("--")) { optind++; break; } else if (argv[optind].startsWith("-")) { System.out.println("Usage: msgsend [[-L store-url] | [-T prot] [-H host] [-U user] [-P passwd]]"); System.out.println("\t[-s subject] [-o from-address] [-c cc-addresses] [-b bcc-addresses]"); System.out.println("\t[-f record-mailbox] [-M transport-host] [-a attach-file] [-d] [address]"); System.exit(1); } else { break; } } try { /* * Prompt for To and Subject, if not specified. */ if (optind < argv.length) { // XXX - concatenate all remaining arguments to = argv[optind]; System.out.println("To: " + to); } else { System.out.print("To: "); System.out.flush(); to = in.readLine(); } if (subject == null) { System.out.print("Subject: "); System.out.flush(); subject = in.readLine(); } else { System.out.println("Subject: " + subject); } /* * Initialize the JavaMail Session. */ Properties props = System.getProperties(); // XXX - could use Session.getTransport() and Transport.connect() // XXX - assume we're using SMTP if (mailhost != null) props.put("mail.smtp.host", mailhost); // Get a Session object Session session = Session.getInstance(props, null); if (debug) session.setDebug(true); /* * Construct the message and send it. */ Message msg = new MimeMessage(session); if (from != null) msg.setFrom(new InternetAddress(from)); else msg.setFrom(); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); if (cc != null) msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc, false)); if (bcc != null) msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc, false)); msg.setSubject(subject); String text = collect(in); if (file != null) { // Attach the specified file. // We need a multipart message to hold the attachment. MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(text); MimeBodyPart mbp2 = new MimeBodyPart(); mbp2.attachFile(file); MimeMultipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); msg.setContent(mp); } else { // If the desired charset is known, you can use // setText(text, charset) msg.setText(text); } msg.setHeader("X-Mailer", mailer); msg.setSentDate(new Date()); // send the thing off Transport.send(msg); System.out.println("\nMail was sent successfully."); /* * Save a copy of the message, if requested. */ if (record != null) { // Get a Store object Store store = null; if (url != null) { URLName urln = new URLName(url); store = session.getStore(urln); store.connect(); } else { if (protocol != null) store = session.getStore(protocol); else store = session.getStore(); // Connect if (host != null || user != null || password != null) store.connect(host, user, password); else store.connect(); } // Get record Folder. Create if it does not exist. Folder folder = store.getFolder(record); if (folder == null) { System.err.println("Can't get record folder."); System.exit(1); } if (!folder.exists()) folder.create(Folder.HOLDS_MESSAGES); Message[] msgs = new Message[1]; msgs[0] = msg; folder.appendMessages(msgs); System.out.println("Mail was recorded successfully."); } } catch (Exception e) { e.printStackTrace(); } }
From source file:examples.rshell.java
public static final void main(String[] args) { String server, localuser, remoteuser, command; RCommandClient client;//from ww w . ja v a2 s . c o m if (args.length != 4) { System.err.println("Usage: rshell <hostname> <localuser> <remoteuser> <command>"); System.exit(1); return; // so compiler can do proper flow control analysis } client = new RCommandClient(); server = args[0]; localuser = args[1]; remoteuser = args[2]; command = args[3]; try { client.connect(server); } catch (IOException e) { System.err.println("Could not connect to server."); e.printStackTrace(); System.exit(1); } try { client.rcommand(localuser, remoteuser, command); } catch (IOException e) { try { client.disconnect(); } catch (IOException f) { } e.printStackTrace(); System.err.println("Could not execute command."); System.exit(1); } IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), System.in, System.out); try { client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.exit(0); }
From source file:examples.unix.rexec.java
public static void main(String[] args) { String server, username, password, command; RExecClient client;/*from w ww.j av a2 s. c o m*/ if (args.length != 4) { System.err.println("Usage: rexec <hostname> <username> <password> <command>"); System.exit(1); return; // so compiler can do proper flow control analysis } client = new RExecClient(); server = args[0]; username = args[1]; password = args[2]; command = args[3]; try { client.connect(server); } catch (IOException e) { System.err.println("Could not connect to server."); e.printStackTrace(); System.exit(1); } try { client.rexec(username, password, command); } catch (IOException e) { try { client.disconnect(); } catch (IOException f) { } e.printStackTrace(); System.err.println("Could not execute command."); System.exit(1); } IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), System.in, System.out); try { client.disconnect(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.exit(0); }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.TrafficRouterStart.java
public static void main(String[] args) throws Exception { System.setProperty("deploy.dir", "src/test"); System.setProperty("dns.zones.dir", "src/test/var/auto-zones"); LogManager.getLogger("org.eclipse.jetty").setLevel(Level.WARN); LogManager.getLogger("org.springframework").setLevel(Level.WARN); ConsoleAppender consoleAppender = new ConsoleAppender(new PatternLayout("%d{ISO8601} [%-5p] %c{4}: %m%n")); LogManager.getRootLogger().addAppender(consoleAppender); LogManager.getRootLogger().setLevel(Level.INFO); File webAppDirectory = new File("src/main/webapp"); if (!webAppDirectory.exists()) { LogManager.getRootLogger().fatal(webAppDirectory.getAbsolutePath() + " does not exist, are you running TrafficRouterStart from the correct directory?"); System.exit(1);//from ww w . j a v a 2 s. c o m } int timeout = (int) Duration.ONE_HOUR.getMilliseconds(); Server server = new Server(); SocketConnector connector = new SocketConnector(); // Set some timeout options to make debugging easier. connector.setMaxIdleTime(timeout); connector.setSoLingerTime(-1); connector.setPort(8081); server.addConnector(connector); WebAppContext bb = new WebAppContext(); bb.setServer(server); bb.setContextPath("/"); bb.setWar("src/main/webapp"); server.setHandler(bb); try { System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP"); server.start(); System.in.read(); System.out.println(">>> STOPPING EMBEDDED JETTY SERVER"); server.stop(); server.join(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
From source file:SimpleCalcScanner.java
public static void main(String[] av) throws IOException { if (av.length == 0) new SimpleCalcScanner(new InputStreamReader(System.in)).doCalc(); else//from w w w . j av a 2 s . c o m for (int i = 0; i < av.length; i++) new SimpleCalcScanner(av[i]).doCalc(); }
From source file:cz.muni.fi.xklinec.zipstream.App.java
/** * Entry point. /* w w w. j a v a 2s .co m*/ * * @param args * @throws FileNotFoundException * @throws IOException * @throws NoSuchFieldException * @throws ClassNotFoundException * @throws NoSuchMethodException */ public static void main(String[] args) throws FileNotFoundException, IOException, NoSuchFieldException, ClassNotFoundException, NoSuchMethodException, InterruptedException { OutputStream fos = null; InputStream fis = null; if ((args.length != 0 && args.length != 2)) { System.err.println(String.format("Usage: app.jar source.apk dest.apk")); return; } else if (args.length == 2) { System.err.println( String.format("Will use file [%s] as input file and [%s] as output file", args[0], args[1])); fis = new FileInputStream(args[0]); fos = new FileOutputStream(args[1]); } else if (args.length == 0) { System.err.println(String.format("Will use file [STDIN] as input file and [STDOUT] as output file")); fis = System.in; fos = System.out; } final Deflater def = new Deflater(9, true); ZipArchiveInputStream zip = new ZipArchiveInputStream(fis); // List of postponed entries for further "processing". List<PostponedEntry> peList = new ArrayList<PostponedEntry>(6); // Output stream ZipArchiveOutputStream zop = new ZipArchiveOutputStream(fos); zop.setLevel(9); // Read the archive ZipArchiveEntry ze = zip.getNextZipEntry(); while (ze != null) { ZipExtraField[] extra = ze.getExtraFields(true); byte[] lextra = ze.getLocalFileDataExtra(); UnparseableExtraFieldData uextra = ze.getUnparseableExtraFieldData(); byte[] uextrab = uextra != null ? uextra.getLocalFileDataData() : null; // ZipArchiveOutputStream.DEFLATED // // Data for entry byte[] byteData = Utils.readAll(zip); byte[] deflData = new byte[0]; int infl = byteData.length; int defl = 0; // If method is deflated, get the raw data (compress again). if (ze.getMethod() == ZipArchiveOutputStream.DEFLATED) { def.reset(); def.setInput(byteData); def.finish(); byte[] deflDataTmp = new byte[byteData.length * 2]; defl = def.deflate(deflDataTmp); deflData = new byte[defl]; System.arraycopy(deflDataTmp, 0, deflData, 0, defl); } System.err.println(String.format( "ZipEntry: meth=%d " + "size=%010d isDir=%5s " + "compressed=%07d extra=%d lextra=%d uextra=%d " + "comment=[%s] " + "dataDesc=%s " + "UTF8=%s " + "infl=%07d defl=%07d " + "name [%s]", ze.getMethod(), ze.getSize(), ze.isDirectory(), ze.getCompressedSize(), extra != null ? extra.length : -1, lextra != null ? lextra.length : -1, uextrab != null ? uextrab.length : -1, ze.getComment(), ze.getGeneralPurposeBit().usesDataDescriptor(), ze.getGeneralPurposeBit().usesUTF8ForNames(), infl, defl, ze.getName())); final String curName = ze.getName(); // META-INF files should be always on the end of the archive, // thus add postponed files right before them if (curName.startsWith("META-INF") && peList.size() > 0) { System.err.println( "Now is the time to put things back, but at first, I'll perform some \"facelifting\"..."); // Simulate som evil being done Thread.sleep(5000); System.err.println("OK its done, let's do this."); for (PostponedEntry pe : peList) { System.err.println( "Adding postponed entry at the end of the archive! deflSize=" + pe.deflData.length + "; inflSize=" + pe.byteData.length + "; meth: " + pe.ze.getMethod()); pe.dump(zop, false); } peList.clear(); } // Capturing interesting files for us and store for later. // If the file is not interesting, send directly to the stream. if ("classes.dex".equalsIgnoreCase(curName) || "AndroidManifest.xml".equalsIgnoreCase(curName)) { System.err.println("### Interesting file, postpone sending!!!"); PostponedEntry pe = new PostponedEntry(ze, byteData, deflData); peList.add(pe); } else { // Write ZIP entry to the archive zop.putArchiveEntry(ze); // Add file data to the stream zop.write(byteData, 0, infl); zop.closeArchiveEntry(); } ze = zip.getNextZipEntry(); } // Cleaning up stuff zip.close(); fis.close(); zop.finish(); zop.close(); fos.close(); System.err.println("THE END!"); }
From source file:ohtu.Poytasaha.java
/** * @param args the command line arguments *///w w w . j av a2 s.c o m public static void main(String[] args) { // // TODO code application logic here // ApplicationContext ctx = new FileSystemXmlApplicationContext("src/main/resources/spring-context.xml"); // Poytasaha poytasaha = (Poytasaha) ctx.getBean("poytasaha"); // poytasaha.run(); // Scanner lukija = new Scanner(System.in); ConsoleIO io = new ConsoleIO(new Scanner(System.in)); FileReferenceDao dao = new FileReferenceDao(); UI ui = new UI(io, dao); ui.run(); }
From source file:com.iveely.computing.Program.java
/** * @param args the command line arguments * @throws java.io.IOException/* w w w . j a v a 2 s . c om*/ */ public static void main(String[] args) throws IOException { if (args != null && args.length > 0) { logger.info("start computing with arguments:" + String.join(",", args)); String type = args[0].toLowerCase(Locale.CHINESE); switch (type) { case "master": launchMaster(); return; case "slave": if (args.length == 4) { ConfigWrapper.get().getSlave().setPort(Integer.parseInt(args[1])); ConfigWrapper.get().getSlave().setSlot(Integer.parseInt(args[2])); ConfigWrapper.get().getSlave().setSlotCount(Integer.parseInt(args[3])); } launchSlave(); return; case "supervisor": launchSupervisor(); return; case "console": launchConsole(); return; } } logger.error("arguments error,example [master | supervisor | slave | console]"); System.out.println("press any keys to exit..."); new BufferedReader(new InputStreamReader(System.in)).readLine(); }