Package io.lumify.imageMetadataHelper

Source Code of io.lumify.imageMetadataHelper.DateExtractor

package io.lumify.imageMetadataHelper;

import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifIFD0Directory;
import com.drew.metadata.exif.ExifSubIFDDirectory;

import java.util.Date;

public class DateExtractor {

    /**
     * Checks the metadata directories in order until the date is found. The first match is returned.
     * <p/>
     * NOTE: Only the ExifIFD0Directory and ExifSubIFDDirectory directories will be scanned for dates. The other 8
     * directories will not be scanned for date and time information yet. (Perhaps implement later).
     */
    public static Date getDateDefault(Metadata metadata) {

        Date date = null;

        ExifIFD0Directory exifDir = metadata.getDirectory(ExifIFD0Directory.class);
        if (exifDir != null) {
            date = exifDir.getDate(ExifIFD0Directory.TAG_DATETIME);
            if (date != null) {
                return date;
            }
        }

        ExifSubIFDDirectory subDir = metadata.getDirectory(ExifSubIFDDirectory.class);
        if (subDir != null) {
            date = subDir.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
            if (date != null) {
                return date;
            }
        }

        return null;
    }

}
TOP

Related Classes of io.lumify.imageMetadataHelper.DateExtractor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.