Java 类com.beust.jcommander.internal.Console 实例源码

项目:stampede    文件:Main.java   
private static String readPwd() throws IOException {
  Console console = JCommander.getConsole();
  if (System.console() == null) { // In Eclipse IDE
    InputStream in = System.in;
    int max = 50;
    byte[] bytes = new byte[max];

    int length = in.read(bytes);
    length--;// last character is \n
    if (length > 0) {
      byte[] newBytes = new byte[length];
      System.arraycopy(bytes, 0, newBytes, 0, length);
      return new String(newBytes, Charsets.UTF_8);
    } else {
      return null;
    }
  } else { // Outside Eclipse IDE
    return new String(console.readPassword(false));
  }
}