本文整理汇总了Java中java.io.Console类的典型用法代码示例。如果您正苦于以下问题:Java Console类的具体用法?Java Console怎么用?Java Console使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Console类属于java.io包,在下文中一共展示了Console类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userCredentials
import java.io.Console; //导入依赖的package包/类
/**
* ask user for Credentials
*/
private void userCredentials() {
AdvancedEncryptionStandard myEncryption = new AdvancedEncryptionStandard();
Scanner input = new Scanner(System.in, "utf-8");
Console console = System.console();
console.printf("Username: ");
this.username = input.nextLine();
//Password Field is not prompted
console.printf("Password: ");
char[] pass = console.readPassword();
this.decryptPassword = new String(pass);
//ecrypts input user password
this.encryptPassword = myEncryption.encrypt(decryptPassword);
this.password = encryptPassword;
System.out.println();
}
示例2: process
import java.io.Console; //导入依赖的package包/类
/**
* Run through the Smart Content APIs and show usage
*/
public void process() {
SmartContentApi client = new SmartContentClient().getClient();
String input;
Console cmdline = System.console();
if (cmdline == null) {
System.err.println("No console for command line demo.");
System.exit(1);
}
// Find a Smart Data concept
input = cmdline.readLine("Enter text to find concepts, categories or entities: ");
System.out.println(findSmartContentDemo(client, input).toString());
}
示例3: init
import java.io.Console; //导入依赖的package包/类
protected void init(String[] args) {
try {
parser.parseArgument(args);
} catch (CmdLineException e) {
System.err.println(e.getMessage());
parser.printUsage(System.err);
System.exit(1);
}
if (help) {
parser.printUsage(System.err);
System.exit(1);
}
if (!AuthScheme.NO_AUTH.equals(authScheme)) {
if (keyStorePath == null) {
System.err.println("keyStorePath is required when " +
"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);
}
}
}
示例4: main
import java.io.Console; //导入依赖的package包/类
public static void main( String[] args ) {
double d = -19.080808;
System.out.println( "-> " + String.valueOf( d ) );
// string tem 2 caracteres Scandinavos
String scandString = "å, ä, and ö";
// tentando exibir caracteres scandinavos diretamente com println
System.out.println(
"Printing scands directly with println: " + scandString );
// agora com um objeto console
Console console = System.console();
if ( console != null ) {
console.printf(
"Printing scands thro' console's printf method: " + scandString );
}
}
示例5: doConsole
import java.io.Console; //导入依赖的package包/类
private void doConsole() throws Exception
{
Console console = System.console();
if (console != null) // IDE not support
{
String className = console.readLine("> ");
CommandManager commandManager = new CommandManager();
while (commandManager.execute(new CommandFactory().createCommand(className)))
{
console.printf(NEW_LINE);
className = console.readLine("> ");
}
}
}
示例6: main
import java.io.Console; //导入依赖的package包/类
/**
* Main entry point.
*
* @param args The password you wanted to encrypt.
* @throws Exception If an error occurred.
*/
public static void main(String[] args) {
String encryptedVal;
Console console = System.console();
if (console == null) {
System.err.println("Couldn't get Console instance");
System.exit(0);
}
// Get the password used for encryption.
char passwordArray[] = console.readPassword("Please Enter a password you want to use for the encryption: ");
try {
encryptedVal = encrypt(args[0], passwordArray);
Files.write(Paths.get("./encrypted_password.txt"), encryptedVal.getBytes(StandardCharsets.UTF_8));
} catch (EncryptingException | IOException ex) {
System.err.println("Error occurred while encrypting or while writing in to the file ");
ex.printStackTrace();
return;
}
Arrays.fill(passwordArray, (char) 0);
System.out.println("File with encrypted value created successfully in your current location");
}
示例7: init
import java.io.Console; //导入依赖的package包/类
protected void init(String[] args) {
try {
parser.parseArgument(args);
} catch (CmdLineException e) {
System.err.println(e.getMessage());
parser.printUsage(System.err);
System.exit(1);
}
if (help) {
parser.printUsage(System.err);
System.exit(1);
}
if (!AuthScheme.NO_AUTH.equals(authScheme)) {
if (keyStorePath == null) {
System.err.println("keyStorePath is required when " +
"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);
}
}
}
示例8: main
import java.io.Console; //导入依赖的package包/类
public static void main( String[] args ) {
String str = " ";
String[] splited = str.split( " " );
System.out.println( "-> " + splited.length );
Console console = System.console();
/*
* Se a JVM é invocada indiretamente pela IDE, ou se a JVM é invocada a
* partir de um processo de background, então o chamada de método
* System.console () irá falhar e retornar nulo.
*/
if ( console == null ) {
System.out.println(
"Executando app de uma ide... objeto console nao recuperado" );
}
else {
console.printf( console.readLine() );
}
}
示例9: readPasswordFromConsole
import java.io.Console; //导入依赖的package包/类
/**
* Prompts the user for the password on the console
*
* @param user
* the username
*
* @return the password
*
* @throws Exception
*/
private static String readPasswordFromConsole(String user) throws Exception {
Console c = System.console();
String password = "";
if (c == null) {
System.err.println("No console.");
System.out.println(String.format("You are logging in as: " + user + "\n"));
System.out.print(String.format("Enter the password of that user account: "));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
password = br.readLine();
System.out.println("");
}
else {
c.format("You are logging in as: " + user + "\n");
char[] passwordChar = c.readPassword("Enter the password of that user account: ");
password = new String(passwordChar);
System.out.println("");
}
return new String(password);
}
示例10: configureConversion
import java.io.Console; //导入依赖的package包/类
private static DocumentType[] configureConversion(Console console, Map<DocumentType, Set<DocumentType>> supportedConversions) {
console.printf("The connected converter supports the following conversion formats:%n");
Map<Integer, DocumentType[]> conversionsByIndex = new HashMap<Integer, DocumentType[]>();
int index = 0;
for (Map.Entry<DocumentType, Set<DocumentType>> entry : supportedConversions.entrySet()) {
for (DocumentType targetType : entry.getValue()) {
conversionsByIndex.put(index, new DocumentType[]{entry.getKey(), targetType});
console.printf(" | [%d]: '%s' -> '%s'%n", index++, entry.getKey(), targetType);
}
}
do {
console.printf("Enter the number of the conversion you want to perform: ");
try {
int choice = Integer.parseInt(console.readLine());
DocumentType[] conversion = conversionsByIndex.get(choice);
if (conversion != null) {
console.printf("Converting '%s' to '%s'. You can change this setup by entering '\\f'.%n", conversion[0], conversion[1]);
return conversion;
}
console.printf("The number you provided is not among the legal choices%n");
} catch (RuntimeException e) {
console.printf("You did not provide a number%n");
}
} while (true);
}
示例11: main
import java.io.Console; //导入依赖的package包/类
public static void main(String[] args) {
Console console = System.console();
if (console != null) {
String user = new String(console.readLine("Enter User:", new Object[0]));
String pwd = new String(console.readPassword("Enter Password:", new Object[0]));
console.printf("User name is:%s", new Object[] { user });
console.printf("Password is:%s", new Object[] { pwd });
} else {
System.out.println("No Console!");
}
}
示例12: getCredentialFromConsole
import java.io.Console; //导入依赖的package包/类
/**
* @return
*/
private Credential getCredentialFromConsole(Credential credential) {
Console cons = System.console();
if (credential.getUsername() == null) {
LOG.info("Enter your kerberos (or, DB user name if DB is not DACT enabled): ");
credential.setUsername(cons.readLine());
}
if (!credential.isAuthenticationMethodProvided()) {
char[] passwd = cons.readPassword("%s", "Password:");
if (passwd != null) {
credential.setPassword(new String(passwd));
}
}
return credential;
}
示例13: defaultMFATokenSupplier
import java.io.Console; //导入依赖的package包/类
public static Supplier<MFAToken> defaultMFATokenSupplier() {
return () -> {
Console console = System.console();
String token = null;
if (console != null) {
char[] secretValue = console.readPassword("Enter MFA code: ");
if (secretValue != null) {
token = new String(secretValue);
}
} else {
// probably running in an IDE; fallback to plaintext
System.out.print("Enter MFA code: ");
Scanner scanner = new Scanner(System.in);
token = scanner.nextLine();
}
if (token == null || token.isEmpty()) {
throw new InvalidInputException("A non-empty MFA code must be entered");
}
return new MFAToken(token);
};
}
示例14: testPrevNextSnippet
import java.io.Console; //导入依赖的package包/类
public void testPrevNextSnippet() throws Exception {
System.setProperty(ANSI_SUPPORTED_PROPERTY, "true");
Field cons = System.class.getDeclaredField("cons");
cons.setAccessible(true);
Constructor console = Console.class.getDeclaredConstructor();
console.setAccessible(true);
cons.set(null, console.newInstance());
doRunTest((inputSink, out) -> {
inputSink.write("void test1() {\nSystem.err.println(1);\n}\n" + LOC +
"void test2() {\nSystem.err.println(1);\n}\n" + LOC + LOC + LOC + LOC + LOC);
waitOutput(out, "\u001b\\[6nvoid test1\\(\\) \\{\n" +
"\u0006\u001b\\[6nSystem.err.println\\(1\\);\n" +
"\u0006\u001b\\[6n\\}\n" +
"\\| created method test1\\(\\)\n" +
"\u0005\u001b\\[6nvoid test2\\(\\) \\{\n" +
"\u0006\u001b\\[6nSystem.err.println\\(1\\);\n" +
"\u0006\u001b\\[6n\\}\n" +
"\\| created method test2\\(\\)\n" +
"\u0005\u001b\\[6n");
});
}
示例15: main
import java.io.Console; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
Argon2 argon2 = Argon2ArgumentFactory.parseArguments(args);
char[] password;
final Console console = System.console();
if(console != null)
password = console.readPassword();
else{
password = new Scanner(System.in).next().toCharArray();
/* UNSAFE - only for testing purposes
like piping input into argon2 - echo password | java -jar argon2.jar saltsalt
*/
}
argon2.setPassword(password)
.hash();
argon2.printSummary();
}