JpegImageMetadata originalMetadata = (JpegImageMetadata) Sanselan
.getMetadata(imageFile);
assertNotNull(originalMetadata);
TiffImageMetadata oldExifMetadata = originalMetadata.getExif();
assertNotNull(oldExifMetadata);
ByteSource stripped;
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ExifRewriter().removeExifMetadata(byteSource, baos);
byte bytes[] = baos.toByteArray();
File tempFile = createTempFile("removed", ".jpg");
Debug.debug("tempFile", tempFile);
IOUtils.writeToFile(bytes, tempFile);
Debug.debug("Output Segments:");
stripped = new ByteSourceArray(bytes);
new JpegUtils().dumpJFIF(stripped);
assertTrue(!hasExifData(tempFile));
}
{
TiffOutputSet outputSet = oldExifMetadata.getOutputSet();
// outputSet.dump();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ExifRewriter().updateExifMetadataLossy(stripped, baos,
outputSet);
byte bytes[] = baos.toByteArray();
File tempFile = createTempFile("inserted" + "_", ".jpg");
Debug.debug("tempFile", tempFile);
IOUtils.writeToFile(bytes, tempFile);
Debug.debug("Output Segments:");
new JpegUtils().dumpJFIF(new ByteSourceArray(bytes));
// assertTrue(!hasExifData(tempFile));
JpegImageMetadata newMetadata = (JpegImageMetadata) Sanselan
.getMetadata(tempFile);
assertNotNull(newMetadata);
TiffImageMetadata newExifMetadata = newMetadata.getExif();
assertNotNull(newExifMetadata);
// newMetadata.dump();
compare(imageFile, oldExifMetadata, newExifMetadata);
}