Class MetadataExtractor.Directory
- java.lang.Object
-
- gov.nih.mipav.model.file.MetadataExtractor.Directory
-
- Direct Known Subclasses:
MetadataExtractor.AdobeJpegDirectory
,MetadataExtractor.AppleMakernoteDirectory
,MetadataExtractor.AppleRunTimeMakernoteDirectory
,MetadataExtractor.BmpHeaderDirectory
,MetadataExtractor.CanonMakernoteDirectory
,MetadataExtractor.CasioType1MakernoteDirectory
,MetadataExtractor.CasioType2MakernoteDirectory
,MetadataExtractor.DuckyDirectory
,MetadataExtractor.ErrorDirectory
,MetadataExtractor.ExifDirectoryBase
,MetadataExtractor.FileSystemDirectory
,MetadataExtractor.FujifilmMakernoteDirectory
,MetadataExtractor.GifAnimationDirectory
,MetadataExtractor.GifCommentDirectory
,MetadataExtractor.GifControlDirectory
,MetadataExtractor.GifHeaderDirectory
,MetadataExtractor.GifImageDirectory
,MetadataExtractor.HuffmanTablesDirectory
,MetadataExtractor.IccDirectory
,MetadataExtractor.IptcDirectory
,MetadataExtractor.JfifDirectory
,MetadataExtractor.JfxxDirectory
,MetadataExtractor.JpegCommentDirectory
,MetadataExtractor.JpegDirectory
,MetadataExtractor.KodakMakernoteDirectory
,MetadataExtractor.KyoceraMakernoteDirectory
,MetadataExtractor.LeicaMakernoteDirectory
,MetadataExtractor.LeicaType5MakernoteDirectory
,MetadataExtractor.NikonType1MakernoteDirectory
,MetadataExtractor.NikonType2MakernoteDirectory
,MetadataExtractor.OlympusCameraSettingsMakernoteDirectory
,MetadataExtractor.OlympusEquipmentMakernoteDirectory
,MetadataExtractor.OlympusFocusInfoMakernoteDirectory
,MetadataExtractor.OlympusImageProcessingMakernoteDirectory
,MetadataExtractor.OlympusMakernoteDirectory
,MetadataExtractor.OlympusRawDevelopment2MakernoteDirectory
,MetadataExtractor.OlympusRawDevelopmentMakernoteDirectory
,MetadataExtractor.OlympusRawInfoMakernoteDirectory
,MetadataExtractor.PanasonicMakernoteDirectory
,MetadataExtractor.PanasonicRawDistortionDirectory
,MetadataExtractor.PanasonicRawIFD0Directory
,MetadataExtractor.PanasonicRawWbInfo2Directory
,MetadataExtractor.PanasonicRawWbInfoDirectory
,MetadataExtractor.PentaxMakernoteDirectory
,MetadataExtractor.PhotoshopDirectory
,MetadataExtractor.PngChromaticitiesDirectory
,MetadataExtractor.PngDirectory
,MetadataExtractor.PrintIMDirectory
,MetadataExtractor.PsdHeaderDirectory
,MetadataExtractor.ReconyxHyperFire2MakernoteDirectory
,MetadataExtractor.ReconyxHyperFireMakernoteDirectory
,MetadataExtractor.ReconyxUltraFireMakernoteDirectory
,MetadataExtractor.RicohMakernoteDirectory
,MetadataExtractor.SamsungType2MakernoteDirectory
,MetadataExtractor.SanyoMakernoteDirectory
,MetadataExtractor.SigmaMakernoteDirectory
,MetadataExtractor.SonyEncodedDataDirectoryBase
,MetadataExtractor.SonyType1MakernoteDirectory
,MetadataExtractor.SonyType6MakernoteDirectory
,MetadataExtractorTest.MockDirectory
- Enclosing class:
- MetadataExtractor
public abstract class MetadataExtractor.Directory extends java.lang.Object
Abstract base class for all directory implementations, having methods for getting and setting tag values of various data types.- Author:
- Drew Noakes https://drewnoakes.com
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Collection<MetadataExtractor.Tag>
_definedTagList
A convenient list holding tag values in the order in which they were stored.protected MetadataExtractor.TagDescriptor<?>
_descriptor
The descriptor used to interpret tag values.private java.util.Collection<java.lang.String>
_errorList
private static java.lang.String
_floatFormatPattern
private MetadataExtractor.Directory
_parent
protected java.util.Map<java.lang.Integer,java.lang.Object>
_tagMap
Map of values hashed by type identifiers.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Directory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addError(java.lang.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.java.lang.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.java.util.Date
getDate(int tagType)
Returns the specified tag's value as a java.util.Date.java.util.Date
getDate(int tagType, java.lang.String subsecond, java.util.TimeZone timeZone)
Returns the specified tag's value as a java.util.Date.java.util.Date
getDate(int tagType, java.util.TimeZone timeZone)
Returns the specified tag's value as a java.util.Date.java.lang.String
getDescription(int tagType)
Provides a description of a tag's value using the descriptor set bysetDescriptor(Descriptor)
.double
getDouble(int tagType)
Returns the specified tag's value as a double, if possible.java.lang.Double
getDoubleObject(int tagType)
Returns the specified tag's value as a Double.int
getErrorCount()
Returns the count of error messages in this directory.java.lang.Iterable<java.lang.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.java.lang.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.java.lang.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.java.lang.Long
getLongObject(int tagType)
Returns the specified tag's value as a long.abstract java.lang.String
getName()
Provides the name of the directory, for display purposes.java.lang.Object
getObject(int tagType)
Returns the object hashed for the particular tag type specified, if available.MetadataExtractor.Directory
getParent()
MetadataExtractor.Rational
getRational(int tagType)
Returns the specified tag's value as a Rational.MetadataExtractor.Rational[]
getRationalArray(int tagType)
Returns the specified tag's value as an array of Rational.java.lang.String
getString(int tagType)
Returns the specified tag's value as a String.java.lang.String
getString(int tagType, java.lang.String charset)
java.lang.String[]
getStringArray(int tagType)
Gets the specified tag's value as a String array, if possible.MetadataExtractor.StringValue
getStringValue(int tagType)
MetadataExtractor.StringValue[]
getStringValueArray(int tagType)
Gets the specified tag's value as a StringValue array, if possible.int
getTagCount()
Returns the number of tags set in this Directory.java.lang.String
getTagName(int tagType)
Returns the name of a specified tag as a String.protected abstract java.util.HashMap<java.lang.Integer,java.lang.String>
getTagNameMap()
Provides the map of tag names, hashed by tag type identifier.java.util.Collection<MetadataExtractor.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.boolean
hasTagName(int tagType)
Gets whether the specified tag is known by the directory and has a name.boolean
isEmpty()
Gets a value indicating whether the directory is empty, meaning it contains no errors and no tag values.void
setBoolean(int tagType, boolean value)
Sets aboolean
value for the specified tag.void
setByteArray(int tagType, byte[] bytes)
Sets abyte[]
(array) for the specified tag.void
setDate(int tagType, java.util.Date value)
Sets ajava.util.Date
value for the specified tag.void
setDescriptor(MetadataExtractor.TagDescriptor<?> descriptor)
Sets the descriptor used to interpret tag values.void
setDouble(int tagType, double value)
Sets adouble
value for the specified tag.void
setDoubleArray(int tagType, double[] doubles)
Sets adouble[]
(array) for the specified tag.void
setFloat(int tagType, float value)
Sets afloat
value for the specified tag.void
setFloatArray(int tagType, float[] floats)
Sets afloat[]
(array) for the specified tag.void
setInt(int tagType, int value)
Sets anint
value for the specified tag.void
setIntArray(int tagType, int[] ints)
Sets anint[]
(array) for the specified tag.void
setLong(int tagType, long value)
Sets along
value for the specified tag.void
setObject(int tagType, java.lang.Object value)
Sets aObject
for the specified tag.void
setObjectArray(int tagType, java.lang.Object array)
Sets an arrayObject
for the specified tag.void
setParent(MetadataExtractor.Directory parent)
void
setRational(int tagType, MetadataExtractor.Rational rational)
Sets aRational
value for the specified tag.void
setRationalArray(int tagType, MetadataExtractor.Rational[] rationals)
Sets aRational[]
(array) for the specified tag.void
setString(int tagType, java.lang.String value)
Sets aString
value for the specified tag.void
setStringArray(int tagType, java.lang.String[] strings)
Sets aString[]
(array) for the specified tag.void
setStringValue(int tagType, MetadataExtractor.StringValue value)
Sets aStringValue
value for the specified tag.void
setStringValueArray(int tagType, MetadataExtractor.StringValue[] strings)
Sets aStringValue[]
(array) for the specified tag.java.lang.String
toString()
-
-
-
Field Detail
-
_floatFormatPattern
private static final java.lang.String _floatFormatPattern
- See Also:
- Constant Field Values
-
_tagMap
protected final java.util.Map<java.lang.Integer,java.lang.Object> _tagMap
Map of values hashed by type identifiers.
-
_definedTagList
protected final java.util.Collection<MetadataExtractor.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.
-
_errorList
private final java.util.Collection<java.lang.String> _errorList
-
_descriptor
protected MetadataExtractor.TagDescriptor<?> _descriptor
The descriptor used to interpret tag values.
-
_parent
private MetadataExtractor.Directory _parent
-
-
Method Detail
-
getName
public abstract java.lang.String getName()
Provides the name of the directory, for display purposes. E.g.Exif
- Returns:
- the name of the directory
-
getTagNameMap
protected abstract java.util.HashMap<java.lang.Integer,java.lang.String> getTagNameMap()
Provides the map of tag names, hashed by tag type identifier.- Returns:
- the map of tag names
-
isEmpty
public boolean isEmpty()
Gets a value indicating whether the directory is empty, meaning it contains no errors and no tag values.
-
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 java.util.Collection<MetadataExtractor.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(MetadataExtractor.TagDescriptor<?> descriptor)
Sets the descriptor used to interpret tag values.- Parameters:
descriptor
- the descriptor used to interpret tag values
-
addError
public void addError(java.lang.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 java.lang.Iterable<java.lang.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.
-
getParent
public MetadataExtractor.Directory getParent()
-
setParent
public void setParent(MetadataExtractor.Directory parent)
-
setInt
public void setInt(int tagType, int value)
Sets anint
value for the specified tag.- Parameters:
tagType
- the tag's value as an intvalue
- the value for the specified tag as an int
-
setIntArray
public void setIntArray(int tagType, int[] ints)
Sets anint[]
(array) for the specified tag.- Parameters:
tagType
- the tag identifierints
- the int array to store
-
setFloat
public void setFloat(int tagType, float value)
Sets afloat
value for the specified tag.- Parameters:
tagType
- the tag's value as an intvalue
- the value for the specified tag as a float
-
setFloatArray
public void setFloatArray(int tagType, float[] floats)
Sets afloat[]
(array) for the specified tag.- Parameters:
tagType
- the tag identifierfloats
- the float array to store
-
setDouble
public void setDouble(int tagType, double value)
Sets adouble
value for the specified tag.- Parameters:
tagType
- the tag's value as an intvalue
- the value for the specified tag as a double
-
setDoubleArray
public void setDoubleArray(int tagType, double[] doubles)
Sets adouble[]
(array) for the specified tag.- Parameters:
tagType
- the tag identifierdoubles
- the double array to store
-
setStringValue
public void setStringValue(int tagType, MetadataExtractor.StringValue value)
Sets aStringValue
value for the specified tag.- Parameters:
tagType
- the tag's value as an intvalue
- the value for the specified tag as a StringValue
-
setString
public void setString(int tagType, java.lang.String value)
Sets aString
value for the specified tag.- Parameters:
tagType
- the tag's value as an intvalue
- the value for the specified tag as a String
-
setStringArray
public void setStringArray(int tagType, java.lang.String[] strings)
Sets aString[]
(array) for the specified tag.- Parameters:
tagType
- the tag identifierstrings
- the String array to store
-
setStringValueArray
public void setStringValueArray(int tagType, MetadataExtractor.StringValue[] strings)
Sets aStringValue[]
(array) for the specified tag.- Parameters:
tagType
- the tag identifierstrings
- the StringValue array to store
-
setBoolean
public void setBoolean(int tagType, boolean value)
Sets aboolean
value for the specified tag.- Parameters:
tagType
- the tag's value as an intvalue
- the value for the specified tag as a boolean
-
setLong
public void setLong(int tagType, long value)
Sets along
value for the specified tag.- Parameters:
tagType
- the tag's value as an intvalue
- the value for the specified tag as a long
-
setDate
public void setDate(int tagType, java.util.Date value)
Sets ajava.util.Date
value for the specified tag.- Parameters:
tagType
- the tag's value as an intvalue
- the value for the specified tag as a java.util.Date
-
setRational
public void setRational(int tagType, MetadataExtractor.Rational rational)
Sets aRational
value for the specified tag.- Parameters:
tagType
- the tag's value as an intrational
- rational number
-
setRationalArray
public void setRationalArray(int tagType, MetadataExtractor.Rational[] rationals)
Sets aRational[]
(array) for the specified tag.- Parameters:
tagType
- the tag identifierrationals
- the Rational array to store
-
setByteArray
public void setByteArray(int tagType, byte[] bytes)
Sets abyte[]
(array) for the specified tag.- Parameters:
tagType
- the tag identifierbytes
- the byte array to store
-
setObject
public void setObject(int tagType, java.lang.Object value)
Sets aObject
for the specified tag.- Parameters:
tagType
- the tag's value as an intvalue
- the value for the specified tag- Throws:
java.lang.NullPointerException
- if value isnull
-
setObjectArray
public void setObjectArray(int tagType, java.lang.Object array)
Sets an arrayObject
for the specified tag.- Parameters:
tagType
- the tag's value as an intarray
- the array of values for the specified tag
-
getInt
public int getInt(int tagType) throws MetadataExtractor.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:- int - Return unchanged.
- Number - Return an int value (real numbers are truncated).
- Rational - Truncate any fractional part and returns remaining int.
- String - Attempt to parse string as an int. If this fails, convert the char[] to an int (using shifts and OR).
- Rational[] - Return int value of first item in array.
- byte[] - Return int value of first item in array.
- int[] - Return int value of first item in array.
- Throws:
MetadataExtractor.MetadataException
- if no value exists for tagType or if it cannot be converted to an int.
-
getInteger
public java.lang.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:- int - Return unchanged
- Number - Return an int value (real numbers are truncated)
- Rational - Truncate any fractional part and returns remaining int
- String - Attempt to parse string as an int. If this fails, convert the char[] to an int (using shifts and OR)
- Rational[] - Return int value of first item in array if length > 0
- byte[] - Return int value of first item in array if length > 0
- int[] - Return int value of first item in array if length > 0
null
is returned.
-
getStringArray
public java.lang.String[] getStringArray(int tagType)
Gets the specified tag's value as a String array, if possible. Only supported where the tag is set as StringValue[], String[], StringValue, 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.
-
getStringValueArray
public MetadataExtractor.StringValue[] getStringValueArray(int tagType)
Gets the specified tag's value as a StringValue array, if possible. Only succeeds if the tag is set as StringValue[], or StringValue.- Parameters:
tagType
- the tag identifier- Returns:
- the tag's value as an array of StringValues. 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 MetadataExtractor.MetadataException
Returns the specified tag's value as a double, if possible.
-
getDoubleObject
public java.lang.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 MetadataExtractor.MetadataException
Returns the specified tag's value as a float, if possible.
-
getFloatObject
public java.lang.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 MetadataExtractor.MetadataException
Returns the specified tag's value as a long, if possible.
-
getLongObject
public java.lang.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 MetadataExtractor.MetadataException
Returns the specified tag's value as a boolean, if possible.
-
getBooleanObject
public java.lang.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 java.util.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 GMTTimeZone
. If theTimeZone
is known, call the overload that accepts one as an argument.
-
getDate
public java.util.Date getDate(int tagType, java.util.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 theTimeZone
represented by thetimeZone
parameter (if it is non-null). Note that this parameter is only considered if the underlying value is a string and it has no time zone information, otherwise it has no effect.
-
getDate
public java.util.Date getDate(int tagType, java.lang.String subsecond, java.util.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 theTimeZone
represented by thetimeZone
parameter (if it is non-null). Note that this parameter is only considered if the underlying value is a string and it has no time zone information, otherwise it has no effect. In addition, thesubsecond
parameter, which specifies the number of digits after the decimal point in the seconds, is set to the returned Date. This parameter is only considered if the underlying value is a string and is has no subsecond information, otherwise it has no effect.- Parameters:
tagType
- the tag identifiersubsecond
- the subsecond value for the DatetimeZone
- the time zone to use- Returns:
- a Date representing the time value
-
getRational
public MetadataExtractor.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 MetadataExtractor.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 java.lang.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 java.lang.String getString(int tagType, java.lang.String charset)
-
getStringValue
public MetadataExtractor.StringValue getStringValue(int tagType)
-
getObject
public java.lang.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 java.lang.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
-
hasTagName
public boolean hasTagName(int tagType)
Gets whether the specified tag is known by the directory and has a name.- Parameters:
tagType
- the tag type identifier- Returns:
- whether this directory has a name for the specified tag
-
getDescription
public java.lang.String getDescription(int tagType)
Provides a description of a tag's value using the descriptor set bysetDescriptor(Descriptor)
.- Parameters:
tagType
- the tag type identifier- Returns:
- the tag value's description as a String
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-