question: private String readLine ( InputStream inputStream ) throws IOException { int counter = 0 ; int increment = 1024 ; int bufferSize = increment ; byte [ ] lineBuffer = new byte [ bufferSize ] ; byte [ ] crlfBuffer = new byte [ 2 ] ; int crlfCounter = 0 ; while ( true ) { char ch ; int i = inputStream . read ( ) ; if ( i == - 1 ) { throw new IOException ( "End of stream" ) ; } else ch = ( char ) ( i & 0xFF ) ; if ( this . maxMessageSize > 0 ) { this . sizeCounter -- ; if ( this . sizeCounter <= 0 ) throw new IOException ( "Max size exceeded!" ) ; } if ( ch != '\r' ) lineBuffer [ counter ++ ] = ( byte ) ( i & 0xFF ) ; else if ( counter == 0 ) crlfBuffer [ crlfCounter ++ ] = ( byte ) '\r' ; if ( ch == '\n' ) { if ( counter == 1 && crlfCounter > 0 ) { crlfBuffer [ crlfCounter ++ ] = ( byte ) '\n' ; } break ; } if ( counter == bufferSize ) { byte [ ] tempBuffer = new byte [ bufferSize + increment ] ; System . arraycopy ( ( Object ) lineBuffer , 0 , ( Object ) tempBuffer , 0 , bufferSize ) ; bufferSize = bufferSize + increment ; lineBuffer = tempBuffer ; } } if ( counter == 1 && crlfCounter > 0 ) { return new String ( crlfBuffer , 0 , crlfCounter , "UTF-8" ) ; } else { return new String ( lineBuffer , 0 , counter , "UTF-8" ) ; } }
target:  read a line of input. Note that we encode the result in UTF-8