// to read a file. This is less efficient than approach 1, as the file
// is opened and read twice.
try {
Metadata metadata = new Metadata();
new ExifReader(jpegFile).extract(metadata);
new IptcReader(jpegFile).extract(metadata);
printImageTags(2, metadata);
} catch (JpegProcessingException jpe) {
System.err.println("error 2a");
}
// Approach 3
// As fast as approach 1 (this is what goes on inside the JpegMetadataReader's
// readMetadata() method), this code is handy if you want to look into other
// Jpeg segments too.
try {
JpegSegmentReader segmentReader = new JpegSegmentReader(jpegFile);
byte[] exifSegment = segmentReader.readSegment(JpegSegmentReader.SEGMENT_APP1);
byte[] iptcSegment = segmentReader.readSegment(JpegSegmentReader.SEGMENT_APPD);
Metadata metadata = new Metadata();
new ExifReader(exifSegment).extract(metadata);
new IptcReader(iptcSegment).extract(metadata);
printImageTags(3, metadata);
} catch (JpegProcessingException jpe) {
System.err.println("error 3a");
}