- /**
- * Ask boolean value from user on command-line.
- */
- public static boolean askBoolean(final String prompt) {
-
- final BufferedReader br = new BufferedReader(new InputStreamReader(
- System.in));
-
- while (true)
- try {
- System.out.print(prompt);
-
- final String userInput = br.readLine().toLowerCase();
-
- if ("y".equals(userInput) || "yes".equals(userInput)
- || "true".equals(userInput))
- return true;
-
- if ("n".equals(userInput) || "no".equals(userInput)
- || "false".equals(userInput))
- return false;
-
- System.out
- .println("Invalid input. You shall enter y/yes/true or n/no/false.");
- } catch (final IOException ioe) {
- ioe.printStackTrace();
- }
- }
-
- /**
- * Ask numerical long value from user on command-line.
- */
- public static long askLong(final String prompt) {
-
- final BufferedReader br = new BufferedReader(new InputStreamReader(
- System.in));
-
- while (true) {
- System.out.print(prompt);
-
- try {
- final String userInput = br.readLine();
-
- try {
- final long result = Long.parseLong(userInput);
- return result;
- } catch (final NumberFormatException e) {
- System.out.println("\nError: You shall enter an integer.");
- }
- } catch (final IOException ioe) {
- ioe.printStackTrace();
- }
-
- }
- }
-
- /**
- * Ask string value from user on command-line.
- */
- public static String askString(final String prompt) {
-
- final BufferedReader br = new BufferedReader(new InputStreamReader(
- System.in));
-
- while (true) {
- System.out.print(prompt);
-
- try {
- final String userInput = br.readLine();
-
- return userInput;
- } catch (final IOException ioe) {
- ioe.printStackTrace();
- }
-
- }
- }
+ /**
+ * Ask boolean value from user on command-line.
+ *
+ * @param prompt to show to the user
+ * @return <code>true</code> is user answered affirmative.
+ */
+ public static boolean askBoolean(final String prompt) {
+
+ final BufferedReader br = new BufferedReader(new InputStreamReader(
+ System.in));
+
+ while (true)
+ try {
+ System.out.print(prompt);
+
+ String line = br.readLine();
+ if (line != null) {
+ final String userInput = line.toLowerCase();
+
+ if ("y".equals(userInput) || "yes".equals(userInput)
+ || "true".equals(userInput))
+ return true;
+
+ if ("n".equals(userInput) || "no".equals(userInput)
+ || "false".equals(userInput))
+ return false;
+ }
+ System.out
+ .println("Invalid input. You shall enter y/yes/true or n/no/false.");
+ } catch (final IOException ioe) {
+ ioe.printStackTrace();
+ }
+ }
+
+ /**
+ * Ask numerical long value from user on command-line.
+ *
+ * @param prompt to show to the user
+ * @return value given by user
+ */
+ public static long askLong(final String prompt) {
+
+ final BufferedReader br = new BufferedReader(new InputStreamReader(
+ System.in));
+
+ while (true) {
+ System.out.print(prompt);
+
+ try {
+ final String userInput = br.readLine();
+
+ try {
+ return Long.parseLong(userInput);
+ } catch (final NumberFormatException e) {
+ System.out.println("\nError: You shall enter an integer.");
+ }
+ } catch (final IOException ioe) {
+ ioe.printStackTrace();
+ }
+
+ }
+ }
+
+ /**
+ * Ask string value from user on command-line.
+ *
+ * @param prompt to show to the user
+ * @return value given by the user
+ */
+ public static String askString(final String prompt) {
+
+ final BufferedReader br = new BufferedReader(new InputStreamReader(
+ System.in));
+
+ while (true) {
+ System.out.print(prompt);
+
+ try {
+ return br.readLine();
+ } catch (final IOException ioe) {
+ ioe.printStackTrace();
+ }
+
+ }
+ }