Skip to content

Commit ca9fb42

Browse files
authored
v3.1.1
1 parent 6c4dcec commit ca9fb42

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/main/java/de/vwsoft/barcodelib4j/image/BarExporter.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,19 @@ public void writeEPS(OutputStream out, ImageColorModel colorModel) throws IOExce
552552

553553
ByteArrayOutputStream tiffArray = new ByteArrayOutputStream(10_000);
554554
BufferedImage img = createBufferedImage(myTiffRes, myTiffRes, null, myForeground, myBackground);
555-
ImageWriter imageWriter = ImageIO.getImageWritersByFormatName("tiff").next();
555+
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("tiff");
556+
if (!writers.hasNext())
557+
throw new IOException("No TIFF ImageWriter found");
558+
ImageWriter imageWriter = writers.next();
556559
ImageWriteParam param = imageWriter.getDefaultWriteParam();
557560
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
558561
param.setCompressionType("LZW");
559-
MemoryCacheImageOutputStream mc = new MemoryCacheImageOutputStream(tiffArray);
560-
imageWriter.setOutput(mc);
561-
imageWriter.write(null, new IIOImage(img, null, null), param);
562-
mc.flush();
562+
try (ImageOutputStream mc = new MemoryCacheImageOutputStream(tiffArray)) {
563+
imageWriter.setOutput(mc);
564+
imageWriter.write(null, new IIOImage(img, null, null), param);
565+
} finally {
566+
imageWriter.dispose();
567+
}
563568

564569
DataOutputStream dos = new DataOutputStream(out);
565570
dos.writeInt(0xC5D0D3C6); // EPS binary file header magic number (4 bytes)

0 commit comments

Comments
 (0)