for (Segment sapp1 : app1) {
handleAPP1Segment(sapp1);
}
// We have no XMP but other APP1, insert XMP behind other APP1
if (xmpSegment == null && !app1.isEmpty()) {
Segment lastAPP1 = app1.get(app1.size() - 1);
xmpSegment = new Segment(Marker.APP1, lastAPP1.offset
+ lastAPP1.length, 0);
}
// We have no APP1 but APP0, insert XMP behind APP0
if (xmpSegment == null) {
List<Segment> app0 = structure.getSegments(Marker.APP0);
if (!app0.isEmpty()) {
Segment lastAPP0 = app0.get(app0.size() - 1);
xmpSegment = new Segment(Marker.APP1, lastAPP0.offset
+ lastAPP0.length, 0);
}
}
// We have neither XMP nor EXIF nor APP0, insert behind SOI
if (xmpSegment == null) {
List<Segment> soi = structure.getSegments(Marker.SOI);
if (soi.isEmpty()) {
throw new XMPReadException("No SOI marker found.");
}
xmpSegment = new Segment(Marker.APP1, soi.get(0).offset, 0);
}
}