Issue 869, handle ImageIO.write() failure per user suggestion

git-svn-id: https://zxing.googlecode.com/svn/trunk@1823 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2011-06-14 18:37:57 +00:00
parent 8a1c720221
commit 7ac5c29d97
2 changed files with 9 additions and 3 deletions

View file

@ -341,7 +341,9 @@ final class DecodeThread extends Thread {
OutputStream outStream = null; OutputStream outStream = null;
try { try {
outStream = new FileOutputStream(resultName); 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) { } catch (FileNotFoundException e) {
System.err.println("Could not create " + resultName); System.err.println("Could not create " + resultName);
} catch (IOException e) { } catch (IOException e) {

View file

@ -62,7 +62,9 @@ public final class MatrixToImageWriter {
public static void writeToFile(BitMatrix matrix, String format, File file) public static void writeToFile(BitMatrix matrix, String format, File file)
throws IOException { throws IOException {
BufferedImage image = toBufferedImage(matrix); 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) public static void writeToStream(BitMatrix matrix, String format, OutputStream stream)
throws IOException { throws IOException {
BufferedImage image = toBufferedImage(matrix); 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);
}
} }
} }