FileDocCategorySizeDatePackage
CommandUtil.javaAPI DocGlassfish v2 API4688Fri May 04 22:25:08 BST 2007com.sun.enterprise.cli.commands

CommandUtil

public class CommandUtil extends Object
This class contains useful api used for the commands module. These methods are: getPassword() - this method prompts the user for a password and attempts to mask inputs with "".
version
$Revision: 1.4 $

Fields Summary
Constructors Summary
Methods Summary
public java.lang.StringgetPassword(java.lang.String prompt)
This method prompts the user to enter the password and attempts to mask inputs with "".

param
prompt - prompt to display on the output device.

	//password holder
	String password = "";
	final MaskingThread maskingThread = new MaskingThread(prompt);
	final Thread thread = new Thread(maskingThread);
	thread.start();
	//block until enter is pressed;
	while (true)
	{
	    char ch = (char)InputsAndOutputs.getInstance().getUserInput().getChar();
	    //char ch = (char)System.in.read();

	    //assume enter pressed, stop masking
	    maskingThread.stopMasking();

	    if (ch == '\r") break;
	    else if (ch == '\n") break;
	    else
            {
		//store the password
		password += ch;
	    }
	}
	InputsAndOutputs.getInstance().getUserOutput().println("");
	return password;
    
public static voidmain(java.lang.String[] argv)

	CommandUtil passfield = new CommandUtil();
	String password = null;
	try 
	{
	    password = passfield.getPassword("Enter your password: " );
	}
	catch (IOException ioe)
	{
	    ioe.printStackTrace();
	}
	System.out.println("The password entered is " + password);