public void addData ( final char [ ] data , final int off , final int size ) { if ( size < 1 ) { return ; } final String str = new String ( data , off , size ) ; if ( str . contains ( "\n" ) ) { final String [ ] lines = str . split ( "\\r?\\n" , - 1 ) ; for ( int i = 0 ; i < lines . length - 1 ; i ++ ) { appendString ( lines [ i ] , true ) ; } if ( lines . length > 0 ) { final String last = lines [ lines . length - 1 ] ; if ( "" . equals ( last ) ) { //end of previous line } else { appendString ( last , false ) ; } } } else if ( str . contains ( "\r" ) ) { final String [ ] lines = str . split ( "\\r" , - 1 ) ; for ( int i = 0 ; i < lines . length - 2 ; i ++ ) { appendString ( lines [ i ] , true ) ; } //last two split strings //a: 1,1: yes,no //b: 0,1: yes,no //c: 0,0: yes(pass),no //d: 1,0: yes(pass), if ( lines . length >= 2 ) { final String last2 = lines [ lines . length - 2 ] ; final String last = lines [ lines . length - 1 ] ; if ( ! "" . equals ( last ) ) { appendString ( last2 , true ) ; appendString ( last , false ) ; } else { //pass \r for later \r\n resolution appendString ( last2 + "\r" , false ) ; } } } else { appendString ( str , false ) ; } }
Add character data to the buffer