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:examples.rexec.java
public static final void main(String[] args) { String server, username, password, command; RExecClient client;//from w ww .ja va2 s . co 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:it.codestudio.callbyj.CallByJ.java
/** * The main method./*www.j av a 2 s .c om*/ * * @param args the arguments */ public static void main(String[] args) { options.addOption("aCom", "audio_com", true, "Specify serial COM port for audio streaming (3G APPLICATION ...)"); options.addOption("cCom", "command_com", true, "Specify serial COM port for modem AT command (PC UI INTERFACE ...)"); options.addOption("p", "play_message", false, "Play recorded message instead to respond with audio from mic"); options.addOption("h", "help", false, "Print help for this application"); try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String audioCOM = ""; String commandCOM = ""; Boolean playMessage = false; args = Utils.fitlerNullString(args); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("aCom")) { audioCOM = cmd.getOptionValue("aCom"); ; } if (cmd.hasOption("cCom")) { commandCOM = cmd.getOptionValue("cCom"); ; } if (cmd.hasOption("p")) { playMessage = true; } if (audioCOM != null && commandCOM != null && !audioCOM.isEmpty() && !commandCOM.isEmpty()) { comManager = ComManager.getInstance(commandCOM, audioCOM, playMessage); } else { HelpFormatter f = new HelpFormatter(); f.printHelp("\r Exaple: CallByJ -aCom COM11 -cCom COM10 \r OptionsTip", options); return; } options = new Options(); options.addOption("h", "help", false, "Print help for this application"); options.addOption("p", "pin", true, "Specify pin of device, if present"); options.addOption("c", "call", true, "Start call to specified number"); options.addOption("e", "end", false, "End all active call"); options.addOption("t", "terminate", false, "Terminate application"); options.addOption("r", "respond", false, "Respond to incoming call"); comManager.startModemCommandManager(); while (true) { try { String[] commands = { br.readLine() }; commands = Utils.fitlerNullString(commands); cmd = parser.parse(options, commands); if (cmd.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp("OptionsTip", options); } if (cmd.hasOption('p')) { String devicePin = cmd.getOptionValue("p"); comManager.insertPin(devicePin); } if (cmd.hasOption('c')) { String numberToCall = cmd.getOptionValue("c"); comManager.sendCommandToModem(ATCommands.CALL, numberToCall); } if (cmd.hasOption('r')) { comManager.respondToIncomingCall(); } if (cmd.hasOption('e')) { comManager.sendCommandToModem(ATCommands.END_CALL); } if (cmd.hasOption('t')) { comManager.sendCommandToModem(ATCommands.END_CALL); comManager.terminate(); System.out.println("CallByJ closed!"); break; //System.exit(0); } } catch (Exception e) { logger.error(e.getMessage(), e); } } } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (comManager != null) comManager.terminate(); } }
From source file:com.esri.geoportal.harvester.agp.AgpOutputApplication.java
public static void main(String[] args) throws Exception { if (args.length == 3) { MetaAnalyzer metaAnalyzer = new MultiMetaAnalyzerWrapper(new SimpleDcMetaAnalyzer(), new SimpleFgdcMetaAnalyzer(), new SimpleIso15115MetaAnalyzer(), new SimpleIso15115_2MetaAnalyzer(), new SimpleIso15119MetaAnalyzer()); AgpOutputConnector connector = new AgpOutputConnector(metaAnalyzer); EntityDefinition def = new EntityDefinition(); AgpOutputBrokerDefinitionAdaptor adaptor = new AgpOutputBrokerDefinitionAdaptor(def); adaptor.setHostUrl(new URL(args[0])); adaptor.setFolderId(StringUtils.trimToNull(args[1])); adaptor.setCredentials(new SimpleCredentials(args[2], args[3])); OutputBroker broker = connector.createBroker(def); DataReferenceSerializer ser = new DataReferenceSerializer(); DataReference ref = null;//from www . java 2 s. co m while ((ref = ser.deserialize(System.in)) != null) { broker.publish(ref); } } }
From source file:com.hillert.spring.validation.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/* ww w. ja v a 2s . co m*/ */ public static void main(final String... args) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome! " + "\n " + "\n For more information please visit: " + "\n http://blog.hillert.com " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in).useDelimiter("\n"); final BusinessService service = context.getBean(BusinessService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.println("Please enter a string and press <enter>: "); while (true) { System.out.print("$ "); String input = scanner.nextLine(); LOGGER.debug("Input string: '{}'", input); if ("q".equalsIgnoreCase(input)) { break; } else if ("null".equals(input)) { input = null; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (MethodConstraintViolationException e) { Set<MethodConstraintViolation<?>> constraintViolations = e.getConstraintViolations(); LOGGER.info("Method Validation failed with {} error(s).", constraintViolations.size()); for (MethodConstraintViolation<?> violation : e.getConstraintViolations()) { LOGGER.info("Method Validation: {}", violation.getConstraintDescriptor()); } } } LOGGER.info("Exiting application...bye."); System.exit(0); }
From source file:com.somnus.spring.validation.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from ww w . ja va 2 s . co m */ public static void main(final String... args) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome! " + "\n " + "\n For more information please visit: " + "\n http://blog.hillert.com " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/*-context.xml"); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in).useDelimiter("\n"); final BusinessService service = context.getBean(BusinessService.class); LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); System.out.println("Please enter a string and press <enter>: "); while (true) { System.out.print("$ "); String input = scanner.nextLine(); LOGGER.debug("Input string: '{}'", input); if ("q".equalsIgnoreCase(input)) { break; } else if ("null".equals(input)) { input = null; } try { System.out.println("Converted to upper-case: " + service.convertToUpperCase(input)); } catch (MethodConstraintViolationException e) { Set<MethodConstraintViolation<?>> constraintViolations = e.getConstraintViolations(); LOGGER.info("Method Validation failed with {} error(s).", constraintViolations.size()); for (MethodConstraintViolation<?> violation : e.getConstraintViolations()) { LOGGER.info("Method Validation: {}", violation.getPropertyPath().toString()); LOGGER.info("Method Validation: {}", violation.getConstraintDescriptor()); LOGGER.info("Method Validation: {}", violation.getMessage()); } } } LOGGER.info("Exiting application...bye."); System.exit(0); }
From source file:br.usp.poli.lta.cereda.spa2run.Main.java
public static void main(String[] args) { Utils.printBanner();//from w w w .jav a 2 s . c o m CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(Utils.getOptions(), args); List<Spec> specs = Utils.fromFilesToSpecs(line.getArgs()); List<Metric> metrics = Utils.fromFilesToMetrics(line); Utils.setMetrics(metrics); Utils.resetCalculations(); AdaptiveAutomaton automaton = Utils.getAutomatonFromSpecs(specs); System.out.println("SPA generated successfully:"); System.out.println("- " + specs.size() + " submachine(s) found."); if (!Utils.detectEpsilon(automaton)) { System.out.println("- No empty transitions."); } if (!metrics.isEmpty()) { System.out.println("- " + metrics.size() + " metric(s) found."); } System.out.println("\nStarting shell, please wait...\n" + "(press CTRL+C or type `:quit'\n" + "to exit the application)\n"); String query = ""; Scanner scanner = new Scanner(System.in); String prompt = "[%d] query> "; String result = "[%d] result> "; int counter = 1; do { try { String term = String.format(prompt, counter); System.out.print(term); query = scanner.nextLine().trim(); if (!query.equals(":quit")) { boolean accept = automaton.recognize(Utils.toSymbols(query)); String type = automaton.getRecognitionPaths().size() == 1 ? " (deterministic)" : " (nondeterministic)"; System.out.println(String.format(result, counter) + accept + type); if (!metrics.isEmpty()) { System.out.println(StringUtils.repeat(" ", String.format("[%d] ", counter).length()) + Utils.prettyPrintMetrics()); } System.out.println(); } } catch (Exception exception) { System.out.println(); Utils.printException(exception); System.out.println(); } counter++; Utils.resetCalculations(); } while (!query.equals(":quit")); System.out.println("That's all folks!"); } catch (ParseException nothandled) { Utils.printHelp(); } catch (Exception exception) { Utils.printException(exception); } }
From source file:org.sbq.batch.mains.ActivityEmulator.java
public static void main(String[] vars) throws IOException { System.out.println("ActivityEmulator - STARTED."); ActivityEmulator activityEmulator = new ActivityEmulator(); activityEmulator.begin();//www . j av a 2 s . c o m System.out.println("Enter your command: >"); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String command = null; while (!"stop".equals(command = in.readLine())) { if ("status".equals(command)) { List<String> onlineUsers = new LinkedList<String>(); for (Map.Entry<String, AtomicBoolean> entry : activityEmulator.getUserStatusByLogin().entrySet()) { if (entry.getValue().get()) { onlineUsers.add(entry.getKey()); } } System.out.println("Users online: " + Arrays.toString(onlineUsers.toArray())); System.out.println("Number of cycles left: " + activityEmulator.getBlockingQueue().size()); } System.out.println("Enter your command: >"); } activityEmulator.stop(); System.out.println("ActivityEmulator - STOPPED."); }
From source file:ReadHeaders.java
/** Main program showing how to use it */ public static void main(String[] av) { switch (av.length) { case 0://w w w . j a va 2 s . com ReadHeaders r = new ReadHeaders(new BufferedReader(new InputStreamReader(System.in))); printit(r); break; default: for (int i = 0; i < av.length; i++) try { ReadHeaders rr = new ReadHeaders(new BufferedReader(new FileReader(av[i]))); printit(rr); } catch (FileNotFoundException e) { System.err.println(e); } break; } }
From source file:com.asual.lesscss.LessEngineCli.java
public static void main(String[] args) throws LessException, URISyntaxException { Options cmdOptions = new Options(); cmdOptions.addOption(LessOptions.CHARSET_OPTION, true, "Input file charset encoding. Defaults to UTF-8."); cmdOptions.addOption(LessOptions.COMPRESS_OPTION, false, "Flag that enables compressed CSS output."); cmdOptions.addOption(LessOptions.CSS_OPTION, false, "Flag that enables compilation of .css files."); cmdOptions.addOption(LessOptions.LESS_OPTION, true, "Path to a custom less.js for Rhino version."); try {/*from ww w . j av a 2 s . c o m*/ CommandLineParser cmdParser = new GnuParser(); CommandLine cmdLine = cmdParser.parse(cmdOptions, args); LessOptions options = new LessOptions(); if (cmdLine.hasOption(LessOptions.CHARSET_OPTION)) { options.setCharset(cmdLine.getOptionValue(LessOptions.CHARSET_OPTION)); } if (cmdLine.hasOption(LessOptions.COMPRESS_OPTION)) { options.setCompress(true); } if (cmdLine.hasOption(LessOptions.CSS_OPTION)) { options.setCss(true); } if (cmdLine.hasOption(LessOptions.LESS_OPTION)) { options.setLess(new File(cmdLine.getOptionValue(LessOptions.LESS_OPTION)).toURI().toURL()); } LessEngine engine = new LessEngine(options); if (System.in.available() != 0) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringWriter sw = new StringWriter(); char[] buffer = new char[1024]; int n = 0; while (-1 != (n = in.read(buffer))) { sw.write(buffer, 0, n); } String src = sw.toString(); if (!src.isEmpty()) { System.out.println(engine.compile(src, null, options.isCompress())); System.exit(0); } } String[] files = cmdLine.getArgs(); if (files.length == 1) { System.out.println(engine.compile(new File(files[0]), options.isCompress())); System.exit(0); } if (files.length == 2) { engine.compile(new File(files[0]), new File(files[1]), options.isCompress()); System.exit(0); } } catch (IOException ioe) { System.err.println("Error opening input file."); } catch (ParseException pe) { System.err.println("Error parsing arguments."); } String[] paths = LessEngine.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath() .split(File.separator); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar " + paths[paths.length - 1] + " input [output] [options]", cmdOptions); System.exit(1); }
From source file:com.github.xbn.examples.testdev.ReplaceAllIndentTabsWithSpacesXmpl.java
public static final void main(String[] directoryRoot_paramIdxZero) { //Setup and protection String dirRoot = GetFromCommandLineAtIndex.text(directoryRoot_paramIdxZero, 0, "directoryRoot_paramIdxZero", null);/*from w ww . ja v a2 s . c o m*/ System.out.println("This example code will overwrite the files in \"" + dirRoot + "\". Enter the number 1234567890 to proceed."); if (!new Scanner(System.in).nextLine().equals("1234567890")) { System.out.println("Abort."); return; } Path dirPath = new PathMustBe().existing().writable().directory().noFollowLinks().getOrCrashIfBad(dirRoot, "directoryRoot_paramIdxZero[0]"); File fileRootDir = new File(dirRoot); //Go IOFileFilter allFileTypesKeepFilter = FileFilterUtils.and(FileFilterUtils.suffixFileFilter(".java"), FileFilterUtils.suffixFileFilter(".html")); Iterator<File> fileItr = FileUtils.iterateFiles(fileRootDir, allFileTypesKeepFilter, null); new ReplaceAllIndentTabsWithSpaces(3, System.out, TabToSpaceDebugLevel.FILE_SUMMARIES) .overwriteDirectory(fileItr); }