Top Description Fields Constructors Methods
javax.imageio.plugins.tiff

public Class TIFFDirectory

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
com.sun.imageio.plugins.tiff.TIFFIFD
Imports
java.util.ArrayList, .Arrays, .Iterator, .List, .Map, .TreeMap, javax.imageio.metadata.IIOInvalidTreeException, .IIOMetadata, .IIOMetadataFormatImpl, com.sun.imageio.plugins.tiff.TIFFIFD, .TIFFImageMetadata

A convenience class for simplifying interaction with TIFF native image metadata. A TIFF image metadata tree represents an Image File Directory (IFD) from a TIFF 6.0 stream. An IFD consists of a number of IFD Entries each of which associates an identifying tag number with a compatible value. A TIFFDirectory instance corresponds to an IFD and contains a set of TIFFFields each of which corresponds to an IFD Entry in the IFD.

When reading, a TIFFDirectory may be created by passing the value returned by ImageReader.getImageMetadata() to createFromMetadata(). The TIFFFields in the directory may then be obtained using the accessor methods provided in this class.

When writing, an IIOMetadata object for use by one of the write() methods of javax.imageio.ImageWriter may be created from a TIFFDirectory by getAsMetadata(). The TIFFDirectory itself may be created by construction or from the IIOMetadata object returned by ImageWriter.getDefaultImageMetadata(). The TIFFFields in the directory may be set using the mutator methods provided in this class.

A TIFFDirectory is aware of the tag numbers in the group of TIFFTagSets associated with it. When a TIFFDirectory is created from a native image metadata object, these tag sets are derived from the tagSets attribute of the TIFFIFD node.

A TIFFDirectory might also have a parent TIFFTag. This will occur if the directory represents an IFD other than the root IFD of the image. The parent tag is the tag of the IFD Entry which is a pointer to the IFD represented by this TIFFDirectory. The TIFFTag#isIFDPointer method of this parent TIFFTag must return true. When a TIFFDirectory is created from a native image metadata object, the parent tag set is set from the parentTagName attribute of the corresponding TIFFIFD node. Note that a TIFFDirectory instance which has a non-null parent tag will be contained in the data field of a TIFFField instance which has a tag field equal to the contained directory's parent tag.

As an example consider an Exif image. The TIFFDirectory instance corresponding to the Exif IFD in the Exif stream would have parent tag TAG_EXIF_IFD_POINTER and would include ExifTIFFTagSet in its group of known tag sets. The TIFFDirectory corresponding to this Exif IFD will be contained in the data field of a TIFFField which will in turn be contained in the TIFFDirectory corresponding to the primary IFD of the Exif image which will itself have a null-valued parent tag.

Note that this implementation is not synchronized. If multiple threads use a TIFFDirectory instance concurrently, and at least one of the threads modifies the directory, for example, by adding or removing TIFFFields or TIFFTagSets, it must be synchronized externally.

Since
9
See Also
IIOMetadata, TIFFField, TIFFTag, TIFFTagSet

Field Summary

Modifier and TypeField and Description
private Map<Integer, TIFFField>
highFields

A mapping of Integer tag numbers to TIFFFields for fields which are not low tag numbered.

private TIFFField[]
lowFields

The fields in this directory which have a low tag number.

private static final int
MAX_LOW_FIELD_TAG_NUM

The largest low-valued tag number in the TIFF 6.0 specification.

private int
numLowFields

The number of low tag numbered fields in the directory.

private TIFFTag
parentTag

The parent TIFFTag of this directory.

private List<TIFFTagSet>
tagSets

The TIFFTagSets associated with this directory.

Constructor Summary

AccessConstructor and Description
public
TIFFDirectory(TIFFTagSet[]
The TIFFTagSets associated with this directory.
tagSets
,
TIFFTag
The parent TIFFTag of this directory; may be null.
parentTag
)

Constructs a TIFFDirectory which is aware of a given group of TIFFTagSets.

Method Summary

Modifier and TypeMethod and Description
public void
addTagSet(TIFFTagSet
The TIFFTagSet to add.
tagSet
)

Adds an element to the group of TIFFTagSets of which this directory is aware.

public void
addTIFFField(TIFFField
The field to add.
f
)

Adds a TIFF field to the directory.

public TIFFDirectory

Returns:

A clone of this TIFFDirectory.
clone
()

Overrides java.lang.Object.clone.

Clones the directory and all the fields contained therein.

public boolean

Returns:

Whether a TIFFTag with tag number equal to tagNumber is present in this TIFFDirectory.
containsTIFFField
(int
The tag number.
tagNumber
)

Determines whether a TIFF field with the given tag number is contained in this directory.

public static TIFFDirectory

Returns:

A TIFFDirectory populated from the contents of the supplied metadata object.
createFromMetadata
(IIOMetadata
A metadata object which supports a compatible image metadata format.
tiffImageMetadata
)

Creates a TIFFDirectory instance from the contents of an image metadata object.

public IIOMetadata

Returns:

A metadata instance initialized from the contents of this TIFFDirectory.
getAsMetadata
()

Converts the directory to a metadata object.

public int

Returns:

The number of TIFFFields in this TIFFDirectory.
getNumTIFFFields
()

Returns the number of TIFFFields in this directory.

public TIFFTag

Returns:

The parent TIFFTag of this TIFFDiectory or null.
getParentTag
()

Returns the parent TIFFTag of this directory if one has been defined or null otherwise.

public TIFFTag

Returns:

The corresponding TIFFTag or null.
getTag
(int
The tag number of interest.
tagNumber
)

Returns the TIFFTag which has tag number equal to tagNumber or null if no such tag exists in the TIFFTagSets associated with this directory.

public TIFFTagSet[]

Returns:

The TIFFTagSets associated with this TIFFDirectory.
getTagSets
()

Returns the TIFFTagSets of which this directory is aware.

public TIFFField

Returns:

A TIFFField with the requested tag number of null if no such field is present.
getTIFFField
(int
The tag number of the tag associated with the field.
tagNumber
)

Retrieves a TIFF field from the directory.

public TIFFField[]

Returns:

An array of all TIFF fields in order of numerically increasing tag number.
getTIFFFields
()

Retrieves all TIFF fields from the directory.

public void
removeTagSet(TIFFTagSet
The TIFFTagSet to remove.
tagSet
)

Removes an element from the group of TIFFTagSets of which this directory is aware.

public void
removeTIFFField(int
The tag number of the tag associated with the field.
tagNumber
)

Removes a TIFF field from the directory.

public void
removeTIFFFields()

Removes all TIFF fields from the directory.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

highFieldsback to summary
private Map<Integer, TIFFField> highFields

A mapping of Integer tag numbers to TIFFFields for fields which are not low tag numbered.

lowFieldsback to summary
private TIFFField[] lowFields

The fields in this directory which have a low tag number. These are managed as an array for efficiency as they are the most common fields.

MAX_LOW_FIELD_TAG_NUMback to summary
private static final int MAX_LOW_FIELD_TAG_NUM

The largest low-valued tag number in the TIFF 6.0 specification.

numLowFieldsback to summary
private int numLowFields

The number of low tag numbered fields in the directory.

parentTagback to summary
private TIFFTag parentTag

The parent TIFFTag of this directory.

tagSetsback to summary
private List<TIFFTagSet> tagSets

The TIFFTagSets associated with this directory.

Constructor Detail

TIFFDirectoryback to summary
public TIFFDirectory(TIFFTagSet[] tagSets, TIFFTag parentTag)

Constructs a TIFFDirectory which is aware of a given group of TIFFTagSets. An optional parent TIFFTag may also be specified.

Parameters
tagSets:TIFFTagSet[]

The TIFFTagSets associated with this directory.

parentTag:TIFFTag

The parent TIFFTag of this directory; may be null.

Exceptions
NullPointerException:
if tagSets is null.

Method Detail

addTagSetback to summary
public void addTagSet(TIFFTagSet tagSet)

Adds an element to the group of TIFFTagSets of which this directory is aware.

Parameters
tagSet:TIFFTagSet

The TIFFTagSet to add.

Exceptions
NullPointerException:
if tagSet is null.
addTIFFFieldback to summary
public void addTIFFField(TIFFField f)

Adds a TIFF field to the directory.

Parameters
f:TIFFField

The field to add.

Exceptions
NullPointerException:
if f is null.
cloneback to summary
public TIFFDirectory clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Clones the directory and all the fields contained therein.

Returns:TIFFDirectory

A clone of this TIFFDirectory.

Annotations
@Override
Exceptions
CloneNotSupportedException:
if the instance cannot be cloned.
containsTIFFFieldback to summary
public boolean containsTIFFField(int tagNumber)

Determines whether a TIFF field with the given tag number is contained in this directory.

Parameters
tagNumber:int

The tag number.

Returns:boolean

Whether a TIFFTag with tag number equal to tagNumber is present in this TIFFDirectory.

createFromMetadataback to summary
public static TIFFDirectory createFromMetadata(IIOMetadata tiffImageMetadata) throws IIOInvalidTreeException

Creates a TIFFDirectory instance from the contents of an image metadata object. The supplied object must support an image metadata format supported by the TIFF javax.imageio.ImageWriter plug-in. This will usually be either the TIFF native image metadata format javax_imageio_tiff_image_1.0 or the Java Image I/O standard metadata format javax_imageio_1.0.

Parameters
tiffImageMetadata:IIOMetadata

A metadata object which supports a compatible image metadata format.

Returns:TIFFDirectory

A TIFFDirectory populated from the contents of the supplied metadata object.

Exceptions
IIOInvalidTreeException:
if the supplied metadata object cannot be parsed.
NullPointerException:
if tiffImageMetadata is null.
IllegalArgumentException:
if tiffImageMetadata does not support a compatible image metadata format.
getAsMetadataback to summary
public IIOMetadata getAsMetadata()

Converts the directory to a metadata object.

Returns:IIOMetadata

A metadata instance initialized from the contents of this TIFFDirectory.

getNumTIFFFieldsback to summary
public int getNumTIFFFields()

Returns the number of TIFFFields in this directory.

Returns:int

The number of TIFFFields in this TIFFDirectory.

getParentTagback to summary
public TIFFTag getParentTag()

Returns the parent TIFFTag of this directory if one has been defined or null otherwise.

Returns:TIFFTag

The parent TIFFTag of this TIFFDiectory or null.

getTagback to summary
public TIFFTag getTag(int tagNumber)

Returns the TIFFTag which has tag number equal to tagNumber or null if no such tag exists in the TIFFTagSets associated with this directory.

Parameters
tagNumber:int

The tag number of interest.

Returns:TIFFTag

The corresponding TIFFTag or null.

getTagSetsback to summary
public TIFFTagSet[] getTagSets()

Returns the TIFFTagSets of which this directory is aware.

Returns:TIFFTagSet[]

The TIFFTagSets associated with this TIFFDirectory.

getTIFFFieldback to summary
public TIFFField getTIFFField(int tagNumber)

Retrieves a TIFF field from the directory.

Parameters
tagNumber:int

The tag number of the tag associated with the field.

Returns:TIFFField

A TIFFField with the requested tag number of null if no such field is present.

getTIFFFieldsback to summary
public TIFFField[] getTIFFFields()

Retrieves all TIFF fields from the directory.

Returns:TIFFField[]

An array of all TIFF fields in order of numerically increasing tag number.

removeTagSetback to summary
public void removeTagSet(TIFFTagSet tagSet)

Removes an element from the group of TIFFTagSets of which this directory is aware.

Parameters
tagSet:TIFFTagSet

The TIFFTagSet to remove.

Exceptions
NullPointerException:
if tagSet is null.
removeTIFFFieldback to summary
public void removeTIFFField(int tagNumber)

Removes a TIFF field from the directory.

Parameters
tagNumber:int

The tag number of the tag associated with the field.

removeTIFFFieldsback to summary
public void removeTIFFFields()

Removes all TIFF fields from the directory.