当前位置: 首页>>代码示例>>Java>>正文


Java Console类代码示例

本文整理汇总了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();
}
 
开发者ID:GrigorisParaskevakos,项目名称:BankAccount_PasaskevakosG_BootCamp3,代码行数:20,代码来源:LoginScreen.java

示例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());
}
 
开发者ID:DataNinjaAPI,项目名称:dataninja-smartcontent-api-sdk-java,代码行数:19,代码来源:SmartContentDemo.java

示例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);
        }
    }
}
 
开发者ID:zhenshengcai,项目名称:floodlight-hardware,代码行数:27,代码来源:AuthTool.java

示例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 );
        }
    }
 
开发者ID:juliocnsouzadev,项目名称:ocpjp,代码行数:17,代码来源:SpecialCharHandling.java

示例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("> ");
        }
    }
}
 
开发者ID:geekflow,项目名称:light,代码行数:19,代码来源:Main.java

示例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");
}
 
开发者ID:wso2-extensions,项目名称:identity-agent-sso,代码行数:29,代码来源:Encryption.java

示例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);
        }
    }
}
 
开发者ID:sammyyx,项目名称:ACAMPController,代码行数:27,代码来源:AuthTool.java

示例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() );
    }
}
 
开发者ID:juliocnsouzadev,项目名称:ocpjp,代码行数:20,代码来源:Echo.java

示例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);
}
 
开发者ID:hpclab,项目名称:TheMatrixProject,代码行数:33,代码来源:IadCreator.java

示例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);
}
 
开发者ID:documents4j,项目名称:documents4j,代码行数:26,代码来源:StandaloneClient.java

示例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!");
	}
}
 
开发者ID:leon66666,项目名称:JavaCommon,代码行数:12,代码来源:ConsoleDemo.java

示例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;
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:20,代码来源:CredentialReader.java

示例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);
    };
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:25,代码来源:MFAToken.java

示例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");
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:PasteAndMeasurementsUITest.java

示例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();
    }
 
开发者ID:andreas1327250,项目名称:argon2-java,代码行数:21,代码来源:Main.java


注:本文中的java.io.Console类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。