20
20
21
21
import com .univocity .parsers .csv .CsvParser ;
22
22
import com .univocity .parsers .csv .CsvParserSettings ;
23
+ import org .checkerframework .checker .nullness .qual .NonNull ;
23
24
import org .checkerframework .checker .nullness .qual .Nullable ;
24
25
import org .spacious_team .table_wrapper .api .AbstractReportPage ;
25
26
import org .spacious_team .table_wrapper .api .TableCellAddress ;
@@ -44,23 +45,38 @@ public class CsvReportPage extends AbstractReportPage<CsvTableRow> {
44
45
* Field and line delimiter detected automatically. UTF-8 encoded file expected.
45
46
*/
46
47
public CsvReportPage (Path path ) throws IOException {
47
- this (Files .newInputStream (path , StandardOpenOption .READ ));
48
+ try (InputStream inputStream = Files .newInputStream (path , StandardOpenOption .READ )) {
49
+ this .rows = readRows (inputStream , UTF_8 , getDefaultCsvParserSettings ());
50
+ }
48
51
}
49
52
50
53
/**
51
- * Closes inputStream if success. UTF-8 encoded stream data expected.
54
+ * Field and line delimiter detected automatically. UTF-8 encoded file expected.
55
+ *
56
+ * @implSpec Does not close inputStream
52
57
*/
53
58
public CsvReportPage (InputStream inputStream ) throws IOException {
54
59
this (inputStream , UTF_8 , getDefaultCsvParserSettings ());
55
60
}
56
61
57
62
/**
58
- * Closes inputStream if success
63
+ * @implSpec Does not close inputStream
59
64
*/
60
65
public CsvReportPage (InputStream inputStream , Charset charset , CsvParserSettings csvParserSettings ) throws IOException {
66
+ CloseIgnoringInputStream closeIgnoringInputStream = new CloseIgnoringInputStream (inputStream );
67
+ this .rows = readRows (closeIgnoringInputStream , charset , csvParserSettings );
68
+ }
69
+
70
+ /**
71
+ * @implSpec Closes inputStream
72
+ */
73
+ private static String [] @ NonNull [] readRows (InputStream inputStream ,
74
+ Charset charset ,
75
+ CsvParserSettings csvParserSettings ) throws IOException {
61
76
try (Reader inputReader = new InputStreamReader (inputStream , charset )) {
62
77
CsvParser parser = new CsvParser (csvParserSettings );
63
- rows = parser .parseAll (inputReader ).toArray (new String [0 ][]);
78
+ return parser .parseAll (inputReader )
79
+ .toArray (new String [0 ][]);
64
80
}
65
81
}
66
82
0 commit comments