Changeset 10862 in josm for trunk/src/com/drew/metadata/iptc/IptcReader.java
- Timestamp:
- 2016-08-20T20:58:03+02:00 (10 years ago)
- File:
-
- 1 edited
-
trunk/src/com/drew/metadata/iptc/IptcReader.java (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/metadata/iptc/IptcReader.java
r8243 r10862 1 1 /* 2 * Copyright 2002-201 5Drew Noakes2 * Copyright 2002-2016 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 26 26 import com.drew.lang.SequentialReader; 27 27 import com.drew.lang.annotations.NotNull; 28 import com.drew.lang.annotations.Nullable; 28 29 import com.drew.metadata.Directory; 29 30 import com.drew.metadata.Metadata; 30 31 31 32 import java.io.IOException; 32 import java.util.Arrays; 33 import java.util.Date; 33 import java.util.Collections; 34 34 35 35 /** … … 60 60 public Iterable<JpegSegmentType> getSegmentTypes() 61 61 { 62 return Arrays.asList(JpegSegmentType.APPD);62 return Collections.singletonList(JpegSegmentType.APPD); 63 63 } 64 64 … … 78 78 public void extract(@NotNull final SequentialReader reader, @NotNull final Metadata metadata, long length) 79 79 { 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 { 80 88 IptcDirectory directory = new IptcDirectory(); 81 89 metadata.addDirectory(directory); 90 91 if (parentDirectory != null) 92 directory.setParent(parentDirectory); 82 93 83 94 int offset = 0; … … 105 116 106 117 // we need at least five bytes left to read a tag 107 if (offset + 5 > =length) {118 if (offset + 5 > length) { 108 119 directory.addError("Too few bytes remain for a valid IPTC tag"); 109 120 return; … … 184 195 reader.skip(tagByteCount - 1); 185 196 return; 186 case IptcDirectory.TAG_RELEASE_DATE:187 case IptcDirectory.TAG_DATE_CREATED:188 // Date object189 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 below200 }201 } else {202 reader.skip(tagByteCount);203 }204 case IptcDirectory.TAG_RELEASE_TIME:205 case IptcDirectory.TAG_TIME_CREATED:206 // time...207 197 default: 208 198 // fall through … … 227 217 String[] newStrings; 228 218 if (oldStrings == null) { 219 // TODO hitting this block means any prior value(s) are discarded 229 220 newStrings = new String[1]; 230 221 } else {
Note:
See TracChangeset
for help on using the changeset viewer.
