// boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
// if (ignoreImageData)
// continue;
ByteSource byteSource = new ByteSourceFile(imageFile);
// Debug.debug("Source Segments:");
// new JpegUtils().dumpJFIF(byteSource);
Map params = new HashMap();
String xmpXml = new JpegImageParser().getXmpXml(byteSource, params);
assertNotNull(xmpXml);
// Debug.debug("xmpXml", xmpXml.length());
// Debug.debug();
File noXmpFile = createTempFile(imageFile.getName() + ".", ".jpg");
{
// test remove
OutputStream os = null;
try
{
os = new FileOutputStream(noXmpFile);
os = new BufferedOutputStream(os);
new JpegXmpRewriter().removeXmpXml(byteSource, os);
} finally
{
if (os != null) {
os.close();
}
os = null;
}
// Debug.debug("Source Segments:");
// new JpegUtils().dumpJFIF(new ByteSourceFile(noXmpFile));
String outXmp = new JpegImageParser().getXmpXml(
new ByteSourceFile(noXmpFile), params);
assertNull(outXmp);
}
{
// test update
String newXmpXml = "test";
File updated = createTempFile(imageFile.getName() + ".", ".jpg");
OutputStream os = null;
try
{
os = new FileOutputStream(updated);
os = new BufferedOutputStream(os);
new JpegXmpRewriter().updateXmpXml(byteSource, os,
newXmpXml);
} finally
{
if (os != null) {
os.close();
}
os = null;
}
// Debug.debug("Source Segments:");
// new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
String outXmp = new JpegImageParser().getXmpXml(
new ByteSourceFile(updated), params);
assertNotNull(outXmp);
assertEquals(outXmp, newXmpXml);
}
{
// test insert
String newXmpXml = "test";
File updated = createTempFile(imageFile.getName() + ".", ".jpg");
OutputStream os = null;
try
{
os = new FileOutputStream(updated);
os = new BufferedOutputStream(os);
new JpegXmpRewriter().updateXmpXml(new ByteSourceFile(noXmpFile), os,
newXmpXml);
} finally
{
if (os != null) {
os.close();
}
os = null;
}
// Debug.debug("Source Segments:");
// new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
String outXmp = new JpegImageParser().getXmpXml(
new ByteSourceFile(updated), params);
assertNotNull(outXmp);
assertEquals(outXmp, newXmpXml);
}
}
}