You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2019/07/18 13:40:52 UTC
[tika] 02/02: TIKA-2908 -- reorder closing of streams in tesseract
parser
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tika.git
commit 477a8cad63c455be195e4a75468cc3e162e67688
Author: TALLISON <ta...@apache.org>
AuthorDate: Thu Jul 18 09:19:57 2019 -0400
TIKA-2908 -- reorder closing of streams in tesseract parser
---
.../org/apache/tika/parser/ocr/TesseractOCRParser.java | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java b/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java
index 5c6c517..655aaf8 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java
@@ -61,6 +61,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.nio.charset.Charset;
@@ -236,23 +237,19 @@ public class TesseractOCRParser extends AbstractParser implements Initializable
public void parse(Image image, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException,
SAXException, TikaException {
TemporaryResources tmp = new TemporaryResources();
- FileOutputStream fos = null;
- TikaInputStream tis = null;
try {
int w = image.getWidth(null);
int h = image.getHeight(null);
BufferedImage bImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
File file = tmp.createTemporaryFile();
- fos = new FileOutputStream(file);
- ImageIO.write(bImage, "png", fos);
- tis = TikaInputStream.get(file);
- parse(tis, handler, metadata, context);
+ try (OutputStream fos = new FileOutputStream(file)) {
+ ImageIO.write(bImage, "png", fos);
+ }
+ try (TikaInputStream tis = TikaInputStream.get(file)) {
+ parse(tis, handler, metadata, context);
+ }
} finally {
tmp.dispose();
- if (tis != null)
- tis.close();
- if (fos != null)
- fos.close();
}
}