Ignore:
Timestamp:
2016-08-20T20:58:03+02:00 (10 years ago)
Author:
Don-vip
Message:

update to metadata-extractor 2.9.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/metadata/iptc/IptcReader.java

    r8243 r10862  
    11/*
    2  * Copyright 2002-2015 Drew Noakes
     2 * Copyright 2002-2016 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    2626import com.drew.lang.SequentialReader;
    2727import com.drew.lang.annotations.NotNull;
     28import com.drew.lang.annotations.Nullable;
    2829import com.drew.metadata.Directory;
    2930import com.drew.metadata.Metadata;
    3031
    3132import java.io.IOException;
    32 import java.util.Arrays;
    33 import java.util.Date;
     33import java.util.Collections;
    3434
    3535/**
     
    6060    public Iterable<JpegSegmentType> getSegmentTypes()
    6161    {
    62         return Arrays.asList(JpegSegmentType.APPD);
     62        return Collections.singletonList(JpegSegmentType.APPD);
    6363    }
    6464
     
    7878    public void extract(@NotNull final SequentialReader reader, @NotNull final Metadata metadata, long length)
    7979    {
     80        extract(reader, metadata, length, null);
     81    }
     82
     83    /**
     84     * Performs the IPTC data extraction, adding found values to the specified instance of {@link Metadata}.
     85     */
     86    public void extract(@NotNull final SequentialReader reader, @NotNull final Metadata metadata, long length, @Nullable Directory parentDirectory)
     87    {
    8088        IptcDirectory directory = new IptcDirectory();
    8189        metadata.addDirectory(directory);
     90
     91        if (parentDirectory != null)
     92            directory.setParent(parentDirectory);
    8293
    8394        int offset = 0;
     
    105116
    106117            // we need at least five bytes left to read a tag
    107             if (offset + 5 >= length) {
     118            if (offset + 5 > length) {
    108119                directory.addError("Too few bytes remain for a valid IPTC tag");
    109120                return;
     
    184195                reader.skip(tagByteCount - 1);
    185196                return;
    186             case IptcDirectory.TAG_RELEASE_DATE:
    187             case IptcDirectory.TAG_DATE_CREATED:
    188                 // Date object
    189                 if (tagByteCount >= 8) {
    190                     string = reader.getString(tagByteCount);
    191                     try {
    192                         int year = Integer.parseInt(string.substring(0, 4));
    193                         int month = Integer.parseInt(string.substring(4, 6)) - 1;
    194                         int day = Integer.parseInt(string.substring(6, 8));
    195                         Date date = new java.util.GregorianCalendar(year, month, day).getTime();
    196                         directory.setDate(tagIdentifier, date);
    197                         return;
    198                     } catch (NumberFormatException e) {
    199                         // fall through and we'll process the 'string' value below
    200                     }
    201                 } else {
    202                     reader.skip(tagByteCount);
    203                 }
    204             case IptcDirectory.TAG_RELEASE_TIME:
    205             case IptcDirectory.TAG_TIME_CREATED:
    206                 // time...
    207197            default:
    208198                // fall through
     
    227217            String[] newStrings;
    228218            if (oldStrings == null) {
     219                // TODO hitting this block means any prior value(s) are discarded
    229220                newStrings = new String[1];
    230221            } else {
Note: See TracChangeset for help on using the changeset viewer.