Ignore:
Timestamp:
2015-03-10T01:17:39+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #11162 - update to metadata-extractor 2.7.2

File:
1 edited

Legend:

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

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121package com.drew.metadata;
     
    3737 * data types.
    3838 *
    39  * @author Drew Noakes http://drewnoakes.com
     39 * @author Drew Noakes https://drewnoakes.com
    4040 */
    4141public abstract class Directory
    4242{
    43     // TODO get Array methods need to return cloned data, to maintain this directory's integrity
    44 
    4543    /** Map of values hashed by type identifiers. */
    4644    @NotNull
     
    104102    public Collection<Tag> getTags()
    105103    {
    106         return _definedTagList;
     104        return Collections.unmodifiableCollection(_definedTagList);
    107105    }
    108106
     
    158156    public Iterable<String> getErrors()
    159157    {
    160         return _errorList;
     158        return Collections.unmodifiableCollection(_errorList);
    161159    }
    162160
     
    414412            return null;
    415413
    416         if (o instanceof String) {
     414        if (o instanceof Number) {
     415            return ((Number)o).intValue();
     416        } else if (o instanceof String) {
    417417            try {
    418418                return Integer.parseInt((String)o);
     
    428428                return (int)val;
    429429            }
    430         } else if (o instanceof Number) {
    431             return ((Number)o).intValue();
    432430        } else if (o instanceof Rational[]) {
    433431            Rational[] rationals = (Rational[])o;
     
    498496        if (o == null)
    499497            return null;
     498        if (o instanceof int[])
     499            return (int[])o;
    500500        if (o instanceof Rational[]) {
    501501            Rational[] rationals = (Rational[])o;
     
    506506            return ints;
    507507        }
    508         if (o instanceof int[])
    509             return (int[])o;
     508        if (o instanceof short[]) {
     509            short[] shorts = (short[])o;
     510            int[] ints = new int[shorts.length];
     511            for (int i = 0; i < shorts.length; i++) {
     512                ints[i] = shorts[i];
     513            }
     514            return ints;
     515        }
    510516        if (o instanceof byte[]) {
    511517            byte[] bytes = (byte[])o;
    512518            int[] ints = new int[bytes.length];
    513519            for (int i = 0; i < bytes.length; i++) {
    514                 byte b = bytes[i];
    515                 ints[i] = b;
     520                ints[i] = bytes[i];
    516521            }
    517522            return ints;
     
    527532        if (o instanceof Integer)
    528533            return new int[] { (Integer)o };
    529        
     534
    530535        return null;
    531536    }
     
    560565            }
    561566            return bytes;
     567        } else if (o instanceof short[]) {
     568            short[] shorts = (short[])o;
     569            byte[] bytes = new byte[shorts.length];
     570            for (int i = 0; i < shorts.length; i++) {
     571                bytes[i] = (byte)shorts[i];
     572            }
     573            return bytes;
    562574        } else if (o instanceof CharSequence) {
    563575            CharSequence str = (CharSequence)o;
     
    703715    /**
    704716     * Returns the specified tag's value as a java.util.Date.  If the value is unset or cannot be converted, <code>null</code> is returned.
    705      * <p/>
     717     * <p>
    706718     * If the underlying value is a {@link String}, then attempts will be made to parse the string as though it is in
    707719     * the current {@link TimeZone}.  If the {@link TimeZone} is known, call the overload that accepts one as an argument.
     
    712724        return getDate(tagType, null);
    713725    }
    714    
     726
    715727    /**
    716728     * Returns the specified tag's value as a java.util.Date.  If the value is unset or cannot be converted, <code>null</code> is returned.
    717      * <p/>
     729     * <p>
    718730     * If the underlying value is a {@link String}, then attempts will be made to parse the string as though it is in
    719731     * the {@link TimeZone} represented by the {@code timeZone} parameter (if it is non-null).  Note that this parameter
     
    818830            boolean isLongArray = componentType.getName().equals("long");
    819831            boolean isByteArray = componentType.getName().equals("byte");
     832            boolean isShortArray = componentType.getName().equals("short");
    820833            StringBuilder string = new StringBuilder();
    821834            for (int i = 0; i < arrayLength; i++) {
     
    826839                else if (isIntArray)
    827840                    string.append(Array.getInt(o, i));
     841                else if (isShortArray)
     842                    string.append(Array.getShort(o, i));
    828843                else if (isLongArray)
    829844                    string.append(Array.getLong(o, i));
     
    896911
    897912    /**
     913     * Gets whether the specified tag is known by the directory and has a name.
     914     *
     915     * @param tagType the tag type identifier
     916     * @return whether this directory has a name for the specified tag
     917     */
     918    public boolean hasTagName(int tagType)
     919    {
     920        return getTagNameMap().containsKey(tagType);
     921    }
     922
     923    /**
    898924     * Provides a description of a tag's value using the descriptor set by
    899925     * <code>setDescriptor(Descriptor)</code>.
     
    908934        return _descriptor.getDescription(tagType);
    909935    }
     936
     937    @Override
     938    public String toString()
     939    {
     940        return String.format("%s Directory (%d %s)",
     941            getName(),
     942            _tagMap.size(),
     943            _tagMap.size() == 1
     944                ? "tag"
     945                : "tags");
     946    }
    910947}
Note: See TracChangeset for help on using the changeset viewer.