Support writing ASCII array in TIFF metadata (#656)

* Support writing ASCII array in TIFF metadata

* corrected formatting and extracted string writing to method
This commit is contained in:
Oliver Schmidtmer
2022-01-12 18:56:22 +01:00
committed by GitHub
parent b8614eca4d
commit 74611e4e52
2 changed files with 48 additions and 5 deletions
@@ -47,8 +47,10 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* TIFFWriterTest
@@ -254,6 +256,27 @@ public class TIFFWriterTest extends MetadataWriterAbstractTest {
assertEquals(98, stream.getStreamPosition());
}
@Test
public void testWriteASCIIArray() throws IOException {
ArrayList<Entry> entries = new ArrayList<>();
String[] strings = new String []{"Twelve", "Monkeys", "ImageIO"};
entries.add(new AbstractEntry(TIFF.TAG_SOFTWARE, strings) {});
Directory directory = new AbstractDirectory(entries) {};
ByteArrayOutputStream output = new FastByteArrayOutputStream(1024);
ImageOutputStream imageStream = ImageIO.createImageOutputStream(output);
imageStream.setByteOrder(ByteOrder.LITTLE_ENDIAN); // LE = Intel
createWriter().write(directory, imageStream);
imageStream.flush();
byte[] data = output.toByteArray();
Directory read = new TIFFReader().read(new ByteArrayImageInputStream(data));
assertNotNull(read.getEntryById(TIFF.TAG_SOFTWARE));
assertTrue("value not an string array", read.getEntryById(TIFF.TAG_SOFTWARE).getValue() instanceof String[]);
assertArrayEquals("", strings, (String[]) read.getEntryById(TIFF.TAG_SOFTWARE).getValue());
}
@Test
public void testComputeIFDSizeNested() throws IOException {
TIFFEntry artist = new TIFFEntry(TIFF.TAG_SOFTWARE, TIFF.TYPE_ASCII, "TwelveMonkeys ImageIO");