1 33 34 35 package bsh; 36 37 import java.io.*; 38 39 47 class CommandLineReader extends FilterReader { 48 49 public CommandLineReader( Reader in ) { 50 super(in); 51 } 52 53 static final int 54 normal = 0, 55 lastCharNL = 1, 56 sentSemi = 2; 57 58 int state = lastCharNL; 59 60 public int read() throws IOException { 61 int b; 62 63 if ( state == sentSemi ) { 64 state = lastCharNL; 65 return '\n'; 66 } 67 68 while ( (b = in.read()) == '\r' ); 70 71 if ( b == '\n' ) 72 if ( state == lastCharNL ) { 73 b = ';'; 74 state = sentSemi; 75 } else 76 state = lastCharNL; 77 else 78 state = normal; 79 80 return b; 81 } 82 83 88 public int read(char buff[], int off, int len) throws IOException 89 { 90 int b = read(); 91 if ( b == -1 ) 92 return -1; else { 94 buff[off]=(char)b; 95 return 1; 96 } 97 } 98 99 public static void main( String [] args ) throws Exception { 101 Reader in = new CommandLineReader( new InputStreamReader(System.in) ); 102 while ( true ) 103 System.out.println( in.read() ); 104 105 } 106 } 107 108 | Popular Tags |