* commit 'cd9545a499a1124a52e4edf962c53b83f23ebae8': If a console doesn't exist, read password from stdin.
This commit is contained in:
commit
6129c60a35
1 changed files with 16 additions and 5 deletions
|
@ -167,18 +167,29 @@ class SignApk {
|
|||
}
|
||||
|
||||
/**
|
||||
* Reads the password from console and returns it as a string.
|
||||
* If a console doesn't exist, reads the password from stdin
|
||||
* If a console exists, reads the password from console and returns it as a string.
|
||||
*
|
||||
* @param keyFile The file containing the private key. Used to prompt the user.
|
||||
*/
|
||||
private static String readPassword(File keyFile) {
|
||||
Console console;
|
||||
char[] pwd;
|
||||
if((console = System.console()) != null &&
|
||||
(pwd = console.readPassword("[%s]", "Enter password for " + keyFile)) != null){
|
||||
return String.valueOf(pwd);
|
||||
if ((console = System.console()) == null) {
|
||||
System.out.print("Enter password for " + keyFile + " (password will not be hidden): ");
|
||||
System.out.flush();
|
||||
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
|
||||
try {
|
||||
return stdin.readLine();
|
||||
} catch (IOException ex) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
if ((pwd = console.readPassword("[%s]", "Enter password for " + keyFile)) != null) {
|
||||
return String.valueOf(pwd);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue