本文整理了Java中java.lang.System.console()
方法的一些代码示例,展示了System.console()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.console()
方法的具体详情如下:
包路径:java.lang.System
类名称: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
public InteractiveTask(VJTop app) {
this.app = app;
tty = System.err;
console = System.console();
}
代码示例来源:origin: syncany/syncany
private InitConsole() {
this.console = System.console();
this.systemIn = null;
this.systemOut = null;
}
代码示例来源:origin: jenkinsci/jenkins
public String call() throws IOException {
Console console = System.console();
if (console == null) return null; // no terminal
char[] w = console.readPassword("Password:");
if (w==null) return null;
return new String(w);
}
代码示例来源:origin: jenkinsci/jenkins
private static String askForPasswd(String filePath){
Console cons = System.console();
String passwd = null;
if (cons != null){
char[] p = cons.readPassword("%s", "Enter passphrase for " + filePath + ":");
passwd = String.valueOf(p);
}
return passwd;
}
代码示例来源:origin: neo4j/neo4j
@Override
public char[] promptPassword( String fmt, Object... args )
{
return System.console().readPassword( fmt, args );
}
代码示例来源:origin: neo4j/neo4j
@Override
public String readLine()
{
return System.console().readLine();
}
代码示例来源:origin: neo4j/neo4j
@Override
public String promptLine( String fmt, Object... args )
{
return System.console().readLine( fmt, args );
}
代码示例来源:origin: stackoverflow.com
System.out.print("Enter something:");
String input = System.console().readLine();
代码示例来源:origin: stackoverflow.com
import java.io.Console;
Console console = System.console();
String s = console.readLine();
int i = Integer.parseInt(console.readLine());
代码示例来源:origin: apache/ignite
/** Constructor. */
private GridConsoleAdapter(Console delegate) {
this.delegate = System.console();
if (delegate == null)
throw new NullPointerException("Console is not available.");
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
public char[] readPassword(String prompt) {
Console console = System.console();
char[] pass = console.readPassword(prompt);
return pass;
}
代码示例来源:origin: prestodb/presto
private String getPassword()
{
checkState(clientOptions.user != null, "Username must be specified along with password");
String defaultPassword = System.getenv("PRESTO_PASSWORD");
if (defaultPassword != null) {
return defaultPassword;
}
java.io.Console console = System.console();
if (console == null) {
throw new RuntimeException("No console from which to read password");
}
char[] password = console.readPassword("Password: ");
if (password != null) {
return new String(password);
}
return "";
}
代码示例来源:origin: floragunncom/search-guard
private static String promptForPassword(String passwordName, String commandLineOption, String envVarName) throws Exception {
final Console console = System.console();
if(console == null) {
throw new Exception("Cannot allocate a console. Set env var "+envVarName+" or "+commandLineOption+" on commandline in that case");
}
return new String(console.readPassword("[%s]", passwordName+" password:"));
}
代码示例来源:origin: apache/incubator-gobblin
private static String getPasswordFromConsole() {
System.out.print("Please enter the keystore password: ");
return new String(System.console().readPassword());
}
}
代码示例来源:origin: stackoverflow.com
public class ConsoleDemo {
public static void main(String[] args) {
String[] data = { "\u250C\u2500\u2500\u2500\u2500\u2500\u2510",
"\u2502Hello\u2502",
"\u2514\u2500\u2500\u2500\u2500\u2500\u2518" };
for (String s : data) {
System.out.println(s);
}
for (String s : data) {
System.console().writer().println(s);
}
}
}
代码示例来源:origin: apache/ignite
/** */
public static @Nullable GridConsoleAdapter getInstance() {
Console console = System.console();
return console == null ? null : new GridConsoleAdapter(console);
}
代码示例来源:origin: confluentinc/ksql
private void showWelcomeMessage() {
final Console console = System.console();
if (console == null) {
return;
}
final PrintWriter writer =
new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8));
WelcomeMsgUtils.displayWelcomeMessage(80, writer);
writer.printf("Server %s started with query file %s. Interactive mode is disabled.%n",
Version.getVersion(),
queriesFile);
writer.flush();
}
代码示例来源:origin: neo4j/neo4j
private DiagnosticsReporterProgress buildProgress()
{
DiagnosticsReporterProgress progress;
if ( System.console() != null )
{
progress = new InteractiveProgress( out, verbose );
}
else
{
progress = new NonInteractiveProgress( out, verbose );
}
return progress;
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testGetMappedProperty_sun_stdout_encoding() {
final PropertiesUtil pu = new PropertiesUtil(System.getProperties());
Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8;
assertEquals(expected, pu.getCharsetProperty("sun.stdout.encoding"));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void testGetMappedProperty_sun_stderr_encoding() {
final PropertiesUtil pu = new PropertiesUtil(System.getProperties());
Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8;
assertEquals(expected, pu.getCharsetProperty("sun.err.encoding"));
}
内容来源于网络,如有侵权,请联系作者删除!