From 1dd585ff91b38fc3caf679c8df0bee9695e1ae09 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 3 Apr 2016 10:29:05 +0100 Subject: Rethrow unwrapped IOException in public methods --- .../java/org/zwobble/mammoth/DocumentConverter.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/main/java/org/zwobble/mammoth/DocumentConverter.java') diff --git a/src/main/java/org/zwobble/mammoth/DocumentConverter.java b/src/main/java/org/zwobble/mammoth/DocumentConverter.java index a357487..f7112f4 100644 --- a/src/main/java/org/zwobble/mammoth/DocumentConverter.java +++ b/src/main/java/org/zwobble/mammoth/DocumentConverter.java @@ -12,6 +12,7 @@ import org.zwobble.mammoth.internal.docx.ZippedDocxFile; import org.zwobble.mammoth.internal.html.Html; import org.zwobble.mammoth.internal.results.InternalResult; import org.zwobble.mammoth.internal.util.Casts; +import org.zwobble.mammoth.internal.util.PassThroughException; import java.io.File; import java.io.IOException; @@ -76,16 +77,18 @@ public class DocumentConverter { * means that relative paths to other files, such as images, cannot be resolved. */ public Result convertToHtml(InputStream stream) throws IOException { - return withDocxFile(stream, zipFile -> - convertToHtml(Optional.empty(), zipFile)).toResult(); + return PassThroughException.unwrap(() -> + withDocxFile(stream, zipFile -> + convertToHtml(Optional.empty(), zipFile)).toResult()); } /** * Converts {@code file} into an HTML string. */ public Result convertToHtml(File file) throws IOException { - return withDocxFile(file, zipFile -> - convertToHtml(Optional.of(file.toPath()), zipFile)).toResult(); + return PassThroughException.unwrap(() -> + withDocxFile(file, zipFile -> + convertToHtml(Optional.of(file.toPath()), zipFile)).toResult()); } private InternalResult convertToHtml(Optional path, DocxFile zipFile) { @@ -102,8 +105,9 @@ public class DocumentConverter { * Each paragraph is followed by two newlines. */ public Result extractRawText(InputStream stream) throws IOException { - return withDocxFile(stream, zipFile -> - extractRawText(Optional.empty(), zipFile)).toResult(); + return PassThroughException.unwrap(() -> + withDocxFile(stream, zipFile -> + extractRawText(Optional.empty(), zipFile)).toResult()); } /** @@ -112,8 +116,9 @@ public class DocumentConverter { * Each paragraph is followed by two newlines. */ public Result extractRawText(File file) throws IOException { - return withDocxFile(file, zipFile -> - extractRawText(Optional.of(file.toPath()), zipFile)).toResult(); + return PassThroughException.unwrap(() -> + withDocxFile(file, zipFile -> + extractRawText(Optional.of(file.toPath()), zipFile)).toResult()); } private InternalResult extractRawText(Optional path, DocxFile zipFile) { -- cgit v1.2.3