FileDocCategorySizeDatePackage
LineReaderImpl.javaAPI DocGlassfish v2 API3145Fri May 04 22:31:06 BST 2007com.sun.appserv.management.util.misc

LineReaderImpl

public class LineReaderImpl extends Object implements LineReader
Reads a line from the specified input stream, outputs the prompt to System.out.

Fields Summary
final InputStreamReader
mInputStreamReader
Constructors Summary
public LineReaderImpl(InputStream inputStream)

		mInputStreamReader	= new InputStreamReader( inputStream );
	
Methods Summary
public java.lang.StringreadLine(java.lang.String prompt)

		final StringBuffer	line	= new StringBuffer();
		
		if ( prompt != null )
		{
			System.out.print( prompt );
		}
		
		while ( true )
		{
			final int	value	= mInputStreamReader.read();
			if ( value < 0 )
			{
				if ( line.length() != 0 )
				{
					// read a line but saw EOF before a newline
					break;
				}
				return( null );
			}
			
			final char	theChar	= (char)value;
			if ( theChar == '\n" )
				break;
			
			line.append( theChar );
		}
		
		return( line.toString().trim() );