Package java.io

Examples of java.io.Console$ConsoleReader


        if (pd != null) {
          if (pd.getParameter().password()) {
            //
            // Password option, use the Console to retrieve the password
            //
            Console console = System.console();
            if (console == null) {
              throw new ParameterException("No console is available to get parameter " + a);
            }
            System.out.print("Value for " + a + " (" + pd.getDescription() + "):");
            char[] password = console.readPassword();
            pd.addValue(new String(password));
          } else {
            //
            // Regular option
            //
View Full Code Here


        String username;
        String password;
        MobClient cli;

        try {
            Console console = System.console();
            username = console.readLine("username: ");
            password = new String(console.readPassword("password: "));

            System.out.println("> Connessione al server in corso, attendere...");
            cli = authServer.login(username, password);
        }
        catch (RemoteException re){
View Full Code Here

        });

        System.out.println("> Connessione admin effettuata.");

        boolean uscita = false;
        Console console = System.console();
        int risposta;
        String nomeMatch;
        int maxPlayers;
        ArrayList<String> matches;

        while (!uscita) {


            matches = adminGS.getMatches();

            if (matches.size()>0) System.out.println("\n> Lista partite presenti sul server:");

            for (int k = 0; k < matches.size(); k++) {
                System.out.println(">> (" + k + ") " + matches.get(k));
            }

            System.out.println("\n> 1) creare una nuova partita");
            if (matches.size()>0) System.out.println("> 2) eliminare una partita");
            System.out.println("> 0) esci.");
            risposta = Integer.parseInt(console.readLine(">>> "));

            switch (risposta) {
                case 1:
                    nomeMatch = console.readLine(">>> Inserire il nome della partita: ");
                    maxPlayers = Integer.parseInt(console.readLine(">>> Inserire il numero massimo di utenti (2-4): "));
                    adminGS.createMatch(nomeMatch, maxPlayers);
                    break;

                case 2:
                    int scelta = Integer.parseInt(console.readLine(">>> Inserire il numero della partita: "));
                    if ((scelta>=0) && (scelta<matches.size())){
                        nomeMatch = matches.get(scelta);
                        adminGS.deleteMatch(nomeMatch);
                    }
                    break;
View Full Code Here

import java.util.regex.Matcher;
public class RegexTestHarness {
    public static void main(String[] args){
        Console console = System.console();
        if (console == null) {
            System.err.println("No console.");
            System.exit(1);
        }
        while (true) {
            Pattern pattern =
            Pattern.compile(console.readLine("%nEnter your regex: "));
            Matcher matcher =
            pattern.matcher(console.readLine("Enter input string to search: "));
            boolean found = false;
            while (matcher.find()) {
                console.format("I found the text" +
                    " \"%s\" starting at " +
                    "index %d and ending at index %d.%n",
                    matcher.group(),
                    matcher.start(),
                    matcher.end());
                found = true;
            }
            if(!found){
                console.format("No match found.%n");
            }
        }
    }
View Full Code Here

         *
         * The next prompted-for value will be the admin password, if required.
         */
        if (programOpts.getUser() == null && !noPassword) {
            // prompt for it (if interactive)
            Console cons = System.console();
            if (cons != null && programOpts.isInteractive()) {
                cons.printf("%s", strings.get("AdminUserRequiredPrompt",
                        SystemPropertyConstants.DEFAULT_ADMIN_USER));
                String val = cons.readLine();
                if (ok(val)) {
                    programOpts.setUser(val);
                    if (adminPassword == null) {
                        adminPassword = getAdminPassword();
                    }
View Full Code Here

    /**
     * Collect a JDR report when run outside the Application Server.
     */
    public JdrReport standaloneCollect(String host, String port) throws OperationFailedException {
        Console cons = System.console();
        String username = null;
        String password = null;

        if (host == null) {
            host = "localhost";
        }
        if (port == null) {
            port = "9990";
        }

        // Let's go ahead and see if we need to auth before prompting the user
        // for a username and password
        boolean must_auth = false;

        try {
            URL managementApi = new URL("http://" + host + ":" + port + "/management");
            HttpURLConnection conn = (HttpURLConnection) managementApi.openConnection();
            int code = conn.getResponseCode();
            if (code != 200) {
                must_auth = true;
            }
        }
        catch(Exception e) {
        }

        if (must_auth) {
            if (cons != null) {
                username = cons.readLine("Management username: ");
                password = String.valueOf(cons.readPassword("Management password: "));
            }
        }
        SosInterpreter interpreter = new SosInterpreter();
        return interpreter.collect(username, password, host, port);
    }
View Full Code Here

     * @throws Exception
     */
    private void negotiateAdministratorDetails()
      throws Exception
    {
        Console console = System.console();
     
      System.out.println("Creating an initial administrator account");
     
      boolean dataOK = false;
     
      String email = null;
      String firstName = null;
      String lastName = null;
        char[] password1 = null;
        char[] password2 = null;
      String language = I18nUtil.DEFAULTLOCALE.getLanguage();
     
      while (!dataOK)
      {
        System.out.print("E-mail address: ");
        System.out.flush();
       
        email = console.readLine();
            if (!StringUtils.isBlank(email))
            {
                email = email.trim();
            }
            else
            {
                System.out.println("Please provide an email address.");
                continue;
            }
       
        System.out.print("First name: ");
        System.out.flush();
       
        firstName = console.readLine();

            if (firstName != null)
            {
                firstName = firstName.trim();
            }
       
        System.out.print("Last name: ");
        System.out.flush();
       
        lastName = console.readLine();

            if (lastName != null)
            {
                lastName = lastName.trim();
            }
      
            if (ConfigurationManager.getProperty("webui.supported.locales") != null)
            {
                System.out.println("Select one of the following languages: " + ConfigurationManager.getProperty("webui.supported.locales"));
                System.out.print("Language: ");
                System.out.flush();
           
            language = console.readLine();

                if (language != null)
                {
                    language = language.trim();
                    language = I18nUtil.getSupportedLocale(new Locale(language)).getLanguage();
                }
            }
           
        System.out.println("Password will not display on screen.");
        System.out.print("Password: ");
        System.out.flush();

        password1 = console.readPassword();
       
        System.out.print("Again to confirm: ");
        System.out.flush();
       
        password2 = console.readPassword();

            //TODO real password validation
            if (password1.length > 1 && Arrays.equals(password1, password2))
        {
          // password OK
          System.out.print("Is the above data correct? (y or n): ");
          System.out.flush();
         
          String s = console.readLine();

                if (s != null)
                {
                    s = s.trim();
                    if (s.toLowerCase().startsWith("y"))
View Full Code Here

  @Override
  public char[] readPassword(Mode mode) throws PreferencesException
  {
    char[] password;
   
    Console console = System.console();
    if (console == null)
    {
       if (isEchoAllowed())
       {
         //Since we are echoing the password anyway no need to make the user validate by typing second time
        
         if (!StringUtils.isEmpty(getEchoWarningText()))
           System.err.println(getEchoWarningText());
     
         if (!StringUtils.isEmpty(getPasswordPrompt()))
           System.err.print(getPasswordPrompt() + ": ");
        
         @SuppressWarnings("resource") //Don't want to close System.in
         Scanner sc = new Scanner(System.in);
         try
         {
           password = sc.nextLine().toCharArray();
         }
         catch (NoSuchElementException e)
         {
           //End of System.in stream possible I guess, regard as a cancel
           password = null;
         }
       }
       else
         throw new PreferencesException("Console not available, cannot read password from user securely.");
    }
    else
    {
      if (mode == Mode.ENCRYPTION)
      {
        boolean passwordsAreTheSame;
        do
        {
          if (!StringUtils.isEmpty(getPasswordPrompt()))
             System.err.print(getPasswordPrompt() + ": ");
         
          password = console.readPassword();
         
          //User cancelled
          if (password.length == 0)
            return(null);
         
          if (!StringUtils.isEmpty(getVerifyPrompt()))
            System.err.print(getVerifyPrompt() + ": ");
           
          char[] verifyPassword = console.readPassword();
         
          passwordsAreTheSame = Arrays.equals(password, verifyPassword);
          if (!passwordsAreTheSame && !StringUtils.isEmpty(getVerifyErrorMessage()))
            System.err.println(getVerifyErrorMessage());
        }
        while (!passwordsAreTheSame);
      }
      else
      {
        if (!StringUtils.isEmpty(getPasswordPrompt()))
           System.err.print(getPasswordPrompt() + ": ");
       
        password = console.readPassword();
      }
    }
     
    //If the user just presses ENTER regard as a cancel
    if (password != null && password.length == 0)
View Full Code Here

        while (true) {
            String readLine = null;
            String dv = getDefault(env);
            String prompt = getPrompt(projectName, env, dv);
            if (System.console() != null) {
                Console console = System.console();
                if (console == null) {
                    throw new RuntimeException(Messages.msg("no.console"));
                }
                readLine = console.readLine(prompt);
            } else {
                System.out.print(prompt);
                BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
                try {
                    readLine = reader.readLine();
View Full Code Here

    String secNum = (String) xpath.evaluate(expr, document, XPathConstants.STRING);
    return secNum;
  }

  private static String promptForPathExpr() {
    Console c = System.console();
    if (c == null) {
      throw new IllegalStateException("This app needs a 'controlling terminal' to prompt; use with filename and expr arguments");
    }
    return c.readLine("Enter XPath prompt for %s", fileName);
  }
View Full Code Here

TOP

Related Classes of java.io.Console$ConsoleReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.