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:de.inpiraten.jdemocrator.TAN.generator.TANGenerator.java
public static void main(String[] args) { //Intro message GPL.printLicenseNotice();/*from w w w. j av a 2 s . c o m*/ System.out.println("\njDemocrator Authority TAN Generator"); System.out.println("===================================\n"); System.out.println("This programm will generate voting TANs for a semi-online secrete voting."); try { //Initialize TAN Generator TANGenerator G = new TANGenerator(new BufferedReader(new InputStreamReader(System.in))); //Randomly generate master TANs G.generateMasterTANs(); //Generate TANs from master TANs TAN[][] tans = new TAN[G.event.numberOfElections][]; for (int i = 0; i < tans.length; i++) { try { tans[i] = G.event.TANType.generateFromMasterTAN(G.masterTAN[i], G.event, G.event.numberOfVoters); } catch (NoSuchAlgorithmException e) { System.out.println("The Key Derivation function described as " + G.event.keyDerivationFunction + " is not supported. Exiting."); System.exit(2); } catch (InvalidKeySpecException e) { System.out.println("Invalied Key Spec Exception while generating TANs. Exiting."); System.exit(3); } } //Mix up the TANs for (int i = 0; i < tans.length; i++) { shuffle(tans[i]); } //TODO Write the TANs and master TANs to (printable) files } catch (IOException e) { System.out.println("An I/O Error occured"); System.exit(1); } }
From source file:examples.rlogin.java
public static final void main(String[] args) { String server, localuser, remoteuser, terminal; RLoginClient client;//from w ww . j a v a2 s . co m if (args.length != 4) { System.err.println("Usage: rlogin <hostname> <localuser> <remoteuser> <terminal>"); System.exit(1); return; // so compiler can do proper flow control analysis } client = new RLoginClient(); server = args[0]; localuser = args[1]; remoteuser = args[2]; terminal = args[3]; try { client.connect(server); } catch (IOException e) { System.err.println("Could not connect to server."); e.printStackTrace(); System.exit(1); } try { client.rlogin(localuser, remoteuser, terminal); } catch (IOException e) { try { client.disconnect(); } catch (IOException f) { } e.printStackTrace(); System.err.println("rlogin authentication failed."); 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:Base64Decode.java
/** * A test method of questionable utility. *//* w w w .j a va2 s. co m*/ public static void main(String args[]) { try { FileOutputStream fos = new FileOutputStream("out.dat"); fos.write(decode(System.in)); fos.close(); } catch (IOException ie) { ie.printStackTrace(); } }
From source file:org.mzd.shap.spring.cli.ConfigSetup.java
public static void main(String[] args) { // check args if (args.length != 1) { exitOnError(1, null);//from w w w . j a v a 2 s .c o m } // check file existance File analyzerXML = new File(args[0]); if (!analyzerXML.exists()) { exitOnError(1, "'" + analyzerXML.getPath() + "' did not exist\n"); } // prompt user whether existing data should be purged boolean isPurged = false; String ormContext = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { System.out.println("\nDo you wish to purge the database before running setup?"); System.out.println("WARNING: all existing data in SHAP will be lost!"); System.out.println("Really purge? yes/[NO]"); String ans = br.readLine(); if (ans.toLowerCase().equals("yes")) { System.out.println("Purging enabled"); ormContext = "orm-purge-context.xml"; isPurged = true; } else { System.out.println("Purging disabled"); ormContext = "orm-context.xml"; } } catch (IOException ex) { throw new RuntimeException(ex); } // run tool try { // Using a generic application context since we're referencing // both classpath and filesystem resources. GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new ClassPathResource("datasource-context.xml"), new ClassPathResource(ormContext), new FileSystemResource(analyzerXML)); ctx.refresh(); /* * Create an base admin user. */ if (isPurged) { //only attempted if we've wiped the old database. RoleDao roleDao = (RoleDao) ctx.getBean("roleDao"); Role adminRole = roleDao.saveOrUpdate(new Role("admin", "ROLE_ADMIN")); Role userRole = roleDao.saveOrUpdate(new Role("user", "ROLE_USER")); UserDao userDao = (UserDao) ctx.getBean("userDao"); userDao.saveOrUpdate(new User("admin", "admin", "shap01", adminRole, userRole)); } /* * Create some predefined analyzers. Users should have modified * the configuration file to suit their environment. */ AnnotatorDao annotatorDao = (AnnotatorDao) ctx.getBean("annotatorDao"); DetectorDao detectorDao = (DetectorDao) ctx.getBean("detectorDao"); ConfigSetup config = (ConfigSetup) ctx.getBean("configuration"); for (Annotator an : config.getAnnotators()) { System.out.println("Adding annotator: " + an.getName()); annotatorDao.saveOrUpdate(an); } for (Detector dt : config.getDetectors()) { System.out.println("Adding detector: " + dt.getName()); detectorDao.saveOrUpdate(dt); } System.exit(0); } catch (Throwable t) { System.err.println(t.getMessage()); System.exit(1); } }
From source file:example.wildcard.Client.java
public static void main(String[] args) { String url = BROKER_URL; if (args.length > 0) { url = args[0].trim();/* w w w.ja v a2s . c o m*/ } ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "password", url); Connection connection = null; try { Topic senderTopic = new ActiveMQTopic(System.getProperty("topicName")); connection = connectionFactory.createConnection("admin", "password"); Session senderSession = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE); MessageProducer sender = senderSession.createProducer(senderTopic); Session receiverSession = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE); String policyType = System.getProperty("wildcard", ".*"); String receiverTopicName = senderTopic.getTopicName() + policyType; Topic receiverTopic = receiverSession.createTopic(receiverTopicName); MessageConsumer receiver = receiverSession.createConsumer(receiverTopic); receiver.setMessageListener(new MessageListener() { public void onMessage(Message message) { try { if (message instanceof TextMessage) { String text = ((TextMessage) message).getText(); System.out.println("We received a new message: " + text); } } catch (JMSException e) { System.out.println("Could not read the receiver's topic because of a JMSException"); } } }); connection.start(); System.out.println("Listening on '" + receiverTopicName + "'"); System.out.println("Enter a message to send: "); Scanner inputReader = new Scanner(System.in); while (true) { String line = inputReader.nextLine(); if (line == null) { System.out.println("Done!"); break; } else if (line.length() > 0) { try { TextMessage message = senderSession.createTextMessage(); message.setText(line); System.out.println("Sending a message: " + message.getText()); sender.send(message); } catch (JMSException e) { System.out.println("Exception during publishing a message: "); } } } receiver.close(); receiverSession.close(); sender.close(); senderSession.close(); } catch (Exception e) { System.out.println("Caught exception!"); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { System.out.println("When trying to close connection: "); } } } }
From source file:languages.TabFile.java
public static void main(String[] args) { if (args[0].equals("optimize")) { Scanner sc = new Scanner(System.in); String targetPath;//from ww w . j a v a2 s.c o m String originPath; System.out.println("Please enter the path of the original *.tab-files:"); originPath = sc.nextLine(); System.out.println( "Please enter the path where you wish to save the optimized *.tab-files (Directories will be created, existing files with same filenames will be overwritten):"); targetPath = sc.nextLine(); sc.close(); File folder = new File(originPath); File[] listOfFiles = folder.listFiles(); assert listOfFiles != null; for (File file : listOfFiles) { if (!file.getName().equals("LICENSE")) { TabFile origin; try { String originFileName = file.getAbsolutePath(); System.out.print("Reading file '" + originFileName + "'..."); origin = new TabFile(originFileName); System.out.println("Done!"); System.out.print("Optimizing file..."); TabFile res = TabFile.optimizeDictionaries(origin, 2, true); System.out.println("Done!"); String targetFileName = targetPath + File.separator + file.getName(); System.out.println("Saving new file as '" + targetFileName + "'..."); res.save(targetFileName); System.out.println("Done!"); } catch (IOException e) { FOKLogger.log(TabFile.class.getName(), Level.SEVERE, "An error occurred", e); } } } } else if (args[0].equals("merge")) { System.err.println( "Merging dictionaries is not supported anymore. Please checkout commit 1a6fa16 to merge dictionaries."); } }
From source file:com.genentech.struchk.OEMDLPercieveChecker.java
public static void main(String[] args) throws ParseException, JDOMException, IOException { // create command line Options object Options options = new Options(); Option opt = new Option("i", true, "input file [.ism,.sdf,...]"); opt.setRequired(true);/* www . j a v a2 s.c o m*/ options.addOption(opt); opt = new Option("o", true, "output file"); opt.setRequired(false); options.addOption(opt); opt = new Option("d", false, "debug: wait for user to press key at startup."); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } if (args.length != 0) { exitWithHelp(options); } String inFile = cmd.getOptionValue("i"); String outFile = cmd.getOptionValue("o"); OEMDLPercieveChecker checker = null; try { checker = new OEMDLPercieveChecker(); oemolostream out = new oemolostream(outFile); oemolistream in = new oemolistream(inFile); OEGraphMol mol = new OEGraphMol(); while (oechem.OEReadMolecule(in, mol)) { if (!checker.checkMol(mol)) oechem.OEWriteMolecule(out, mol); } checker.delete(); in.close(); in.delete(); out.close(); out.delete(); } catch (Exception e) { throw new Error(e); } System.err.println("Done:"); }
From source file:edu.usf.cutr.obascs.OBASCSMain.java
public static void main(String[] args) { String logLevel = null;/*ww w . j av a 2 s .c o m*/ String outputFilePath = null; String inputFilePath = null; String spreadSheetId = null; Logger logger = Logger.getInstance(); Options options = CommandLineUtil.createCommandLineOptions(); CommandLineParser parser = new BasicParser(); CommandLine cmd; try { cmd = parser.parse(options, args); logLevel = CommandLineUtil.getLogLevel(cmd); logger.setup(logLevel); outputFilePath = CommandLineUtil.getOutputPath(cmd); spreadSheetId = CommandLineUtil.getSpreadSheetId(cmd); inputFilePath = CommandLineUtil.getInputPath(cmd); } catch (ParseException e1) { logger.logError(e1); } catch (FileNotFoundException e) { logger.logError(e); } Map<String, String> agencyMap = null; try { agencyMap = FileUtil.readAgencyInformantions(inputFilePath); } catch (IOException e1) { logger.logError(e1); } logger.log("Consolidation started..."); logger.log("Trying as public url"); ListFeed listFeed = null; Boolean authRequired = false; try { listFeed = SpreadSheetReader.readPublicSpreadSheet(spreadSheetId); } catch (IOException e) { logger.logError(e); } catch (ServiceException e) { logger.log("Authentication Required"); authRequired = true; } if (listFeed == null && authRequired == true) { Scanner scanner = new Scanner(System.in); String userName, password; logger.log("UserName:"); userName = scanner.nextLine(); logger.log("Password:"); password = scanner.nextLine(); scanner.close(); try { listFeed = SpreadSheetReader.readPrivateSpreadSheet(userName, password, spreadSheetId); } catch (IOException e) { logger.logError(e); } catch (ServiceException e) { logger.logError(e); } } if (listFeed != null) { //Creating consolidated stops String consolidatedString = FileConsolidator.consolidateFile(listFeed, agencyMap); try { FileUtil.writeToFile(consolidatedString, outputFilePath); } catch (FileNotFoundException e) { logger.logError(e); } //Creating sample stop consolidation script config file try { String path = ClassLoader.getSystemClassLoader() .getResource(GeneralConstants.CONSOLIDATION_SCRIPT_CONFIG_FILE).getPath(); String configXml = FileUtil.readFile(URLUtil.trimSpace(path)); configXml = ConfigFileGenerator.generateStopConsolidationScriptConfigFile(configXml, agencyMap); path = URLUtil.trimPath(outputFilePath) + "/" + GeneralConstants.CONSOLIDATION_SCRIPT_CONFIG_FILE; FileUtil.writeToFile(configXml, path); } catch (IOException e) { logger.logError(e); } //Creating sample real-time config file try { String path = ClassLoader.getSystemClassLoader() .getResource(GeneralConstants.SAMPLE_REALTIME_CONFIG_FILE).getPath(); String configXml = FileUtil.readFile(URLUtil.trimSpace(path)); configXml = ConfigFileGenerator.generateSampleRealTimeConfigFile(configXml, agencyMap); path = URLUtil.trimPath(outputFilePath) + "/" + GeneralConstants.SAMPLE_REALTIME_CONFIG_FILE; FileUtil.writeToFile(configXml, path); } catch (IOException e) { logger.logError(e); } } else { logger.logError("Cannot write files"); } logger.log("Consolidation finished..."); }
From source file:com.ibm.jaql.lang.Jaql.java
public static void main(String args[]) throws Exception { InputStream in;//from w w w.j ava 2 s .c o m if (args.length > 0) { in = new FileInputStream(args[0]); } else { in = System.in; } run("<stdin>", new InputStreamReader(in, "UTF-8")); // System.exit(0); // possible jvm 1.6 work around for "JDWP Unable to get JNI 1.2 environment" }
From source file:EchoClient.java
public static void main(String[] args) throws IOException { Socket echoSocket = null;/*from w w w .j a v a 2 s . c o m*/ PrintWriter out = null; BufferedReader in = null; try { echoSocket = new Socket("taranis", 7); out = new PrintWriter(echoSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader( echoSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: taranis."); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for " + "the connection to: taranis."); System.exit(1); } BufferedReader stdIn = new BufferedReader( new InputStreamReader(System.in)); String userInput; while ((userInput = stdIn.readLine()) != null) { out.println(userInput); System.out.println("echo: " + in.readLine()); } out.close(); in.close(); stdIn.close(); echoSocket.close(); }