package JavaLinkedListDemo;
import java.io.* ; // required to use the BufferedReader class
public class jmhUtilities {
/** Default constructor to create a new instance of jmhUtilities.
* This constructor is not called because the jmhUtilities class
* contains only static methods.
*/
jmhUtilities() {
}
/** Get a line of text entered by the user from the console. The need for all
* this code is one thing that many people don’t like about Java! 8-(
*
Here's how this method works:
*ReadLine method of the
* BufferedReader classBufferedReader object
* that takes the only input object we have, System.in, which is an
* instance of the InputStream class. BufferedReader
* constructors only take objects of the Reader class.Reader class (or
* a class derived from a Reader class from an InputStream
* object. Looking through the API, we find the “bridge” we need: the
* InputStreamReader class.InputStreamReader class
* from the system-supplied System.in object (of type
* Inputstream).BufferedReader object.As noted above, this complexity is definitely a turn-off to many * people, but it is a nice demonstration of OOP and “building bridges” * between objects, a common requirement of all OO languages and * systems.
* @returnString entered by the user
*/
public static String ReadLine() {
String strUserEntry = "" ; // string entered by the user
InputStreamReader isrConsole = new InputStreamReader( System.in ) ;
BufferedReader brConsole = new BufferedReader( isrConsole ) ;
try {
System.out.flush() ; // ensure that prompt is visible
strUserEntry = brConsole.readLine() ; // read the user's input
} catch ( IOException ioe ) {
System.err.println( "An IOException has occurred in method ReadLine." ) ;
System.err.println( "The system reported:" ) ;
System.err.println( ioe.toString() ) ;
// the toString() method is not really needed above, but I have
// included it for clarity to show what the system actually does
// automatically
System.exit( 1 ) ; // terminate program execution with an error flag
}
return strUserEntry ;
}
}