com.drew.metadata
Class Directory

java.lang.Object
  extended by com.drew.metadata.Directory
Direct Known Subclasses:
AdobeJpegDirectory, CanonMakernoteDirectory, CasioType1MakernoteDirectory, CasioType2MakernoteDirectory, ExifIFD0Directory, ExifInteropDirectory, ExifSubIFDDirectory, ExifThumbnailDirectory, FujifilmMakernoteDirectory, GpsDirectory, IccDirectory, IptcDirectory, JfifDirectory, JpegCommentDirectory, JpegDirectory, KodakMakernoteDirectory, KyoceraMakernoteDirectory, NikonType1MakernoteDirectory, NikonType2MakernoteDirectory, OlympusMakernoteDirectory, PanasonicMakernoteDirectory, PentaxMakernoteDirectory, PhotoshopDirectory, PsdHeaderDirectory, SigmaMakernoteDirectory, SonyType1MakernoteDirectory, SonyType6MakernoteDirectory, XmpDirectory

public abstract class Directory
extends Object

Abstract base class for all directory implementations, having methods for getting and setting tag values of various data types.

Author:
Drew Noakes http://drewnoakes.com

Field Summary
protected  Collection<Tag> _definedTagList
          A convenient list holding tag values in the order in which they were stored.
protected  TagDescriptor _descriptor
          The descriptor used to interpret tag values.
protected  Map<Integer,Object> _tagMap
          Map of values hashed by type identifiers.
 
Constructor Summary
protected Directory()
           
 
Method Summary
 void addError(String message)
          Registers an error message with this directory.
 boolean containsTag(int tagType)
          Indicates whether the specified tag type has been set.
 boolean getBoolean(int tagType)
          Returns the specified tag's value as a boolean, if possible.
 Boolean getBooleanObject(int tagType)
          Returns the specified tag's value as a boolean.
 byte[] getByteArray(int tagType)
          Gets the specified tag's value as an byte array, if possible.
 Date getDate(int tagType)
          Returns the specified tag's value as a java.util.Date.
 Date getDate(int tagType, TimeZone timeZone)
          Returns the specified tag's value as a java.util.Date.
 String getDescription(int tagType)
          Provides a description of a tag's value using the descriptor set by setDescriptor(Descriptor).
 double getDouble(int tagType)
          Returns the specified tag's value as a double, if possible.
 Double getDoubleObject(int tagType)
          Returns the specified tag's value as a Double.
 int getErrorCount()
          Returns the count of error messages in this directory.
 Iterable<String> getErrors()
          Used to iterate over any error messages contained in this directory.
 float getFloat(int tagType)
          Returns the specified tag's value as a float, if possible.
 Float getFloatObject(int tagType)
          Returns the specified tag's value as a float.
 int getInt(int tagType)
          Returns the specified tag's value as an int, if possible.
 int[] getIntArray(int tagType)
          Gets the specified tag's value as an int array, if possible.
 Integer getInteger(int tagType)
          Returns the specified tag's value as an Integer, if possible.
 long getLong(int tagType)
          Returns the specified tag's value as a long, if possible.
 Long getLongObject(int tagType)
          Returns the specified tag's value as a long.
abstract  String getName()
          Provides the name of the directory, for display purposes.
 Object getObject(int tagType)
          Returns the object hashed for the particular tag type specified, if available.
 Rational getRational(int tagType)
          Returns the specified tag's value as a Rational.
 Rational[] getRationalArray(int tagType)
          Returns the specified tag's value as an array of Rational.
 String getString(int tagType)
          Returns the specified tag's value as a String.
 String getString(int tagType, String charset)
           
 String[] getStringArray(int tagType)
          Gets the specified tag's value as a String array, if possible.
 int getTagCount()
          Returns the number of tags set in this Directory.
 String getTagName(int tagType)
          Returns the name of a specified tag as a String.
protected abstract  HashMap<Integer,String> getTagNameMap()
          Provides the map of tag names, hashed by tag type identifier.
 Collection<Tag> getTags()
          Returns an Iterator of Tag instances that have been set in this Directory.
 boolean hasErrors()
          Gets a value indicating whether this directory has any error messages.
 void setBoolean(int tagType, boolean value)
          Sets a boolean value for the specified tag.
 void setByteArray(int tagType, byte[] bytes)
          Sets a byte[] (array) for the specified tag.
 void setDate(int tagType, Date value)
          Sets a java.util.Date value for the specified tag.
 void setDescriptor(TagDescriptor descriptor)
          Sets the descriptor used to interpret tag values.
 void setDouble(int tagType, double value)
          Sets a double value for the specified tag.
 void setDoubleArray(int tagType, double[] doubles)
          Sets a double[] (array) for the specified tag.
 void setFloat(int tagType, float value)
          Sets a float value for the specified tag.
 void setFloatArray(int tagType, float[] floats)
          Sets a float[] (array) for the specified tag.
 void setInt(int tagType, int value)
          Sets an int value for the specified tag.
 void setIntArray(int tagType, int[] ints)
          Sets an int[] (array) for the specified tag.
 void setLong(int tagType, long value)
          Sets a long value for the specified tag.
 void setObject(int tagType, Object value)
          Sets a Object for the specified tag.
 void setObjectArray(int tagType, Object array)
          Sets an array Object for the specified tag.
 void setRational(int tagType, Rational rational)
          Sets a Rational value for the specified tag.
 void setRationalArray(int tagType, Rational[] rationals)
          Sets a Rational[] (array) for the specified tag.
 void setString(int tagType, String value)
          Sets a String value for the specified tag.
 void setStringArray(int tagType, String[] strings)
          Sets a String[] (array) for the specified tag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_tagMap

protected final Map<Integer,Object> _tagMap
Map of values hashed by type identifiers.


_definedTagList

protected final Collection<Tag> _definedTagList
A convenient list holding tag values in the order in which they were stored. This is used for creation of an iterator, and for counting the number of defined tags.


_descriptor

protected TagDescriptor _descriptor
The descriptor used to interpret tag values.

Constructor Detail

Directory

protected Directory()
Method Detail

getName

public abstract String getName()
Provides the name of the directory, for display purposes. E.g. Exif

Returns:
the name of the directory

getTagNameMap

protected abstract HashMap<Integer,String> getTagNameMap()
Provides the map of tag names, hashed by tag type identifier.

Returns:
the map of tag names

containsTag

public boolean containsTag(int tagType)
Indicates whether the specified tag type has been set.

Parameters:
tagType - the tag type to check for
Returns:
true if a value exists for the specified tag type, false if not

getTags

public Collection<Tag> getTags()
Returns an Iterator of Tag instances that have been set in this Directory.

Returns:
an Iterator of Tag instances

getTagCount

public int getTagCount()
Returns the number of tags set in this Directory.

Returns:
the number of tags set in this Directory

setDescriptor

public void setDescriptor(TagDescriptor descriptor)
Sets the descriptor used to interpret tag values.

Parameters:
descriptor - the descriptor used to interpret tag values

addError

public void addError(String message)
Registers an error message with this directory.

Parameters:
message - an error message.

hasErrors

public boolean hasErrors()
Gets a value indicating whether this directory has any error messages.

Returns:
true if the directory contains errors, otherwise false

getErrors

public Iterable<String> getErrors()
Used to iterate over any error messages contained in this directory.

Returns:
an iterable collection of error message strings.

getErrorCount

public int getErrorCount()
Returns the count of error messages in this directory.


setInt

public void setInt(int tagType,
                   int value)
Sets an int value for the specified tag.

Parameters:
tagType - the tag's value as an int
value - the value for the specified tag as an int

setIntArray

public void setIntArray(int tagType,
                        int[] ints)
Sets an int[] (array) for the specified tag.

Parameters:
tagType - the tag identifier
ints - the int array to store

setFloat

public void setFloat(int tagType,
                     float value)
Sets a float value for the specified tag.

Parameters:
tagType - the tag's value as an int
value - the value for the specified tag as a float

setFloatArray

public void setFloatArray(int tagType,
                          float[] floats)
Sets a float[] (array) for the specified tag.

Parameters:
tagType - the tag identifier
floats - the float array to store

setDouble

public void setDouble(int tagType,
                      double value)
Sets a double value for the specified tag.

Parameters:
tagType - the tag's value as an int
value - the value for the specified tag as a double

setDoubleArray

public void setDoubleArray(int tagType,
                           double[] doubles)
Sets a double[] (array) for the specified tag.

Parameters:
tagType - the tag identifier
doubles - the double array to store

setString

public void setString(int tagType,
                      String value)
Sets a String value for the specified tag.

Parameters:
tagType - the tag's value as an int
value - the value for the specified tag as a String

setStringArray

public void setStringArray(int tagType,
                           String[] strings)
Sets a String[] (array) for the specified tag.

Parameters:
tagType - the tag identifier
strings - the String array to store

setBoolean

public void setBoolean(int tagType,
                       boolean value)
Sets a boolean value for the specified tag.

Parameters:
tagType - the tag's value as an int
value - the value for the specified tag as a boolean

setLong

public void setLong(int tagType,
                    long value)
Sets a long value for the specified tag.

Parameters:
tagType - the tag's value as an int
value - the value for the specified tag as a long

setDate

public void setDate(int tagType,
                    Date value)
Sets a java.util.Date value for the specified tag.

Parameters:
tagType - the tag's value as an int
value - the value for the specified tag as a java.util.Date

setRational

public void setRational(int tagType,
                        Rational rational)
Sets a Rational value for the specified tag.

Parameters:
tagType - the tag's value as an int
rational - rational number

setRationalArray

public void setRationalArray(int tagType,
                             Rational[] rationals)
Sets a Rational[] (array) for the specified tag.

Parameters:
tagType - the tag identifier
rationals - the Rational array to store

setByteArray

public void setByteArray(int tagType,
                         byte[] bytes)
Sets a byte[] (array) for the specified tag.

Parameters:
tagType - the tag identifier
bytes - the byte array to store

setObject

public void setObject(int tagType,
                      Object value)
Sets a Object for the specified tag.

Parameters:
tagType - the tag's value as an int
value - the value for the specified tag
Throws:
NullPointerException - if value is null

setObjectArray

public void setObjectArray(int tagType,
                           Object array)
Sets an array Object for the specified tag.

Parameters:
tagType - the tag's value as an int
array - the array of values for the specified tag

getInt

public int getInt(int tagType)
           throws MetadataException
Returns the specified tag's value as an int, if possible. Every attempt to represent the tag's value as an int is taken. Here is a list of the action taken depending upon the tag's original type:

Throws:
MetadataException - if no value exists for tagType or if it cannot be converted to an int.

getInteger

public Integer getInteger(int tagType)
Returns the specified tag's value as an Integer, if possible. Every attempt to represent the tag's value as an Integer is taken. Here is a list of the action taken depending upon the tag's original type: If the value is not found or cannot be converted to int, null is returned.


getStringArray

public String[] getStringArray(int tagType)
Gets the specified tag's value as a String array, if possible. Only supported where the tag is set as String[], String, int[], byte[] or Rational[].

Parameters:
tagType - the tag identifier
Returns:
the tag's value as an array of Strings. If the value is unset or cannot be converted, null is returned.

getIntArray

public int[] getIntArray(int tagType)
Gets the specified tag's value as an int array, if possible. Only supported where the tag is set as String, Integer, int[], byte[] or Rational[].

Parameters:
tagType - the tag identifier
Returns:
the tag's value as an int array

getByteArray

public byte[] getByteArray(int tagType)
Gets the specified tag's value as an byte array, if possible. Only supported where the tag is set as String, Integer, int[], byte[] or Rational[].

Parameters:
tagType - the tag identifier
Returns:
the tag's value as a byte array

getDouble

public double getDouble(int tagType)
                 throws MetadataException
Returns the specified tag's value as a double, if possible.

Throws:
MetadataException

getDoubleObject

public Double getDoubleObject(int tagType)
Returns the specified tag's value as a Double. If the tag is not set or cannot be converted, null is returned.


getFloat

public float getFloat(int tagType)
               throws MetadataException
Returns the specified tag's value as a float, if possible.

Throws:
MetadataException

getFloatObject

public Float getFloatObject(int tagType)
Returns the specified tag's value as a float. If the tag is not set or cannot be converted, null is returned.


getLong

public long getLong(int tagType)
             throws MetadataException
Returns the specified tag's value as a long, if possible.

Throws:
MetadataException

getLongObject

public Long getLongObject(int tagType)
Returns the specified tag's value as a long. If the tag is not set or cannot be converted, null is returned.


getBoolean

public boolean getBoolean(int tagType)
                   throws MetadataException
Returns the specified tag's value as a boolean, if possible.

Throws:
MetadataException

getBooleanObject

public Boolean getBooleanObject(int tagType)
Returns the specified tag's value as a boolean. If the tag is not set or cannot be converted, null is returned.


getDate

public Date getDate(int tagType)
Returns the specified tag's value as a java.util.Date. If the value is unset or cannot be converted, null is returned.

If the underlying value is a String, then attempts will be made to parse the string as though it is in the current TimeZone. If the TimeZone is known, call the overload that accepts one as an argument.


getDate

public Date getDate(int tagType,
                    TimeZone timeZone)
Returns the specified tag's value as a java.util.Date. If the value is unset or cannot be converted, null is returned.

If the underlying value is a String, then attempts will be made to parse the string as though it is in the TimeZone represented by the timeZone parameter (if it is non-null). Note that this parameter is only considered if the underlying value is a string and parsing occurs, otherwise it has no effect.


getRational

public Rational getRational(int tagType)
Returns the specified tag's value as a Rational. If the value is unset or cannot be converted, null is returned.


getRationalArray

public Rational[] getRationalArray(int tagType)
Returns the specified tag's value as an array of Rational. If the value is unset or cannot be converted, null is returned.


getString

public String getString(int tagType)
Returns the specified tag's value as a String. This value is the 'raw' value. A more presentable decoding of this value may be obtained from the corresponding Descriptor.

Returns:
the String representation of the tag's value, or null if the tag hasn't been defined.

getString

public String getString(int tagType,
                        String charset)

getObject

public Object getObject(int tagType)
Returns the object hashed for the particular tag type specified, if available.

Parameters:
tagType - the tag type identifier
Returns:
the tag's value as an Object if available, else null

getTagName

public String getTagName(int tagType)
Returns the name of a specified tag as a String.

Parameters:
tagType - the tag type identifier
Returns:
the tag's name as a String

getDescription

public String getDescription(int tagType)
Provides a description of a tag's value using the descriptor set by setDescriptor(Descriptor).

Parameters:
tagType - the tag type identifier
Returns:
the tag value's description as a String


Copyright © 2012. All Rights Reserved.