• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package junitparams.mappers;
2 
3 import java.io.BufferedReader;
4 import java.io.Reader;
5 import java.util.LinkedList;
6 import java.util.List;
7 
8 /**
9  * A Data Mapper based on Buffered Reader.
10  */
11 class BufferedReaderDataMapper implements DataMapper {
12 
13     private final int linesToSkip;
14 
BufferedReaderDataMapper()15     BufferedReaderDataMapper() {
16         this(0);
17     }
18 
BufferedReaderDataMapper(int linesToSkip)19     BufferedReaderDataMapper(int linesToSkip) {
20         this.linesToSkip = linesToSkip;
21     }
22 
23     @Override
map(Reader reader)24     public Object[] map(Reader reader) {
25         BufferedReader br = new BufferedReader(reader);
26         String line;
27         List<String> result = new LinkedList<String>();
28         int lineNo = 0;
29         try {
30             while ((line = br.readLine()) != null) {
31                 if (++lineNo > linesToSkip) {
32                     result.add(line);
33                 }
34             }
35             return result.toArray();
36         } catch (Exception e) {
37             throw new RuntimeException(e);
38         }
39     }
40 }
41