Ignore:
Timestamp:
2017-10-30T22:46:09+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #15505 - update to metadata-extractor 2.10.1

File:
1 edited

Legend:

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

    r10862 r13061  
    11/*
    2  * Copyright 2002-2016 Drew Noakes
     2 * Copyright 2002-2017 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    2424import com.drew.lang.annotations.NotNull;
    2525import com.drew.lang.annotations.Nullable;
     26import com.drew.lang.annotations.SuppressWarnings;
    2627
    2728import java.io.UnsupportedEncodingException;
     
    4142 * @author Drew Noakes https://drewnoakes.com
    4243 */
     44@java.lang.SuppressWarnings("WeakerAccess")
    4345public abstract class Directory
    4446{
    45     private static final DecimalFormat _floatFormat = new DecimalFormat("0.###");
     47    private static final String _floatFormatPattern = "0.###";
    4648
    4749    /** Map of values hashed by type identifiers. */
     
    260262
    261263    /**
     264     * Sets a <code>StringValue</code> value for the specified tag.
     265     *
     266     * @param tagType the tag's value as an int
     267     * @param value   the value for the specified tag as a StringValue
     268     */
     269    @java.lang.SuppressWarnings({ "ConstantConditions" })
     270    public void setStringValue(int tagType, @NotNull StringValue value)
     271    {
     272        if (value == null)
     273            throw new NullPointerException("cannot set a null StringValue");
     274        setObject(tagType, value);
     275    }
     276
     277    /**
    262278     * Sets a <code>String</code> value for the specified tag.
    263279     *
     
    280296     */
    281297    public void setStringArray(int tagType, @NotNull String[] strings)
     298    {
     299        setObjectArray(tagType, strings);
     300    }
     301
     302    /**
     303     * Sets a <code>StringValue[]</code> (array) for the specified tag.
     304     *
     305     * @param tagType the tag identifier
     306     * @param strings the StringValue array to store
     307     */
     308    public void setStringValueArray(int tagType, @NotNull StringValue[] strings)
    282309    {
    283310        setObjectArray(tagType, strings);
     
    440467        if (o instanceof Number) {
    441468            return ((Number)o).intValue();
    442         } else if (o instanceof String) {
     469        } else if (o instanceof String || o instanceof StringValue) {
    443470            try {
    444                 return Integer.parseInt((String)o);
     471                return Integer.parseInt(o.toString());
    445472            } catch (NumberFormatException nfe) {
    446473                // convert the char array to an int
    447                 String s = (String)o;
     474                String s = o.toString();
    448475                byte[] bytes = s.getBytes();
    449476                long val = 0;
     
    466493            if (ints.length == 1)
    467494                return ints[0];
     495        } else if (o instanceof short[]) {
     496            short[] shorts = (short[])o;
     497            if (shorts.length == 1)
     498                return (int)shorts[0];
    468499        }
    469500        return null;
     
    472503    /**
    473504     * Gets the specified tag's value as a String array, if possible.  Only supported
    474      * where the tag is set as String[], String, int[], byte[] or Rational[].
     505     * where the tag is set as StringValue[], String[], StringValue, String, int[], byte[] or Rational[].
    475506     *
    476507     * @param tagType the tag identifier
     
    487518        if (o instanceof String)
    488519            return new String[] { (String)o };
     520        if (o instanceof StringValue)
     521            return new String[] { o.toString() };
     522        if (o instanceof StringValue[]) {
     523            StringValue[] stringValues = (StringValue[])o;
     524            String[] strings = new String[stringValues.length];
     525            for (int i = 0; i < strings.length; i++)
     526                strings[i] = stringValues[i].toString();
     527            return strings;
     528        }
    489529        if (o instanceof int[]) {
    490530            int[] ints = (int[])o;
     
    493533                strings[i] = Integer.toString(ints[i]);
    494534            return strings;
    495         } else if (o instanceof byte[]) {
     535        }
     536        if (o instanceof byte[]) {
    496537            byte[] bytes = (byte[])o;
    497538            String[] strings = new String[bytes.length];
     
    499540                strings[i] = Byte.toString(bytes[i]);
    500541            return strings;
    501         } else if (o instanceof Rational[]) {
     542        }
     543        if (o instanceof Rational[]) {
    502544            Rational[] rationals = (Rational[])o;
    503545            String[] strings = new String[rationals.length];
     
    506548            return strings;
    507549        }
     550        return null;
     551    }
     552
     553    /**
     554     * Gets the specified tag's value as a StringValue array, if possible.
     555     * Only succeeds if the tag is set as StringValue[], or StringValue.
     556     *
     557     * @param tagType the tag identifier
     558     * @return the tag's value as an array of StringValues. If the value is unset or cannot be converted, <code>null</code> is returned.
     559     */
     560    @Nullable
     561    public StringValue[] getStringValueArray(int tagType)
     562    {
     563        Object o = getObject(tagType);
     564        if (o == null)
     565            return null;
     566        if (o instanceof StringValue[])
     567            return (StringValue[])o;
     568        if (o instanceof StringValue)
     569            return new StringValue[] {(StringValue) o};
    508570        return null;
    509571    }
     
    575637        if (o == null) {
    576638            return null;
     639        } else if (o instanceof StringValue) {
     640            return ((StringValue)o).getBytes();
    577641        } else if (o instanceof Rational[]) {
    578642            Rational[] rationals = (Rational[])o;
     
    630694        if (o == null)
    631695            return null;
    632         if (o instanceof String) {
     696        if (o instanceof String || o instanceof StringValue) {
    633697            try {
    634                 return Double.parseDouble((String)o);
     698                return Double.parseDouble(o.toString());
    635699            } catch (NumberFormatException nfe) {
    636700                return null;
     
    662726        if (o == null)
    663727            return null;
    664         if (o instanceof String) {
     728        if (o instanceof String || o instanceof StringValue) {
    665729            try {
    666                 return Float.parseFloat((String)o);
     730                return Float.parseFloat(o.toString());
    667731            } catch (NumberFormatException nfe) {
    668732                return null;
     
    678742    {
    679743        Long value = getLongObject(tagType);
    680         if (value!=null)
     744        if (value != null)
    681745            return value;
    682746        Object o = getObject(tagType);
     
    693757        if (o == null)
    694758            return null;
    695         if (o instanceof String) {
     759        if (o instanceof String || o instanceof StringValue) {
    696760            try {
    697                 return Long.parseLong((String)o);
     761                return Long.parseLong(o.toString());
    698762            } catch (NumberFormatException nfe) {
    699763                return null;
     
    709773    {
    710774        Boolean value = getBooleanObject(tagType);
    711         if (value!=null)
     775        if (value != null)
    712776            return value;
    713777        Object o = getObject(tagType);
     
    719783    /** Returns the specified tag's value as a boolean.  If the tag is not set or cannot be converted, <code>null</code> is returned. */
    720784    @Nullable
     785    @SuppressWarnings(value = "NP_BOOLEAN_RETURN_NULL", justification = "keep API interface consistent")
    721786    public Boolean getBooleanObject(int tagType)
    722787    {
     
    726791        if (o instanceof Boolean)
    727792            return (Boolean)o;
    728         if (o instanceof String) {
     793        if (o instanceof String || o instanceof StringValue) {
    729794            try {
    730                 return Boolean.getBoolean((String)o);
     795                return Boolean.getBoolean(o.toString());
    731796            } catch (NumberFormatException nfe) {
    732797                return null;
     
    788853        java.util.Date date = null;
    789854
    790         if (o instanceof String) {
     855        if ((o instanceof String) || (o instanceof StringValue)) {
    791856            // This seems to cover all known Exif and Xmp date strings
    792857            // Note that "    :  :     :  :  " is a valid date string according to the Exif spec (which means 'unknown date'): http://www.awaresystems.be/imaging/tiff/tifftags/privateifd/exif/datetimeoriginal.html
     
    802867                    "yyyy-MM-dd",
    803868                    "yyyy-MM",
     869                    "yyyyMMdd", // as used in IPTC data
    804870                    "yyyy" };
    805             String dateString = (String)o;
     871
     872            String dateString = o.toString();
    806873
    807874            // if the date string has subsecond information, it supersedes the subsecond parameter
     
    9451012                    if (i != 0)
    9461013                        string.append(' ');
    947                     string.append(_floatFormat.format(Array.getFloat(o, i)));
     1014                    string.append(new DecimalFormat(_floatFormatPattern).format(Array.getFloat(o, i)));
    9481015                }
    9491016            } else if (componentType.getName().equals("double")) {
     
    9511018                    if (i != 0)
    9521019                        string.append(' ');
    953                     string.append(_floatFormat.format(Array.getDouble(o, i)));
     1020                    string.append(new DecimalFormat(_floatFormatPattern).format(Array.getDouble(o, i)));
    9541021                }
    9551022            } else if (componentType.getName().equals("byte")) {
     
    9671034
    9681035        if (o instanceof Double)
    969             return _floatFormat.format(((Double)o).doubleValue());
     1036            return new DecimalFormat(_floatFormatPattern).format(((Double)o).doubleValue());
    9701037
    9711038        if (o instanceof Float)
    972             return _floatFormat.format(((Float)o).floatValue());
     1039            return new DecimalFormat(_floatFormatPattern).format(((Float)o).floatValue());
    9731040
    9741041        // Note that several cameras leave trailing spaces (Olympus, Nikon) but this library is intended to show
     
    9901057            return null;
    9911058        }
     1059    }
     1060
     1061    @Nullable
     1062    public StringValue getStringValue(int tagType)
     1063    {
     1064        Object o = getObject(tagType);
     1065        if (o instanceof StringValue)
     1066            return (StringValue)o;
     1067        return null;
    9921068    }
    9931069
Note: See TracChangeset for help on using the changeset viewer.