Package de.julielab.java.utilities
Class CLIInteractionUtilities
- java.lang.Object
-
- de.julielab.java.utilities.CLIInteractionUtilities
-
public class CLIInteractionUtilities extends Object
This class offers helpful methods for standard command line interface applications. Refer to the method descriptions for more information.- Author:
- faessler
-
-
Constructor Summary
Constructors Constructor Description CLIInteractionUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringreadLineFromStdIn()Reads a line from standard input.static StringreadLineFromStdInWithMessage(String message)Prints a message to standard output and then reads a line from standard input.static StringreadLineFromStdInWithMessage(String message, String defaultResponse)Prints a message and also displays a default response that is automatically if the user does not explicitly specifies a response, i.e.static booleanreadYesNoFromStdInWithMessage(String message)Prints a message and appends the string "(y/n)" to indicate a y(es) or n(o) response where the long forms are also accepted.static booleanreadYesNoFromStdInWithMessage(String message, boolean defaultResponse)Prints a message and reads a yes or no answer where the defaultResponse it used if the user just hits enter without typing a response.
-
-
-
Method Detail
-
readLineFromStdIn
public static String readLineFromStdIn() throws IOException
Reads a line from standard input.- Returns:
- The read line.
- Throws:
IOException- If reading the line fails.
-
readLineFromStdInWithMessage
public static String readLineFromStdInWithMessage(String message) throws IOException
Prints a message to standard output and then reads a line from standard input.- Parameters:
message- The message to print.- Returns:
- The read line.
- Throws:
IOException- If reading fails.
-
readLineFromStdInWithMessage
public static String readLineFromStdInWithMessage(String message, String defaultResponse) throws IOException
Prints a message and also displays a default response that is automatically if the user does not explicitly specifies a response, i.e. only hits enter. Then reads a line from standard input.- Parameters:
message- The message to print.defaultResponse- The default response.- Returns:
- The read line or the default response if the user response is empty.
- Throws:
IOException- If reading the input fails.
-
readYesNoFromStdInWithMessage
public static boolean readYesNoFromStdInWithMessage(String message) throws IOException
Prints a message and appends the string "(y/n)" to indicate a y(es) or n(o) response where the long forms are also accepted. Then reads lines from standard input until the user specifies one of the valid responses.- Parameters:
message- The message to display.- Returns:
- True or false depending on the user response.
- Throws:
IOException- If reading the input fails.
-
readYesNoFromStdInWithMessage
public static boolean readYesNoFromStdInWithMessage(String message, boolean defaultResponse) throws IOException
Prints a message and reads a yes or no answer where the defaultResponse it used if the user just hits enter without typing a response. Then reads the response.- Parameters:
message- The message to print.defaultResponse- The default response.- Returns:
- True or false depending on user input.
- Throws:
IOException- If reading the line fails.
-
-