Class PasswordReader.StreamMasker

java.lang.Object
  extended by PasswordReader.StreamMasker
All Implemented Interfaces:
java.lang.Runnable
Enclosing class:
PasswordReader

public static class PasswordReader.StreamMasker
extends java.lang.Object
implements java.lang.Runnable

Masks an InputStream by overwriting blank chars to the PrintStream corresponding to its output. A typical application is for password input masking.

See Also:
My forum posting on password entry, Password masking in console

Constructor Summary
PasswordReader.StreamMasker(java.io.PrintStream out, java.lang.String prompt)
          Constructor.
 
Method Summary
 void run()
          Repeatedly overwrites the current line of out with prompt followed by blanks.
 void stop()
          Signals any thread executing run to stop masking and exit run.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PasswordReader.StreamMasker

public PasswordReader.StreamMasker(java.io.PrintStream out,
                                   java.lang.String prompt)
                            throws java.lang.IllegalArgumentException
Constructor.

Throws:
java.lang.IllegalArgumentException - if out == null; prompt == null; prompt contains the char '\r' or '\n'
Method Detail

run

public void run()
         throws java.lang.RuntimeException
Repeatedly overwrites the current line of out with prompt followed by blanks. This effectively masks any chars coming on out, as long as the masking occurs fast enough.

To help ensure that masking occurs when system is in heavy use, the calling thread will have its priority boosted to the max for the duration of the call (with its original priority restored upon return). Interrupting the calling thread will eventually result in an exit from this method, and the interrupted status of the calling thread will be set to true.

Specified by:
run in interface java.lang.Runnable
Throws:
java.lang.RuntimeException - if an error in the masking process is detected

stop

public void stop()
Signals any thread executing run to stop masking and exit run.