java.lang.System.console()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(261)

本文整理了Java中java.lang.System.console()方法的一些代码示例,展示了System.console()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.console()方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:console

System.console介绍

[英]Returns the java.io.Console associated with this VM, or null. Not all VMs will have an associated console. A console is typically only available for programs run from the command line.
[中]返回java。木卫一。与此VM关联的控制台,或null。并非所有虚拟机都有关联的控制台。控制台通常仅适用于从命令行运行的程序。

代码示例

代码示例来源:origin: vipshop/vjtools

  1. public InteractiveTask(VJTop app) {
  2. this.app = app;
  3. tty = System.err;
  4. console = System.console();
  5. }

代码示例来源:origin: syncany/syncany

  1. private InitConsole() {
  2. this.console = System.console();
  3. this.systemIn = null;
  4. this.systemOut = null;
  5. }

代码示例来源:origin: jenkinsci/jenkins

  1. public String call() throws IOException {
  2. Console console = System.console();
  3. if (console == null) return null; // no terminal
  4. char[] w = console.readPassword("Password:");
  5. if (w==null) return null;
  6. return new String(w);
  7. }

代码示例来源:origin: jenkinsci/jenkins

  1. private static String askForPasswd(String filePath){
  2. Console cons = System.console();
  3. String passwd = null;
  4. if (cons != null){
  5. char[] p = cons.readPassword("%s", "Enter passphrase for " + filePath + ":");
  6. passwd = String.valueOf(p);
  7. }
  8. return passwd;
  9. }

代码示例来源:origin: neo4j/neo4j

  1. @Override
  2. public char[] promptPassword( String fmt, Object... args )
  3. {
  4. return System.console().readPassword( fmt, args );
  5. }

代码示例来源:origin: neo4j/neo4j

  1. @Override
  2. public String readLine()
  3. {
  4. return System.console().readLine();
  5. }

代码示例来源:origin: neo4j/neo4j

  1. @Override
  2. public String promptLine( String fmt, Object... args )
  3. {
  4. return System.console().readLine( fmt, args );
  5. }

代码示例来源:origin: stackoverflow.com

  1. System.out.print("Enter something:");
  2. String input = System.console().readLine();

代码示例来源:origin: stackoverflow.com

  1. import java.io.Console;
  2. Console console = System.console();
  3. String s = console.readLine();
  4. int i = Integer.parseInt(console.readLine());

代码示例来源:origin: apache/ignite

  1. /** Constructor. */
  2. private GridConsoleAdapter(Console delegate) {
  3. this.delegate = System.console();
  4. if (delegate == null)
  5. throw new NullPointerException("Console is not available.");
  6. }

代码示例来源:origin: org.apache.hadoop/hadoop-common

  1. public char[] readPassword(String prompt) {
  2. Console console = System.console();
  3. char[] pass = console.readPassword(prompt);
  4. return pass;
  5. }

代码示例来源:origin: prestodb/presto

  1. private String getPassword()
  2. {
  3. checkState(clientOptions.user != null, "Username must be specified along with password");
  4. String defaultPassword = System.getenv("PRESTO_PASSWORD");
  5. if (defaultPassword != null) {
  6. return defaultPassword;
  7. }
  8. java.io.Console console = System.console();
  9. if (console == null) {
  10. throw new RuntimeException("No console from which to read password");
  11. }
  12. char[] password = console.readPassword("Password: ");
  13. if (password != null) {
  14. return new String(password);
  15. }
  16. return "";
  17. }

代码示例来源:origin: floragunncom/search-guard

  1. private static String promptForPassword(String passwordName, String commandLineOption, String envVarName) throws Exception {
  2. final Console console = System.console();
  3. if(console == null) {
  4. throw new Exception("Cannot allocate a console. Set env var "+envVarName+" or "+commandLineOption+" on commandline in that case");
  5. }
  6. return new String(console.readPassword("[%s]", passwordName+" password:"));
  7. }

代码示例来源:origin: apache/incubator-gobblin

  1. private static String getPasswordFromConsole() {
  2. System.out.print("Please enter the keystore password: ");
  3. return new String(System.console().readPassword());
  4. }
  5. }

代码示例来源:origin: stackoverflow.com

  1. public class ConsoleDemo {
  2. public static void main(String[] args) {
  3. String[] data = { "\u250C\u2500\u2500\u2500\u2500\u2500\u2510",
  4. "\u2502Hello\u2502",
  5. "\u2514\u2500\u2500\u2500\u2500\u2500\u2518" };
  6. for (String s : data) {
  7. System.out.println(s);
  8. }
  9. for (String s : data) {
  10. System.console().writer().println(s);
  11. }
  12. }
  13. }

代码示例来源:origin: apache/ignite

  1. /** */
  2. public static @Nullable GridConsoleAdapter getInstance() {
  3. Console console = System.console();
  4. return console == null ? null : new GridConsoleAdapter(console);
  5. }

代码示例来源:origin: confluentinc/ksql

  1. private void showWelcomeMessage() {
  2. final Console console = System.console();
  3. if (console == null) {
  4. return;
  5. }
  6. final PrintWriter writer =
  7. new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8));
  8. WelcomeMsgUtils.displayWelcomeMessage(80, writer);
  9. writer.printf("Server %s started with query file %s. Interactive mode is disabled.%n",
  10. Version.getVersion(),
  11. queriesFile);
  12. writer.flush();
  13. }

代码示例来源:origin: neo4j/neo4j

  1. private DiagnosticsReporterProgress buildProgress()
  2. {
  3. DiagnosticsReporterProgress progress;
  4. if ( System.console() != null )
  5. {
  6. progress = new InteractiveProgress( out, verbose );
  7. }
  8. else
  9. {
  10. progress = new NonInteractiveProgress( out, verbose );
  11. }
  12. return progress;
  13. }

代码示例来源:origin: org.apache.logging.log4j/log4j-api

  1. @Test
  2. public void testGetMappedProperty_sun_stdout_encoding() {
  3. final PropertiesUtil pu = new PropertiesUtil(System.getProperties());
  4. Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8;
  5. assertEquals(expected, pu.getCharsetProperty("sun.stdout.encoding"));
  6. }

代码示例来源:origin: org.apache.logging.log4j/log4j-api

  1. @Test
  2. public void testGetMappedProperty_sun_stderr_encoding() {
  3. final PropertiesUtil pu = new PropertiesUtil(System.getProperties());
  4. Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8;
  5. assertEquals(expected, pu.getCharsetProperty("sun.err.encoding"));
  6. }

相关文章