View Javadoc

1   /*
2    * Copyright (c) 2002-2007, Marc Prud'hommeaux. All rights reserved.
3    *
4    * This software is distributable under the BSD license. See the terms of the
5    * BSD license in the documentation provided with this software.
6    */
7   package jline.example;
8   
9   import jline.*;
10  
11  import java.io.*;
12  
13  public class PasswordReader {
14      public static void usage() {
15          System.out.println("Usage: java "
16              + PasswordReader.class.getName() + " [mask]");
17      }
18  
19      public static void main(String[] args) throws IOException {
20          ConsoleReader reader = new ConsoleReader();
21  
22          Character mask = (args.length == 0)
23              ? new Character((char) 0)
24              : new Character(args[0].charAt(0));
25  
26          String line = null;
27          do {
28              line = reader.readLine("enter password> ", mask);
29              System.out.println("Got password: " + line);
30          } while(line != null && line.length() > 0);
31      }
32  }