| 6 | import java.lang.reflect.Method; |
| 7 | |
| 8 | public class JDK6Console implements Console { |
| 9 | |
| 10 | private Object console; |
| 11 | |
| 12 | private PrintWriter writer; |
| 13 | |
| 14 | public JDK6Console(Object console) throws Exception { |
| 15 | this.console = console; |
| 16 | Method writerMethod = console.getClass().getDeclaredMethod("writer"); |
| 17 | writer = (PrintWriter) writerMethod.invoke(console); |
| 18 | } |
| 19 | |
| 20 | public void print(CharSequence msg) { |
| 21 | writer.print(msg); |
| 22 | } |
| 23 | |
| 24 | public void println(CharSequence msg) { |
| 25 | writer.println(msg); |
| 26 | } |
| 27 | |
| 28 | public char[] readPassword(boolean echoInput) { |
| 29 | try { |
| 30 | writer.flush(); |
| 31 | Method method; |
| 32 | if (echoInput) { |
| 33 | method = console.getClass().getDeclaredMethod("readLine"); |
| 34 | return ((String) method.invoke(console)).toCharArray(); |
| 35 | } else { |
| 36 | method = console.getClass().getDeclaredMethod("readPassword"); |
| 37 | return (char[]) method.invoke(console); |
| 38 | } |
| 39 | } |
| 40 | catch (Exception e) { |
| 41 | throw new ParameterException(e); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…