[FIXED Close reader after stream has been closed.
All parsers are now working on streams. When a stream is closed
then the associated reader is not automatically closed. This
must be done manually.
@@ -84,14 +84,28 @@ public abstract class ReaderFactory {
@SuppressWarnings("MustBeClosedChecker")
@SuppressFBWarnings("OS_OPEN_STREAM")
public Stream<String> readStream() {
+ BufferedReader reader = new BufferedReader(create());
+ Stream<String> stringStream = reader.lines().onClose(closeReader(reader));
if (hasLineMapper()) {
- return new BufferedReader(create()).lines().map(lineMapper);
+ return stringStream.map(lineMapper);
}
else {
- return new BufferedReader(create()).lines();
+ return stringStream;
}
}
+ @SuppressWarnings("illegalcatch")
+ private Runnable closeReader(final AutoCloseable closeable) {
+ return () -> {
+ try {
+ closeable.close();
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ };
+ }
+
@SuppressWarnings("PMD.CompareObjectsWithEquals")
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification = "test stub")
private boolean hasLineMapper() {
