List of usage examples for java.lang System console
public static Console console()
From source file:org.apache.atlas.utils.AuthenticationUtil.java
public static String[] getBasicAuthenticationInput() { String username = null;//from www . ja va2s.c om String password = null; try { Console console = System.console(); username = console.readLine("Enter username for atlas :- "); char[] pwdChar = console.readPassword("Enter password for atlas :- "); if (pwdChar != null) { password = new String(pwdChar); } } catch (Exception e) { System.out.print("Error while reading "); System.exit(1); } return new String[] { username, password }; }
From source file:org.apache.commons.net.examples.mail.Utils.java
/** * If the initial password is:/* w ww . j a v a2 s. c o m*/ * '*' - replace it with a line read from the system console * '-' - replace it with next line from STDIN * 'ABCD' - if the input is all upper case, use the field as an environment variable name * * Note: there are no guarantees that the password cannot be snooped. * * Even using the console may be subject to memory snooping, * however it should be safer than the other methods. * * STDIN may require creating a temporary file which could be read by others * Environment variables may be visible by using PS */ static String getPassword(String username, String password) throws IOException { if ("-".equals(password)) { // stdin BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); password = in.readLine(); } else if ("*".equals(password)) { // console Console con = System.console(); // Java 1.6 if (con != null) { char[] pwd = con.readPassword("Password for " + username + ": "); password = new String(pwd); } else { throw new IOException("Cannot access Console"); } } else if (password.equals(password.toUpperCase(Locale.ROOT))) { // environment variable name final String tmp = System.getenv(password); if (tmp != null) { // don't overwrite if variable does not exist (just in case password is all uppers) password = tmp; } } return password; }
From source file:com.playonlinux.ui.impl.cli.AbstractCLIStep.java
public final void display() { printMessage();/*from w w w. j a v a 2s .com*/ System.out.println("\n"); String input; if (defineDefaultValue() == null) { input = System.console() .readLine(String.format("< %s [%s] > ", defineInputMessage(), defineDefaultValue())); if (StringUtils.isBlank(input)) { input = defineDefaultValue(); } } else { input = System.console().readLine(String.format("< %s >", defineInputMessage())); } }
From source file:net.minder.KnoxWebHdfsJavaClientExamplesTest.java
@BeforeClass public static void setupSuite() { Console console = System.console(); if (console != null) { console.printf("Knox Host: "); KNOX_HOST = console.readLine();/*from ww w .j ava2 s. c o m*/ console.printf("Topology : "); TOPOLOGY_PATH = console.readLine(); console.printf("Username : "); TEST_USERNAME = console.readLine(); console.printf("Password: "); TEST_PASSWORD = new String(console.readPassword()); } else { JLabel label = new JLabel("Enter Knox host, topology, username, password:"); JTextField host = new JTextField(KNOX_HOST); JTextField topology = new JTextField(TOPOLOGY_PATH); JTextField username = new JTextField(TEST_USERNAME); JPasswordField password = new JPasswordField(TEST_PASSWORD); int choice = JOptionPane.showConfirmDialog(null, new Object[] { label, host, topology, username, password }, "Credentials", JOptionPane.OK_CANCEL_OPTION); assertThat(choice, is(JOptionPane.YES_OPTION)); TEST_USERNAME = username.getText(); TEST_PASSWORD = new String(password.getPassword()); KNOX_HOST = host.getText(); TOPOLOGY_PATH = topology.getText(); } TOPOLOGY_URL = String.format("%s://%s:%d/%s/%s", KNOX_SCHEME, KNOX_HOST, KNOX_PORT, KNOX_PATH, TOPOLOGY_PATH); WEBHDFS_URL = String.format("%s/%s", TOPOLOGY_URL, WEBHDFS_PATH); }
From source file:org.openanzo.client.cli.DefaultConsole.java
public DefaultConsole() { try {//from w w w . java 2 s. c o m if (System.console() != null) { cr = new ConsoleReader(); cr.setBellEnabled(true); } } catch (IOException ioe) { } }
From source file:com.gs.obevo.util.inputreader.ConsoleInputReader.java
private Console getConsole(String readType) { Console console = System.console(); if (console == null) { throw new IllegalStateException("Attempting to fetch System.console() to read in [" + readType + "], but the System.console() is not available in your environment. Try entering in your login via the input arguments or use the -noPrompt argument"); }/* w w w . j a v a 2 s . com*/ return console; }
From source file:org.xlrnet.tibaija.Application.java
private static VirtualCalculator getDefaultCalculator(CodeProvider codeProvider) throws IOException { Reader reader;//from w ww. j a v a2s . com Writer writer; if (System.console() != null) { Console console = System.console(); reader = console.reader(); writer = console.writer(); LOGGER.debug("Initialised native system console"); } else { reader = new InputStreamReader(System.in); writer = new OutputStreamWriter(System.out); LOGGER.debug("Initialised system I/O streams"); } CalculatorIO io = new ConsoleIO(reader, writer); CalculatorMemory memory = new DefaultCalculatorMemory(); HomeScreen homeScreen = new NullHomeScreen(); FontRegistry fontRegistry = new FontRegistry(); fontRegistry.registerFont(Paths.get("largeFont.json"), FontConstants.FONT_LARGE); fontRegistry.registerFont(Paths.get("smallFont.json"), FontConstants.FONT_SMALL); ExecutionEnvironment.newEnvironment(memory, io, codeProvider, homeScreen, fontRegistry); return new TI83Plus(memory, io, codeProvider); }
From source file:ch.cyberduck.cli.Console.java
public Console() { switch (Factory.Platform.getDefault()) { case windows: console = null;/*from w w w.j ava2 s.c o m*/ break; default: console = System.console(); break; } }
From source file:com.jwm123.loggly.reporter.Configuration.java
public void update() throws Exception { Console console = System.console(); do {//from www. j a va 2s.c o m username = console.readLine("Username: "); } while (StringUtils.isBlank(username)); do { password = new String(console.readPassword("Password: ")); } while (StringUtils.isBlank(password)); do { account = console.readLine("Loggly Account: "); } while (StringUtils.isBlank(account)); mailServer = console.readLine("Mail Server: "); mailFrom = console.readLine("Mail From: "); String mailPortStr = console.readLine("Mail Port [25]: "); if (StringUtils.isBlank(mailPortStr) || !mailPortStr.matches("\\d*")) { mailPort = 25; } else { mailPort = new Integer(mailPortStr); } if (StringUtils.isNotBlank(mailServer)) { mailUsername = console.readLine("Mail Username: "); if (StringUtils.isNotBlank(mailUsername)) { mailPassword = new String(console.readPassword("Mail Password: ")); } } writeOut(); }
From source file:kellinwood.zipsigner.cmdline.Main.java
static char[] readPassword(String prompt) { System.out.print(prompt + ": "); System.out.flush();/*www . ja v a 2 s. co m*/ return System.console().readPassword(); }