Package java.io

Examples of java.io.Console$ConsoleReader


        this.vault = vault;
        this.handshakeKey = handshakeKey;
    }

    public void start() {
        Console console = System.console();

        if (console == null) {
            System.err.println("No console.");
            System.exit(1);
        }

        Scanner in = new Scanner(System.in);
        while (true) {
            String commandStr = "Please enter a Digit::   0: Store a password " + " 1: Check whether password exists "
                    + " 2: Exit";

            System.out.println(commandStr);
            int choice = in.nextInt();
            switch (choice) {
                case 0:
                    System.out.println("Task:  Store a password");
                    char[] attributeValue = VaultInteractiveSession.getSensitiveValue("Please enter attribute value");
                    String vaultBlock = null;

                    while (vaultBlock == null || vaultBlock.length() == 0) {
                        vaultBlock = console.readLine("Enter Vault Block:");
                    }

                    String attributeName = null;

                    while (attributeName == null || attributeName.length() == 0) {
                        attributeName = console.readLine("Enter Attribute Name:");
                    }
                    try {
                        vault.store(vaultBlock, attributeName, attributeValue, handshakeKey);

                        String keyAsString = new String(handshakeKey);
                        System.out.println("Attribute Value for (" + vaultBlock + ", " + attributeName + ") saved");

                        System.out.println("                ");
                        System.out.println("Please make note of the following:");
                        System.out.println("********************************************");
                        System.out.println("Vault Block:" + vaultBlock);
                        System.out.println("Attribute Name:" + attributeName);
                        System.out.println("Shared Key:" + keyAsString);
                        System.out.println("Configuration should be done as follows:");
                        System.out.println("VAULT::" + vaultBlock + "::" + attributeName + "::" + keyAsString);
                        System.out.println("********************************************");
                        System.out.println("                ");
                    } catch (SecurityVaultException e) {
                        System.out.println("Exception occurred:" + e.getLocalizedMessage());
                    }
                    break;
                case 1:
                    System.out.println("Task: Verify whether a password exists");
                    try {
                        vaultBlock = null;

                        while (vaultBlock == null || vaultBlock.length() == 0) {
                            vaultBlock = console.readLine("Enter Vault Block:");
                        }

                        attributeName = null;

                        while (attributeName == null || attributeName.length() == 0) {
                            attributeName = console.readLine("Enter Attribute Name:");
                        }
                        if (vault.exists(vaultBlock, attributeName) == false)
                            System.out.println("No value has been store for (" + vaultBlock + ", " + attributeName + ")");
                        else
                            System.out.println("A value exists for (" + vaultBlock + ", " + attributeName + ")");
View Full Code Here


    public static void main(String[] args) throws IOException {
        System.out.println("Welcome to the coding console!");
        MasterPasswordStore.readFromConsole();
        ConfigurationValueCoder valueCoder = new ConfigurationValueCoder();

        Console console = System.console();
        while (true) {
            System.out.println("1. encode values");
            System.out.println("2. decode values");
            System.out.println("3. exit");
            String choice = console.readLine();
            if ("1".equals(choice)) {
                String text = console.readLine("Text: ");
                System.out.println(valueCoder.encode(text));
            } else if ("2".equals(choice)) {
                String text = console.readLine("Text: ");
                System.out.println(valueCoder.decode(text));
            } if ("3".equals(choice)) {
                return;
            }
        }
View Full Code Here

    /**
     * Writes the given object to the console using a shared instance of {@code ParameterFormat}.
     */
    static void print(final Object object) {
        final Console console = System.console();
        final Appendable out = (console != null) ? console.writer() : System.out;
        final ParameterFormat f = getSharedInstance(Colors.NAMING);
        try {
            f.format(object, out);
        } catch (IOException e) {
            throw new AssertionError(e); // Should never happen, since we are writing to stdout.
View Full Code Here

     *
     * <p>This is a convenience method for debugging purpose and for console applications.</p>
     */
    @Debug
    public void print() {
        final Console console = System.console();
        final PrintWriter out = (console != null) ? console.writer() : null;
        final String wkt = formatWKT(Convention.WKT2_SIMPLIFIED, (out != null) && X364.isAnsiSupported(), false);
        if (out != null) {
            out.println(wkt);
        } else {
            System.out.println(wkt);
View Full Code Here

     * @throws IOException
     * @return true if the user trusts the certificate
     */   
    private boolean isItOKToAddCertToTrustStore(X509Certificate c)
                                throws IOException {                    
        Console cons = System.console();
        if (!interactive || cons == null) {
            return true;
        }
       
        cons.printf("%s%n", c.toString());
        String result =
            cons.readLine("%s", strmgr.get("certificateTrustPrompt"));
        return result != null && result.equalsIgnoreCase("y");
    }
View Full Code Here

     * In such case, we will send the XML output to an {@code OutputStream} instead than to a
     * {@code Writer} and let the marshaller apply the encoding itself.
     */
    private boolean isConsole() {
        if (outputBuffer != null) return true; // Special case for JUnit tests only.
        final Console console = System.console();
        return (console != null) && console.writer() == out;
    }
View Full Code Here

    /**
     * Prints the message of the given exception. This method is invoked only when the error occurred before
     * the {@link SubCommand} has been built, otherwise the {@link SubCommand#err} printer shall be used.
     */
    private static void error(final Exception e) {
        final Console console = System.console();
        if (console != null) {
            final PrintWriter err = console.writer();
            err.println(e.getLocalizedMessage());
            err.flush();
        } else {
            final PrintStream err = System.err;
            err.println(e.getLocalizedMessage());
View Full Code Here

        /*
         * Process the --locale, --encoding and --colors options.
         */
        Option option = null; // In case of IllegalArgumentException.
        String value  = null;
        final Console console;
        final boolean explicitEncoding;
        try {
            value = options.get(option = Option.LOCALE);
            locale = (value != null) ? Locales.parse(value) : Locale.getDefault();

            value = options.get(option = Option.TIMEZONE);
            timezone = (value != null) ? TimeZone.getTimeZone(value) : TimeZone.getDefault();

            value = options.get(option = Option.ENCODING);
            explicitEncoding = (value != null);
            encoding = explicitEncoding ? Charset.forName(value) : Charset.defaultCharset();

            value = options.get(option = Option.COLORS);
            console = System.console();
            colors = (value != null) ? Option.COLORS.parseBoolean(value) : (console != null) && X364.isAnsiSupported();
        } catch (RuntimeException e) {
            final String name = option.name().toLowerCase(Locale.US);
            throw new InvalidOptionException(Errors.format(Errors.Keys.IllegalOptionValue_2, name, value), name);
        }
        /*
         * Creates the writers. If this sub-command is created for JUnit test purpose, then we will send the
         * output to a StringBuffer. Otherwise the output will be sent to the java.io.Console if possible,
         * or to the standard output stream otherwise.
         */
        if (isTest) {
            final StringWriter s = new StringWriter();
            outputBuffer = s.getBuffer();
            out = new PrintWriter(s);
            err = out;
        } else {
            outputBuffer = null;
            err = (console != null) ? console.writer() : new PrintWriter(System.err, true);
            if (!explicitEncoding && console != null) {
                out = console.writer();
            } else {
                if (explicitEncoding) {
                    out = new PrintWriter(new OutputStreamWriter(System.out, encoding), true);
                } else {
                    out = new PrintWriter(System.out, true);
View Full Code Here

             * Get the output writer, using the specified encoding if any.
             */
            PrintWriter writer = null;
            final String encoding = System.getProperty(OUTPUT_ENCODING_KEY);
            if (encoding == null) {
                final Console console = System.console();
                if (console != null) {
                    writer = console.writer();
                }
            }
            if (writer == null) {
                if (encoding != null) try {
                    writer = new PrintWriter(new OutputStreamWriter(System.out, encoding));
View Full Code Here

        {
            String passwd = cliRequest.commandLine.getOptionValue( CLIManager.ENCRYPT_MASTER_PASSWORD );
           
            if ( passwd == null )
            {
                Console cons;
                char[] password;
                if ( ( cons = System.console() ) != null
                    && ( password = cons.readPassword( "Master password: " ) ) != null )
                {
                    // Cipher uses Strings
                    passwd = String.copyValueOf( password );
                   
                    // Sun/Oracle advises to empty the char array
                    java.util.Arrays.fill( password, ' ' );
                }
            }

            DefaultPlexusCipher cipher = new DefaultPlexusCipher();

            System.out.println( cipher.encryptAndDecorate( passwd, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ) );

            throw new ExitException( 0 );
        }
        else if ( cliRequest.commandLine.hasOption( CLIManager.ENCRYPT_PASSWORD ) )
        {
            String passwd = cliRequest.commandLine.getOptionValue( CLIManager.ENCRYPT_PASSWORD );
           
            if ( passwd == null )
            {
                Console cons;
                char[] password;
                if ( ( cons = System.console() ) != null
                    && ( password = cons.readPassword( "Password: " ) ) != null )
                {
                    // Cipher uses Strings
                    passwd = String.copyValueOf( password );

                    // Sun/Oracle advises to empty the char array
View Full Code Here

TOP

Related Classes of java.io.Console$ConsoleReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.