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.asquareb.kaaval.MachineKey.java
/** * Main method to execute as a command line utility. Provides the option to * encrypt a string, decrypt a encrypted string or exit from the program *///w w w. j a v a 2s . c o m public static void main(String[] args) { String originalPassword = null; String encryptedPassword = null; try { final BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter E - Encrypt,D - Decrypt,X - Exit :"); final String choice = cin.readLine(); final Random rand = new Random(); boolean phraseCorrect = false; String app = null; if (choice.equalsIgnoreCase("E")) { System.out.print("Enter the string to encrypt :"); originalPassword = cin.readLine(); System.out.println("Choose a phrase of min 8 chars in length "); System.out.println(" Also the password should include 2 Cap,"); System.out.println(" 2 small letters,2 numeric and 2 non alpha numeric chars"); while (!phraseCorrect) { System.out.print("Enter a phrase to encrypt :"); password = cin.readLine().toCharArray(); phraseCorrect = PasswordRules.verifyPassword(password); } System.out.print("Enter application code :"); app = cin.readLine(); app += (rand.nextInt(10000)); encryptedPassword = encrypt(originalPassword, app); System.out.println("Encrypted password :" + encryptedPassword); System.out.println("Key stored in :" + app); System.out.println("*** Provide the encrypted string to app team"); System.out.println("*** Store the key file in a secure durectory"); System.out.println("*** Inform the key file name and location to app team"); } else if (choice.equalsIgnoreCase("D")) { System.out.print("Enter the string to Decrypt :"); encryptedPassword = cin.readLine(); System.out.print("Enter the name of key file :"); app = cin.readLine(); final String decryptedPassword = decrypt(encryptedPassword, app); System.out.print("Decrypted string :" + decryptedPassword); } return; } catch (KaavalException e) { e.PrintProtectException(); } catch (Exception e) { e.printStackTrace(); } }
From source file:OpenDataExtractor.java
public static void main(String[] args) { System.out.println("\nSeleziona in che campo fare la ricerca: "); System.out.println("Elenco completo delle gare in formato (1)"); // cc16106a-1a65-4c34-af13-cc045d181452 System.out.println("Composizione delle commissioni giudicatrici (2)"); // c90f1ffb-c315-4f59-b0e3-b0f2f8709127 System.out.println("Registro delle imprese escluse dalle gare (3)"); // 2ea798cc-1f52-4fc8-a28e-f92a6f409cb8 System.out.println("Registro delle imprese invitate alle gare (4)"); // a124b6af-ae31-428a-8ac5-bb341feb3c46 System.out.println("Registro delle imprese che hanno partecipato alle gare (5)");// e58396cf-1145-4cb1-84a4-34311238a0c6 System.out.println("Anagrafica completa dei contratti per l'acquisizione di beni e servizi (6)"); // aa6a8664-5ef5-43eb-a563-910e25161798 System.out.println("Fornitori (7)"); // 253c8ac9-8335-4425-84c5-4a90be863c00 System.out.println("Autorizzazioni subappalti per i lavori (8)"); // 4f9ba542-5768-4b39-a92a-450c45eabd5d System.out.println("Aggiudicazioni delle gare per i lavori (9)"); // 34e298ad-3a99-4feb-9614-b9c4071b9d8e System.out.println("Dati cruscotto lavori per area (10)"); // 1ee3ea1b-58e3-48bf-8eeb-36ac313eeaf8 System.out.println("Dati cruscotto lavori per lotto (11)"); // cbededce-269f-48d2-8c25-2359bf246f42 int count = 0; int scelta;//from w ww. j a v a 2 s . c o m String id_ref = ""; Scanner scanner; try { do { scanner = new Scanner(System.in); scelta = scanner.nextInt(); switch (scelta) { case 1: id_ref = "cc16106a-1a65-4c34-af13-cc045d181452&q="; break; case 2: id_ref = "c90f1ffb-c315-4f59-b0e3-b0f2f8709127&q="; break; case 3: id_ref = "2ea798cc-1f52-4fc8-a28e-f92a6f409cb8&q="; break; case 4: id_ref = "a124b6af-ae31-428a-8ac5-bb341feb3c46&q="; break; case 5: id_ref = "e58396cf-1145-4cb1-84a4-34311238a0c6&q="; break; case 6: id_ref = "aa6a8664-5ef5-43eb-a563-910e25161798&q="; break; case 7: id_ref = "253c8ac9-8335-4425-84c5-4a90be863c00&q="; break; case 8: id_ref = "4f9ba542-5768-4b39-a92a-450c45eabd5d&q="; break; case 9: id_ref = "34e298ad-3a99-4feb-9614-b9c4071b9d8e&q="; break; case 10: id_ref = "1ee3ea1b-58e3-48bf-8eeb-36ac313eeaf8&q="; break; case 11: id_ref = "cbededce-269f-48d2-8c25-2359bf246f42&q="; break; default: System.out.println("Numero non selezionabile"); System.out.println("Reinserisci"); break; } } while (scelta <= 0 || scelta > 11); scanner = new Scanner(System.in); System.out.println("Inserisci un parametro di ricerca: "); String record = scanner.nextLine(); String limit = "&limit=10000"; System.out.println("id di riferimento: " + id_ref); System.out.println("___________________________"); String requestString = "http://dati.openexpo2015.it/catalog/api/action/datastore_search?resource_id=" + id_ref + record + limit; HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(requestString); HttpResponse response = client.execute(request); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String result = ""; String resline = ""; while ((resline = rd.readLine()) != null) { result += resline; } if (result != null) { JSONObject jsonObject = new JSONObject(result); JSONObject resultJson = (JSONObject) jsonObject.get("result"); JSONArray resultJsonFields = (JSONArray) resultJson.get("fields"); ArrayList<TypeFields> type = new ArrayList<TypeFields>(); TypeFields type1; JSONObject temp; while (count < resultJsonFields.length()) { temp = (JSONObject) resultJsonFields.get(count); type1 = new TypeFields(temp.getString("id"), temp.getString("type")); type.add(type1); count++; } JSONArray arr = (JSONArray) resultJson.get("records"); count = 0; while (count < arr.length()) { System.out.println("Entry numero: " + count); temp = (JSONObject) arr.get(count); for (TypeFields temp2 : type) { System.out.println(temp2.nameType + ": " + temp.get(temp2.nameType)); } count++; System.out.println("--------------------------"); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:examples.SubnetUtilsExample.java
public static void main(String[] args) { String subnet = "192.168.0.1/29"; SubnetUtils utils = new SubnetUtils(subnet); SubnetInfo info = utils.getInfo();/*w ww .j a v a 2 s .c o m*/ System.out.printf("Subnet Information for %s:\n", subnet); System.out.println("--------------------------------------"); System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(), Integer.toBinaryString(info.asInteger(info.getAddress()))); System.out.printf("Netmask:\t\t\t%s\t[%s]\n", info.getNetmask(), Integer.toBinaryString(info.asInteger(info.getNetmask()))); System.out.printf("CIDR Representation:\t\t%s\n\n", info.getCidrSignature()); System.out.printf("Supplied IP Address:\t\t%s\n\n", info.getAddress()); System.out.printf("Network Address:\t\t%s\t[%s]\n", info.getNetworkAddress(), Integer.toBinaryString(info.asInteger(info.getNetworkAddress()))); System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(), Integer.toBinaryString(info.asInteger(info.getBroadcastAddress()))); System.out.printf("First Usable Address:\t\t%s\t[%s]\n", info.getLowAddress(), Integer.toBinaryString(info.asInteger(info.getLowAddress()))); System.out.printf("Last Usable Address:\t\t%s\t[%s]\n", info.getHighAddress(), Integer.toBinaryString(info.asInteger(info.getHighAddress()))); System.out.printf("Total usable addresses: \t%d\n", info.getAddressCount()); System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses())); final String prompt = "Enter an IP address (e.g. 192.168.0.10):"; System.out.println(prompt); Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String address = scanner.nextLine(); System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ") + "within the subnet [" + subnet + "]"); System.out.println(prompt); } }
From source file:com.datastax.sparql.ConsoleCompiler.java
public static void main(final String[] args) throws IOException { //args = "/examples/modern1.sparql"; final Options options = new Options(); options.addOption("f", "file", true, "a file that contains a SPARQL query"); options.addOption("g", "graph", true, "the graph that's used to execute the query [classic|modern|crew|kryo file]"); // TODO: add an OLAP option (perhaps: "--olap spark"?) final CommandLineParser parser = new DefaultParser(); final CommandLine commandLine; try {/* w ww .j a v a2 s. com*/ commandLine = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); printHelp(1); return; } final InputStream inputStream = commandLine.hasOption("file") ? new FileInputStream(commandLine.getOptionValue("file")) : System.in; final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); final StringBuilder queryBuilder = new StringBuilder(); if (!reader.ready()) { printHelp(1); } String line; while (null != (line = reader.readLine())) { queryBuilder.append(System.lineSeparator()).append(line); } final String queryString = queryBuilder.toString(); final Graph graph; if (commandLine.hasOption("graph")) { switch (commandLine.getOptionValue("graph").toLowerCase()) { case "classic": graph = TinkerFactory.createClassic(); break; case "modern": graph = TinkerFactory.createModern(); System.out.println("Modern Graph Created"); break; case "crew": graph = TinkerFactory.createTheCrew(); break; default: graph = TinkerGraph.open(); System.out.println("Graph Created"); long startTime = System.nanoTime(); graph.io(IoCore.gryo()).readGraph(commandLine.getOptionValue("graph")); long endTime = System.nanoTime(); System.out.println("Time taken to load graph from kyro file: " + (endTime - startTime) / 1000000 + " mili seconds"); break; } } else { graph = TinkerFactory.createModern(); } final Traversal<Vertex, ?> traversal = SparqlToGremlinCompiler.convertToGremlinTraversal(graph, queryString); printWithHeadline("SPARQL Query", queryString); printWithHeadline("Traversal (prior execution)", traversal); Bytecode traversalByteCode = traversal.asAdmin().getBytecode(); //JavaTranslator.of(graph.traversal()).translate(traversalByteCode); System.out.println("the Byte Code : " + traversalByteCode.toString()); printWithHeadline("Result", String.join(System.lineSeparator(), JavaTranslator.of(graph.traversal()) .translate(traversalByteCode).toStream().map(Object::toString).collect(Collectors.toList()))); printWithHeadline("Traversal (after execution)", traversal); }
From source file:PSFormatter.java
public static void main(String[] av) throws IOException { if (av.length == 0) new PSFormatter(new InputStreamReader(System.in)).process(); else/* ww w . java 2 s .c o m*/ for (int i = 0; i < av.length; i++) { new PSFormatter(av[i]).process(); } }
From source file:examples.cidr.SubnetUtilsExample.java
public static void main(String[] args) { String subnet = "192.168.0.3/31"; SubnetUtils utils = new SubnetUtils(subnet); SubnetInfo info = utils.getInfo();/*from w w w .j a va 2 s .co m*/ System.out.printf("Subnet Information for %s:\n", subnet); System.out.println("--------------------------------------"); System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(), Integer.toBinaryString(info.asInteger(info.getAddress()))); System.out.printf("Netmask:\t\t\t%s\t[%s]\n", info.getNetmask(), Integer.toBinaryString(info.asInteger(info.getNetmask()))); System.out.printf("CIDR Representation:\t\t%s\n\n", info.getCidrSignature()); System.out.printf("Supplied IP Address:\t\t%s\n\n", info.getAddress()); System.out.printf("Network Address:\t\t%s\t[%s]\n", info.getNetworkAddress(), Integer.toBinaryString(info.asInteger(info.getNetworkAddress()))); System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(), Integer.toBinaryString(info.asInteger(info.getBroadcastAddress()))); System.out.printf("Low Address:\t\t\t%s\t[%s]\n", info.getLowAddress(), Integer.toBinaryString(info.asInteger(info.getLowAddress()))); System.out.printf("High Address:\t\t\t%s\t[%s]\n", info.getHighAddress(), Integer.toBinaryString(info.asInteger(info.getHighAddress()))); System.out.printf("Total usable addresses: \t%d\n", Integer.valueOf(info.getAddressCount())); System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses())); final String prompt = "Enter an IP address (e.g. 192.168.0.10):"; System.out.println(prompt); Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String address = scanner.nextLine(); System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ") + "within the subnet [" + subnet + "]"); System.out.println(prompt); } }
From source file:CSVRE.java
public static void main(String[] argv) throws IOException { System.out.println(CSV_PATTERN); new CSVRE().process(new BufferedReader(new InputStreamReader(System.in))); }
From source file:com.bjond.Main.java
/** * Main entry point. Takes no parameters. Just accepts stdin and outputs to * stdout. Old school...//from w ww.ja v a2 s.c o m * * @param args * * @throws IOException * @throws SQLException */ public static void main(String[] args) throws IOException, SQLException { process(System.in, System.out); }
From source file:edu.oregonstate.eecs.mcplan.domains.yahtzee2.YahtzeeClient.java
/** * @param args//from w ww . j av a 2 s . c o m * @throws IOException */ public static void main(final String[] args) throws IOException { final RandomGenerator rng = new MersenneTwister(42); final YahtzeeState s0 = new YahtzeeState(rng); final YahtzeeSimulator sim = new YahtzeeSimulator(rng, s0); final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); while (!sim.state().isTerminal()) { printState(sim.state()); final String cmd = reader.readLine(); final String[] parts = cmd.split(" "); if ("keep".equals(parts[0])) { final int[] keepers = new int[Hand.Nfaces]; for (int i = 1; i < parts.length; ++i) { final int v = Integer.parseInt(parts[i]); keepers[v - 1] += 1; } sim.takeAction(new JointAction<YahtzeeAction>(new KeepAction(keepers))); } else if ("score".equals(parts[0])) { final YahtzeeScores category = YahtzeeScores.valueOf(parts[1]); sim.takeAction(new JointAction<YahtzeeAction>(new ScoreAction(category))); } else if ("undo".equals(parts[0])) { sim.untakeLastAction(); } else { System.out.println("!!! Bad command"); } } System.out.println("********** Terminal **********"); printState(sim.state()); }
From source file:ExecuteSQL.java
public static void main(String[] args) { Connection conn = null; // Our JDBC connection to the database server try {//from w w w . ja va 2s.c o m String driver = null, url = null, user = "", password = ""; // Parse all the command-line arguments for (int n = 0; n < args.length; n++) { if (args[n].equals("-d")) driver = args[++n]; else if (args[n].equals("-u")) user = args[++n]; else if (args[n].equals("-p")) password = args[++n]; else if (url == null) url = args[n]; else throw new IllegalArgumentException("Unknown argument."); } // The only required argument is the database URL. if (url == null) throw new IllegalArgumentException("No database specified"); // If the user specified the classname for the DB driver, load // that class dynamically. This gives the driver the opportunity // to register itself with the DriverManager. if (driver != null) Class.forName(driver); // Now open a connection the specified database, using the // user-specified username and password, if any. The driver // manager will try all of the DB drivers it knows about to try to // parse the URL and connect to the DB server. conn = DriverManager.getConnection(url, user, password); // Now create the statement object we'll use to talk to the DB Statement s = conn.createStatement(); // Get a stream to read from the console BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // Loop forever, reading the user's queries and executing them while (true) { System.out.print("sql> "); // prompt the user System.out.flush(); // make the prompt appear now. String sql = in.readLine(); // get a line of input from user // Quit when the user types "quit". if ((sql == null) || sql.equals("quit")) break; // Ignore blank lines if (sql.length() == 0) continue; // Now, execute the user's line of SQL and display results. try { // We don't know if this is a query or some kind of // update, so we use execute() instead of executeQuery() // or executeUpdate() If the return value is true, it was // a query, else an update. boolean status = s.execute(sql); // Some complex SQL queries can return more than one set // of results, so loop until there are no more results do { if (status) { // it was a query and returns a ResultSet ResultSet rs = s.getResultSet(); // Get results printResultsTable(rs, System.out); // Display them } else { // If the SQL command that was executed was some // kind of update rather than a query, then it // doesn't return a ResultSet. Instead, we just // print the number of rows that were affected. int numUpdates = s.getUpdateCount(); System.out.println("Ok. " + numUpdates + " rows affected."); } // Now go see if there are even more results, and // continue the results display loop if there are. status = s.getMoreResults(); } while (status || s.getUpdateCount() != -1); } // If a SQLException is thrown, display an error message. // Note that SQLExceptions can have a general message and a // DB-specific message returned by getSQLState() catch (SQLException e) { System.err.println("SQLException: " + e.getMessage() + ":" + e.getSQLState()); } // Each time through this loop, check to see if there were any // warnings. Note that there can be a whole chain of warnings. finally { // print out any warnings that occurred SQLWarning w; for (w = conn.getWarnings(); w != null; w = w.getNextWarning()) System.err.println("WARNING: " + w.getMessage() + ":" + w.getSQLState()); } } } // Handle exceptions that occur during argument parsing, database // connection setup, etc. For SQLExceptions, print the details. catch (Exception e) { System.err.println(e); if (e instanceof SQLException) System.err.println("SQL State: " + ((SQLException) e).getSQLState()); System.err.println( "Usage: java ExecuteSQL [-d <driver>] " + "[-u <user>] [-p <password>] <database URL>"); } // Be sure to always close the database connection when we exit, // whether we exit because the user types 'quit' or because of an // exception thrown while setting things up. Closing this connection // also implicitly closes any open statements and result sets // associated with it. finally { try { conn.close(); } catch (Exception e) { } } }