Package java.io

Examples of java.io.Console$ConsoleWriter


  public static final int LOCAL_PORT = 10000;
  public static final String LOCAL_HOST = "localhost";

  public static void main(String[] args) {

    Console console = System.console();
    //read user name, using java.util.Formatter syntax :
    if (vcap_email == null) {
      vcap_email = console.readLine("Login E-Mail? ");
        }
    //read the password, without echoing the output
    if (vcap_passwd == null) {
      vcap_passwd = new String(console.readPassword("Password? "));
        }

    CloudFoundryClient client =  clientInit();

    String version = client.getCloudInfo().getVersion();
    if (Float.valueOf(version) >= 2.0) {
      //read org, using java.util.Formatter syntax :
      if (vcap_org == null) {
        vcap_org = console.readLine("Org to use? ");
      }
      //read space, using java.util.Formatter syntax :
      if (vcap_space == null) {
        vcap_space = console.readLine("Space to use? ");
      }

      client =  clientOrgSpace(client);
    }

    CloudApplication serverApp = null;
    try {
      serverApp = client.getApplication(TunnelHelper.getTunnelAppName());
    }
    catch (CloudFoundryException e) {}
    if (serverApp == null) {
      System.out.println("Deploying Caldecott server app");
      TunnelHelper.deployTunnelApp(client);
    }
    try {
      serverApp = client.getApplication(TunnelHelper.getTunnelAppName());
    }
    catch (CloudFoundryException e) {
      System.err.println("Unable to deploy Caldecott server app: " + e.getMessage());
      throw e;
    }
    if (!serverApp.getState().equals(CloudApplication.AppState.STARTED)) {
      System.out.println("Starting Caldecott server app");
      client.startApplication(serverApp.getName());
    }

    while (vcap_service == null) {
      System.out.println("You have the following services defined:");
      List<CloudService> services = client.getServices();
      int i = 0;
      for (CloudService svc : services) {
        i++;
        System.out.println(i + ": " + svc.getName());
      }
      if (i ==0) {
        System.err.println("It looks like you don't have any services defined. Please create one first!");
        System.exit(1);
      }
      String svc = console.readLine("Which Service to connect to (" + 1 + "-" + i +")? ");
      int svc_ix = 0;
      try {
        svc_ix = Integer.parseInt(svc);
      } catch (NumberFormatException e) {
        System.err.println(svc + " is not a valid choice!");
        continue;
      }
      if (svc_ix < 1 || svc_ix > i) {
        System.err.println(svc + " is not a valid choice!");
        continue;
      }
      vcap_service = services.get(svc_ix - 1).getName();
    }
    System.out.println("Starting tunnel on " + CC_URL + " to service " + vcap_service + " on behalf of " + vcap_email);

    TunnelHelper.bindServiceToTunnelApp(client, vcap_service);

    InetSocketAddress local = new InetSocketAddress(LOCAL_HOST, LOCAL_PORT);
    String url = TunnelHelper.getTunnelUri(client);
    Map<String, String> info = TunnelHelper.getTunnelServiceInfo(client, vcap_service);
    String host = info.get("hostname");
    int port = Integer.valueOf(info.get("port"));
    String auth = TunnelHelper.getTunnelAuth(client);

    String svc_username = info.get("username");
    String svc_passwd = info.get("password");
    String svc_dbname = info.get("db") != null ? info.get("db") : info.get("name");
    String txt_dbname = info.get("db") != null ? "db" : "name";
    String svc_vhost = info.get("vhost");

    TunnelServer server = new TunnelServer(local, new HttpTunnelFactory(url, host, port, auth));

    server.start();

    System.out.println("Tunnel is running on " + LOCAL_HOST +" port " + LOCAL_PORT + " with auth=" + auth);
    if (svc_vhost != null) {
      System.out.println("Connect client with username=" + svc_username +" password=" + svc_passwd + " " + "vhost=" + svc_vhost);
    }
    else {
      System.out.println("Connect client with username=" + svc_username +" password=" + svc_passwd + " " + txt_dbname + "=" + svc_dbname);
    }
    while (true) {
      if (console != null) {
        String command = console.readLine("Enter exit to stop: ");
        if (command.toLowerCase().equals("exit")) {
          break;
        }
      }
      try {
View Full Code Here


                                       "authScheme is " + authScheme);
                    parser.printUsage(System.err);
                    System.exit(1);
                }
                if (keyStorePassword == null) {
                    Console con = System.console();
                    char[] password = con.readPassword("Enter key store password: ");
                    keyStorePassword = new String(password);
                }
            }
        }
View Full Code Here

  }

  @Override
  public String readPassword() throws IOException {
    String password = null;
    Console cons;
    char[] passwd;
    if ((cons = System.console()) != null
        && (passwd = cons.readPassword("[%s]", "password:")) != null) {
      password = new String(passwd);
    }
    return password;
  }
View Full Code Here

  }

  @Override
  public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

    Console cons = System.console();
    if (cons == null && password == null) {
      throw new UnsupportedCallbackException(callbacks[0], "Console is not available");
    }

    for (int i = 0; i < callbacks.length; i++) {

      if (callbacks[i] instanceof PasswordCallback) {

        PasswordCallback passwordCallback = (PasswordCallback) callbacks[i];

        if (password == null) {
          // It is used instead of cons.readPassword(prompt), because the prompt
          // may contain '%' characters
          passwordCallback.setPassword(cons.readPassword("%s", new Object[] {((PasswordCallback) callbacks[i]).getPrompt()}));
        }
        else {
          passwordCallback.setPassword(password);
        }
      }
View Full Code Here

      commands.put("peek", new PeekSharesCommand());
      commands.put("history", new HistoryCommand());
   }

   public static void main(String args[]) throws Exception {
      Console con = System.console();
      Client client = new Client(con);
      con.printf(PROMPT);

      while (true) {
         String input = con.readLine(">");
         if ("quit".equals(input)) break;
         Command cmd = client.parseCommand(input);
         if (cmd == null) {
            con.printf("Unable to perform the requested action.\n");
         } else {
            cmd.execute(con, input);
         }
      }
   }
View Full Code Here

                    server.getAbsolutePath());
        }
        // TODO: try to detect if launching from external volume like a flash
        // drive and store on the local flash drive instead

        Console console = System.console();
        int result;
        try {
            if (console == null && argv.length == 0) {
                argv = new String[] { "serve", "--gui" };
            }
View Full Code Here

            String pass = commands.getOptionValue("p");
            if (pass != null) {
                password = pass.toCharArray();
            } else {
                try {
                    Console console = System.console();
                    if (console != null) {
                        password = console.readPassword("Password: ");
                    } else {
                        log.info("No console detected for password input.");
                    }
                } catch (Throwable t) {
                    log.error("Unexpected error while reading password", t);
View Full Code Here

        String pass = commands.getOptionValue("p");
        if (pass != null) {
            password = pass.toCharArray();
        } else {
            try {
                Console console = System.console();
                if (console != null) {
                    password = console.readPassword("Password: ");
                } else {
                    log.info("No console detected for password input.");
                }
            } catch (Throwable t) {
                log.error("Unexpected error while reading password", t);
            }
        }
        if (password == null) {
            log.error("Password is required to post.");
            return 127; // "command not found"
        }
        if (password.length < 6) {
            System.err
                    .println("Password must be at least six characters in length.");
            return 127; // "command not found"
        }

        // obtain keys
        KeyPair signingKeys = null;
        KeyPair encryptionKeys = null;
        String keyPath = commands.getOptionValue("k");

        // if id was not specified from the command line
        if (id == null) {

            // if password was not specified from command line
            if (pass == null) {
                try {
                    // verify password
                    char[] verify = null;
                    Console console = System.console();
                    if (console != null) {
                        verify = console.readPassword("Re-type Password: ");
                    } else {
                        log.info("No console detected for password verification.");
                    }
                    if (verify == null || verify.length != password.length) {
                        System.err.println("Passwords do not match.");
View Full Code Here

   * @param message
   * @return
   */
  public static String readPassword(String message, Scanner input) {
    String password;
    Console console = System.console();
    if (console != null) {
      char[] secretValue = System.console().readPassword(message);
      password = new String(secretValue);
    } else {
      System.out.print(message);
View Full Code Here

      }
    }
  }

  protected void promptUser() {
    Console c = System.console();
    if (c == null) {
      LOG.unableToPromptForMasterUseKnoxCLI();
      System.err.println("No console.");
      System.exit(1);
    }
 
    boolean noMatch;
    do {
        char [] newPassword1 = c.readPassword("Enter master secret: ");
        char [] newPassword2 = c.readPassword("Enter master secret again: ");
        noMatch = ! Arrays.equals(newPassword1, newPassword2);
        if (noMatch) {
            c.format("Passwords don't match. Try again.%n");
        } else {
            this.master = Arrays.copyOf(newPassword1, newPassword1.length);
        }
        Arrays.fill(newPassword1, ' ');
        Arrays.fill(newPassword2, ' ');
View Full Code Here

TOP

Related Classes of java.io.Console$ConsoleWriter

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.