1 23 24 29 30 package com.sun.appserv.management.util.misc; 31 32 33 import java.io.InputStream ; 34 import java.io.InputStreamReader ; 35 36 40 public class LineReaderImpl implements LineReader 41 { 42 final InputStreamReader mInputStreamReader; 43 44 public 45 LineReaderImpl( InputStream inputStream ) 46 { 47 mInputStreamReader = new InputStreamReader ( inputStream ); 48 } 49 50 public String 51 readLine( String prompt ) 52 throws java.io.IOException 53 { 54 final StringBuffer line = new StringBuffer (); 55 56 if ( prompt != null ) 57 { 58 System.out.print( prompt ); 59 } 60 61 while ( true ) 62 { 63 final int value = mInputStreamReader.read(); 64 if ( value < 0 ) 65 { 66 if ( line.length() != 0 ) 67 { 68 break; 70 } 71 return( null ); 72 } 73 74 final char theChar = (char)value; 75 if ( theChar == '\n' ) 76 break; 77 78 line.append( theChar ); 79 } 80 81 return( line.toString().trim() ); 82 } 83 } 84 85 86 87 88 | Popular Tags |