From 7ac5c29d97451bf3cdbd8be5773d1650d91becd0 Mon Sep 17 00:00:00 2001 From: srowen Date: Tue, 14 Jun 2011 18:37:57 +0000 Subject: [PATCH] Issue 869, handle ImageIO.write() failure per user suggestion git-svn-id: https://zxing.googlecode.com/svn/trunk@1823 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- javase/src/com/google/zxing/client/j2se/DecodeThread.java | 4 +++- .../com/google/zxing/client/j2se/MatrixToImageWriter.java | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/javase/src/com/google/zxing/client/j2se/DecodeThread.java b/javase/src/com/google/zxing/client/j2se/DecodeThread.java index 27311c123..1c4390ce0 100644 --- a/javase/src/com/google/zxing/client/j2se/DecodeThread.java +++ b/javase/src/com/google/zxing/client/j2se/DecodeThread.java @@ -341,7 +341,9 @@ final class DecodeThread extends Thread { OutputStream outStream = null; try { outStream = new FileOutputStream(resultName); - ImageIO.write(result, "png", outStream); + if (!ImageIO.write(result, "png", outStream)) { + System.err.println("Could not encode an image to " + resultName); + } } catch (FileNotFoundException e) { System.err.println("Could not create " + resultName); } catch (IOException e) { diff --git a/javase/src/com/google/zxing/client/j2se/MatrixToImageWriter.java b/javase/src/com/google/zxing/client/j2se/MatrixToImageWriter.java index 918455510..f58f0e8d1 100644 --- a/javase/src/com/google/zxing/client/j2se/MatrixToImageWriter.java +++ b/javase/src/com/google/zxing/client/j2se/MatrixToImageWriter.java @@ -62,7 +62,9 @@ public final class MatrixToImageWriter { public static void writeToFile(BitMatrix matrix, String format, File file) throws IOException { BufferedImage image = toBufferedImage(matrix); - ImageIO.write(image, format, file); + if (!ImageIO.write(image, format, file)) { + throw new IOException("Could not write an image of format " + format + " to " + file); + } } /** @@ -73,7 +75,9 @@ public final class MatrixToImageWriter { public static void writeToStream(BitMatrix matrix, String format, OutputStream stream) throws IOException { BufferedImage image = toBufferedImage(matrix); - ImageIO.write(image, format, stream); + if (!ImageIO.write(image, format, stream)) { + throw new IOException("Could not write an image of format " + format); + } } }