I need to be able to update image metadata (namely, tags, creator, description, comments) and do it within regular Exif and XMP. Most likely, i'll be reading the Exif, and writing XMP.
After much searching for a library that works ALSO for writing, I came across twelvemonkeys.
https://github.com/haraldk/TwelveMonkeys
This seemed to be promising. And indeed, with little effort I was able to read, already, the Exif containing description in one of my images. Not with the standard javax API, mind you, but with a twelvemonkeys API. That's fine with me. Whatever works!
At this point, I was happy to avoid the standard API as much as possible, as it seemed horribly convoluted and inefficient. I started about reading in my Exif, and coding the modification for my proof-of-concept. The idea being, the most efficient way to achieve what I want (quick and safe modification of metadata within JPEG files) was to perform the following steps:
- Read all segments into a list
- Find the segment that needs modification
- Do that modification
- Write all segments, sequentially, to a temp file
- If all goes well, rename the original to later safely delete, rename the copy to the original name, and finally, delete the original file.
However, I was a bit dismayed when I discovered that there seems to be no implementation of
com.twelvemonkeys.imageio.metadata.Directory
which implements the methods
add(Entry)
and
remove(Object)
with anything other than a
throw new UnsupportedOperationException("Directory is read-only");
If this is not the way to efficiently (and safely) achieve what I want to do... Does anyone have a suggestion on how, in pure Java, I can do this?