diff --git a/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxEncoderStreamTest.java b/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxEncoderStreamTest.java index 3aa88c4a..a3076ca1 100644 --- a/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxEncoderStreamTest.java +++ b/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/CCITTFaxEncoderStreamTest.java @@ -43,6 +43,7 @@ import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.io.*; import java.net.URL; +import java.util.Arrays; import static org.junit.Assert.*; @@ -124,6 +125,32 @@ public class CCITTFaxEncoderStreamTest { testImage(getClassLoaderResource("/tiff/fivepages-scan-causingerrors.tif")); } + /** + * Test for "Fixed an issue with long runlengths in CCITTFax writing #188" + * + * @throws IOException + */ + @Test + public void testRunlengthIssue() throws IOException { + byte[] data = new byte[400]; + Arrays.fill(data, (byte) 0xFF); + data[0] = 0; + data[399] = 0; + + ByteArrayOutputStream imageOutput = new ByteArrayOutputStream(); + OutputStream outputSteam = new CCITTFaxEncoderStream(imageOutput, 3200, 1, TIFFExtension.COMPRESSION_CCITT_T6, 1, 0L); + outputSteam.write(data); + outputSteam.close(); + byte[] encodedData = imageOutput.toByteArray(); + + byte[] decodedData = new byte[data.length]; + CCITTFaxDecoderStream inputStream = new CCITTFaxDecoderStream(new ByteArrayInputStream(encodedData), 3200, TIFFExtension.COMPRESSION_CCITT_T6, 1, 0L); + new DataInputStream(inputStream).readFully(decodedData); + inputStream.close(); + + assertArrayEquals(data, decodedData); + } + protected URL getClassLoaderResource(final String pName) { return getClass().getResource(pName); }