Package java.io

Examples of java.io.Console$ConsoleWriter


    /**
     * 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 (IllegalArgumentException 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

                    }
                    if (!deleteConfigFile()) {
                        handleException("Error deleting Password config File");
                    }
                } else {
                    Console console;
                    char[] password;
                    if(sameKeyAndKeyStorePass){
                        if ((console = System.console()) != null && (password = console.readPassword("[%s]",
                                        "Enter KeyStore and Private Key Password :")) != null) {
                            keyStorePassWord = String.valueOf(password);
                            privateKeyPassWord= keyStorePassWord;
                        }
                    } else {
                        if ((console = System.console()) != null &&
                            (password = console.readPassword("[%s]",
                                                        "Enter KeyStore Password :")) != null) {
                            keyStorePassWord = String.valueOf(password);
                        }
                        if ((console = System.console()) != null &&
                            (password = console.readPassword("[%s]",
                                                        "Enter Private Key Password : ")) != null) {
                            privateKeyPassWord = String.valueOf(password);
                        }
                    }
                }
View Full Code Here

     */
    private static void createEncryptedValue(){

        log.info("By default, CipherTool can be used for creating encrypted value for given plain text." +
                 " For more options visit help  ./ciphertool.sh -help or ./ciphertool.bat -help\n");
        Console console;
        char[] password;
        String firstPassword = null;
        String secondPassword = null;
        if ((console = System.console()) != null &&
            (password = console.readPassword("[%s]",
                                        "Enter Plain text value :")) != null) {
            firstPassword = String.valueOf(password);
        }

        if ((console = System.console()) != null &&
            (password = console.readPassword("[%s]",
                                        "Please Enter value Again :")) != null) {
            secondPassword = String.valueOf(password);
        }

        if(firstPassword != null && secondPassword != null && !firstPassword.equals("")
View Full Code Here

     * @param key secure alias of password
     * @return  Password
     */
    private static String passwordReader(String key){

        Console console;
        char[] password;
        String firstPassword = null;
        String secondPassword = null;
        if ((console = System.console()) != null &&
            (password = console.readPassword("[%s]",
                                        "Enter Password of Secret Alias - '" + key + "' :")) != null) {
            firstPassword = String.valueOf(password);
        }

        if ((console = System.console()) != null &&
            (password = console.readPassword("[%s]",
                                        "Please Enter Password Again :")) != null) {
            secondPassword = String.valueOf(password);
        }

        if(firstPassword != null && secondPassword != null && !firstPassword.equals("")
View Full Code Here

    /**
     * Read primary key store password of carbon sever from command-line
     * @return password
     */
    protected static String carbonKeyPasswordReader() {
        Console console;
        char[] password;
        if ((console = System.console()) != null &&
            (password = console.readPassword("[%s]",
                            "Please Enter Primary KeyStore Password of Carbon Server : ")) != null) {
            return String.valueOf(password);
        }
        return null;
    }
View Full Code Here

     * @return a lehetseges valaszok közül a kivalasztott
     * @throws IOException a hibakezelés miatt
     */
    public int Ask(String question, Vector<String> choices_list) throws IOException {
        int choice_id = 0;
        Console konzol = System.console();
        if (konzol == null) {
            System.err.println("No console.");
            System.exit(1);
        }

        String valasz = new String();
        System.out.println(question);
        System.out.print("(");
        for(int i=0; i<choices_list.size(); i++) {
            System.out.print(choices_list.elementAt(i));
            if(i!=choices_list.size()-1)
                System.out.print("/");
        }
        System.out.print(")");
        while(true) {
            valasz = konzol.readLine();
            if(choices_list.contains(valasz)) {
                choice_id = choices_list.indexOf(valasz);
                break;
            }
            else
View Full Code Here

//            System.out.println("\tERROR:\t called_method_names vector empty, misuse detected...");
//    }

    public int Ask(String question, Vector<String> choices_list) throws IOException {
        int choice_id = 0;
        Console konzol = System.console();
        if (konzol == null) {
            System.err.println("No console.");
            System.exit(1);
        }

        String valasz = new String();
        System.out.println(question);
        System.out.print("(");
        for(int i=0; i<choices_list.size(); i++) {
            System.out.print(choices_list.elementAt(i));
            if(i!=choices_list.size()-1)
                System.out.print("/");
        }
        System.out.print(")");
        while(true) {
            valasz = konzol.readLine();
            if(choices_list.contains(valasz)) {
                choice_id = choices_list.indexOf(valasz);
                break;
            }
            else
View Full Code Here

TOP

Related Classes of java.io.Console$ConsoleWriter

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.