Java Code Examples for java.io.Console#format()

The following examples show how to use java.io.Console#format() . 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: BenchmarkMotifDiscovery.java    From SAX with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

    series = TSProcessor.readFileColumn(TEST_DATA_FNAME, 0, 0);

    Console c = System.console();
    if (c != null) {
      c.format("\nPress ENTER to proceed.\n");
      c.readLine();
    }

    Date start = new Date();
    // motifsBF = BruteForceMotifImplementation.series2BruteForceMotifs(series, MOTIF_SIZE,
    // MOTIF_RANGE, ZNORM_THRESHOLD);
    // System.out.println(motifsBF);

    MotifRecord motifsEMMA = EMMAImplementation.series2EMMAMotifs(series, MOTIF_SIZE, MOTIF_RANGE,
        PAA_SIZE, ALPHABET_SIZE, ZNORM_THRESHOLD);
    Date end = new Date();

    System.out.println(motifsEMMA);

    System.out.println("done in " + SAXProcessor.timeToString(start.getTime(), end.getTime()));
  }
 
Example 2
Source File: KnoxCLI.java    From knox with Apache License 2.0 6 votes vote down vote up
protected char[] promptUserForPassword() {
  char[] password = null;
  Console c = System.console();
  if (c == null) {
    System.err
        .println("No console to fetch password from user.Consider setting via --generate or --value.");
    System.exit(1);
  }

  boolean noMatch;
  do {
    char[] newPassword1 = c.readPassword("Enter password: ");
    char[] newPassword2 = c.readPassword("Enter password again: ");
    noMatch = !Arrays.equals(newPassword1, newPassword2);
    if (noMatch) {
      c.format("Passwords don't match. Try again.%n");
    } else {
      password = Arrays.copyOf(newPassword1, newPassword1.length);
    }
    Arrays.fill(newPassword1, ' ');
    Arrays.fill(newPassword2, ' ');
  } while (noMatch);
  return password;
}
 
Example 3
Source File: PromptUtils.java    From knox with Apache License 2.0 6 votes vote down vote up
public static char[] challengeUserForEstablishingMaterSecret() {
  char[] response = null;
  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 {
          response = Arrays.copyOf(newPassword1, newPassword1.length);
      }
      Arrays.fill(newPassword1, ' ');
      Arrays.fill(newPassword2, ' ');
  } while (noMatch);

  return response;
}
 
Example 4
Source File: CMFMasterService.java    From knox with Apache License 2.0 6 votes vote down vote up
protected void promptUser() {
  Console c = System.console();
  if (c == null) {
    LOG.unableToPromptForMasterUseKnoxCLI();
    System.err.println("No console.");
    System.exit(1);
  }

  boolean valid = false;
  do {
      char [] newPassword1 = c.readPassword("Enter master secret: ");
      char [] newPassword2 = c.readPassword("Enter master secret again: ");
      if ( newPassword1.length == 0 ) {
          c.format("Password too short. Try again.%n");
      } else if (!Arrays.equals(newPassword1, newPassword2) ) {
          c.format("Passwords don't match. Try again.%n");
      } else {
          this.master = Arrays.copyOf(newPassword1, newPassword1.length);
          valid = true;
      }
      Arrays.fill(newPassword1, ' ');
      Arrays.fill(newPassword2, ' ');
  } while (!valid);
}
 
Example 5
Source File: CredentialShell.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public void format(String message) {
  Console console = System.console();
  console.format(message);
}
 
Example 6
Source File: CredentialShell.java    From big-c with Apache License 2.0 4 votes vote down vote up
public void format(String message) {
  Console console = System.console();
  console.format(message);
}