Java Code Examples for java.io.Console#printf()
The following examples show how to use
java.io.Console#printf() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CMFMasterService.java From knox with Apache License 2.0 | 6 votes |
protected void displayWarning(boolean persisting) { Console c = System.console(); if (c == null) { LOG.unableToPromptForMasterUseKnoxCLI(); System.err.println("No console."); System.exit(1); } if (persisting) { c.printf("***************************************************************************************************\n"); c.printf("You have indicated that you would like to persist the master secret for this service instance.\n"); c.printf("Be aware that this is less secure than manually entering the secret on startup.\n"); c.printf("The persisted file will be encrypted and primarily protected through OS permissions.\n"); c.printf("***************************************************************************************************\n"); } else { c.printf("***************************************************************************************************\n"); c.printf("Be aware that you will need to enter your master secret for future starts exactly as you do here.\n"); c.printf("This secret is needed to access protected resources for the service process.\n"); c.printf("The master secret must be protected, kept secret and not stored in clear text anywhere.\n"); c.printf("***************************************************************************************************\n"); } }
Example 2
Source File: ConsoleConsoleClass.java From tutorials with MIT License | 6 votes |
public static void main(String[] args) { Console console = System.console(); if (console == null) { System.out.print("No console available"); return; } String progLanguauge = console.readLine("Enter your favourite programming language: "); console.printf(progLanguauge + " is very interesting!"); char[] pass = console.readPassword("To finish, enter password: "); if ("BAELDUNG".equals(pass.toString().toUpperCase())) console.printf("Good! Regards!"); else console.printf("Nice try. Regards."); }
Example 3
Source File: Aion.java From aion with MIT License | 5 votes |
private static char[] getSslPassword(CfgAion cfg) { CfgSsl sslCfg = cfg.getApi().getRpc().getSsl(); char[] sslPass = sslCfg.getPass(); // interactively ask for a password for the ssl file if they did not set on in the config // file if (sslCfg.getEnabled() && sslPass == null) { Console console = System.console(); // https://docs.oracle.com/javase/10/docs/api/java/io/Console.html // if the console does not exist, then either: // 1) jvm's underlying platform does not provide console // 2) process started in non-interactive mode (background scheduler, redirected output, // etc.) // don't wan't to compromise security in these scenarios if (console == null) { System.out.println( "SSL-certificate-use requested with RPC server and no console found. " + "Please set the ssl password in the config file (insecure) to run kernel non-interactively with this option."); System.exit(SystemExitCodes.INITIALIZATION_ERROR); } else { console.printf("---------------------------------------------\n"); console.printf("----------- INTERACTION REQUIRED ------------\n"); console.printf("---------------------------------------------\n"); sslPass = console.readPassword( "Password for SSL keystore file [" + sslCfg.getCert() + "]\n"); } } return sslPass; }
Example 4
Source File: Cli.java From aion with MIT License | 5 votes |
private String getCertName(Console console) { console.printf("Enter certificate name:\n"); String certName = console.readLine(); if ((certName == null) || (certName.isEmpty())) { System.out.println("Error: no certificate name entered."); System.exit(SystemExitCodes.INITIALIZATION_ERROR); } return certName; }
Example 5
Source File: AuthenticateInStandaloneApplication.java From google-ads-java with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { // Generates the client ID and client secret from the Google Cloud Console: // https://console.cloud.google.com String clientId; String clientSecret; Console console = System.console(); if (console == null) { // The console will be null when running this example in some IDEs. In this case, please // set the clientId and clientSecret in the lines below. clientId = "INSERT_CLIENT_ID_HERE"; clientSecret = "INSERT_CLIENT_SECRET_HERE"; // Ensures that the client ID and client secret are not the "INSERT_..._HERE" values. Preconditions.checkArgument( !clientId.matches("INSERT_.*_HERE"), "Client ID is invalid. Please update the example and try again."); Preconditions.checkArgument( !clientSecret.matches("INSERT_.*_HERE"), "Client secret is invalid. Please update the example and try again."); } else { console.printf( "NOTE: When prompting for the client secret below, echoing will be disabled%n"); console.printf(" since the client secret is sensitive information.%n"); console.printf("Enter your client ID:%n"); clientId = console.readLine(); console.printf("Enter your client secret:%n"); clientSecret = String.valueOf(console.readPassword()); } new AuthenticateInStandaloneApplication().runExample(clientId, clientSecret); }
Example 6
Source File: AuthenticateInWebApplication.java From google-ads-java with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { // To fill in the values below, generate a client ID and client secret from the Google Cloud // Console (https://console.cloud.google.com) by creating credentials for a Web application. // Set the "Authorized redirect URIs" to: // http://localhost/oauth2callback String clientId; String clientSecret; String loginEmailAddressHint; Console console = System.console(); if (console == null) { // The console will be null when running this example in some IDEs. In this case, please // set the clientId and clientSecret in the lines below. clientId = "INSERT_CLIENT_ID_HERE"; clientSecret = "INSERT_CLIENT_SECRET_HERE"; // Optional: If your application knows which user is trying to authenticate, you can set this // to the user's email address so that the Google Authentication Server will automatically // populate the account selection prompt with that address. loginEmailAddressHint = null; // Ensures that the client ID and client secret are not the "INSERT_..._HERE" values. Preconditions.checkArgument( !clientId.matches("INSERT_.*_HERE"), "Client ID is invalid. Please update the example and try again."); Preconditions.checkArgument( !clientSecret.matches("INSERT_.*_HERE"), "Client secret is invalid. Please update the example and try again."); } else { console.printf( "NOTE: When prompting for the client secret below, echoing will be disabled%n"); console.printf(" since the client secret is sensitive information.%n"); console.printf("Enter your client ID:%n"); clientId = console.readLine(); console.printf("Enter your client secret:%n"); clientSecret = String.valueOf(console.readPassword()); console.printf("(Optional) Enter the login email address hint:%n"); loginEmailAddressHint = Strings.emptyToNull(console.readLine()); } new AuthenticateInWebApplication().runExample(clientId, clientSecret, loginEmailAddressHint); }
Example 7
Source File: ConsoleDemo.java From JavaCommon with Apache License 2.0 | 5 votes |
public static void main(String[] args) { Console console = System.console(); if (console != null) { String user = new String(console.readLine("Enter User:", new Object[0])); String pwd = new String(console.readPassword("Enter Password:", new Object[0])); console.printf("User name is:%s", new Object[] { user }); console.printf("Password is:%s", new Object[] { pwd }); } else { System.out.println("No Console!"); } }
Example 8
Source File: SystemClassExamples.java From journaldev with MIT License | 5 votes |
private static void systemConsoleDemo() { Console console = System.console(); if(console != null){ Calendar c = new GregorianCalendar(); console.printf("Welcome %1$s%n", "Pankaj"); //prints "Welcome Pankaj" console.printf("Current time is: %1$tm %1$te,%1$tY%n", c); //prints "Current time is: 08 5,2013" console.flush(); }else{ //No console is attached when run through Eclipse, background process System.out.println("No Console attached"); } }
Example 9
Source File: StdInPasswordCallback.java From camelinaction2 with Apache License 2.0 | 5 votes |
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { WSPasswordCallback pc = (WSPasswordCallback) callbacks[0]; Console console = System.console(); console.printf("Please enter your Rider Auto Parts password: "); char[] passwordChars = console.readPassword(); String passwordString = new String(passwordChars); pc.setPassword(passwordString); }
Example 10
Source File: CliMain.java From btrbck with GNU General Public License v3.0 | 5 votes |
private void cmdLock() { readAndLockRepository(); Console console = System.console(); if (console != null) { console.printf("Repository locked. Press enter to unlock.\n"); console.readLine(); console.printf("Repository unlocked.\n"); } }
Example 11
Source File: AddUser.java From keycloak with Apache License 2.0 | 5 votes |
private static String promptForInput() throws Exception { Console console = System.console(); if (console == null) { throw new Exception("Couldn't get Console instance"); } console.printf("Press ctrl-d (Unix) or ctrl-z (Windows) to exit\n"); char passwordArray[] = console.readPassword("Password: "); if(passwordArray == null) System.exit(0); return new String(passwordArray); }