Wrap all RuntimeExceptions into ParsingExceptions.
package edu.hm.hafner.analysis;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
+import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.InvalidPathException;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.io.input.ReaderInputStream;
import org.apache.commons.lang3.ObjectUtils;
@@ -84,6 +85,7 @@ public abstract class ReaderFactory {
@SuppressWarnings("MustBeClosedChecker")
@SuppressFBWarnings("OS_OPEN_STREAM")
public Stream<String> readStream() {
+ try {
BufferedReader reader = new BufferedReader(create());
Stream<String> stringStream = reader.lines().onClose(closeReader(reader));
if (hasLineMapper()) {
@@ -93,6 +95,10 @@ public abstract class ReaderFactory {
return stringStream;
}
}
+ catch (UncheckedIOException e) {
+ throw new ParsingException(e);
+ }
+ }
@SuppressWarnings({"illegalcatch", "PMD.DoNotUseThreads", "PMD.AvoidThrowingRawExceptionTypes"})
private Runnable closeReader(final AutoCloseable closeable) {
@@ -123,6 +129,9 @@ public abstract class ReaderFactory {
try (Stream<String> lines = readStream()) {
return lines.collect(Collectors.joining("\n"));
}
+ catch (UncheckedIOException e) {
+ throw new ParsingException(e);
+ }
}
/**
