public static <T>ArrayList<T> read(InputStream fileStream,String charsetName,ITransformer<String,T> transformer) throws FileNotFoundException {
  Scanner scanner=new Scanner(fileStream,charsetName);
  ArrayList<T> list=new ArrayList<>();
  while (scanner.hasNextLine()) {
    String line=scanner.nextLine();
    list.add(transformer.transform(line));
  }
  scanner.close();
  return list;
}

public static < T > ArrayList < T > read ( InputStream fileStream , String charsetName , ITransformer < String , T > transformer ) throws FileNotFoundException { Scanner scanner = new Scanner ( fileStream , charsetName ) ; ArrayList < T > list = new ArrayList < > ( ) ; while ( scanner . hasNextLine ( ) ) { String line = scanner . nextLine ( ) ; list . add ( transformer . transform ( line ) ) ; } scanner . close ( ) ; return list ; }
this function reads an inputstream line - by - line and converts each line into an object using a transformer that is passed as a parameter .
