public static String readLine(InputStream in,String charset) throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  while (true) {
    int b=in.read();
    if (b == -1) {
      if (baos.size() == 0) {
        return null;
      }
 else {
        break;
      }
    }
    if (b == '\n') {
      break;
    }
    if (b != '\r') {
      baos.write(b);
      continue;
    }
    int b2=in.read();
    if (b2 == -1) {
      baos.write(b);
      break;
    }
    if (b2 == '\n') {
      break;
    }
    baos.write(b);
    baos.write(b2);
  }
  return baos.toString(charset);
}

public static String readLine ( InputStream in , String charset ) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; while ( true ) { int b = in . read ( ) ; if ( b == - 1 ) { if ( baos . size ( ) == 0 ) { return null ; } else { break ; } } if ( b == '\n' ) { break ; } if ( b != '\r' ) { baos . write ( b ) ; continue ; } int b2 = in . read ( ) ; if ( b2 == - 1 ) { baos . write ( b ) ; break ; } if ( b2 == '\n' ) { break ; } baos . write ( b ) ; baos . write ( b2 ) ; } return baos . toString ( charset ) ; }
read a line from the given stream .
