| 170 | |
| 171 | // ================================================================== |
| 172 | private static String getLine(String p, boolean b) { |
| 173 | String response; |
| 174 | |
| 175 | if (c != null) { |
| 176 | // Standard console mode |
| 177 | if (b) { |
| 178 | response = new String(c.readPassword(p)); |
| 179 | } else |
| 180 | response = c.readLine(p); |
| 181 | |
| 182 | } else { |
| 183 | // For instance when testing from Eclipse |
| 184 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); |
| 185 | |
| 186 | System.out.print(p); |
| 187 | |
| 188 | try { |
| 189 | // Cannot suppress echo for password entry |
| 190 | response = in.readLine(); |
| 191 | } catch (IOException e) { |
| 192 | response = ""; |
| 193 | } // end of try/catch |
| 194 | |
| 195 | } // endif c |
| 196 | |
| 197 | return (response.isEmpty()) ? null : response; |
| 198 | } // end of getLine |
| 199 | |
| 200 | } // end of class Client |