- All Implemented Interfaces:
- Cloneable
 A field in a TIFF Image File Directory (IFD) is defined as a
 tag number accompanied by a sequence of values of identical data type.
 TIFF 6.0 defines 12 data types; a 13th type IFD is
 defined in TIFF Tech Note 1 of TIFF Specification Supplement 1. These
 TIFF data types are referred to by Java constants and mapped internally
 onto Java language data types and type names as follows:
 
| TIFF Data Type | Java Constant | Java Data Type | Java Type Name | 
|---|---|---|---|
| BYTE | TIFFTag.TIFF_BYTE | byte | "Byte" | 
| ASCII | TIFFTag.TIFF_ASCII | String | "Ascii" | 
| SHORT | TIFFTag.TIFF_SHORT | char | "Short" | 
| LONG | TIFFTag.TIFF_LONG | long | "Long" | 
| RATIONAL | TIFFTag.TIFF_RATIONAL | long[2]{numerator, denominator} | "Rational" | 
| SBYTE | TIFFTag.TIFF_SBYTE | byte | "SByte" | 
| UNDEFINED | TIFFTag.TIFF_UNDEFINED | byte | "Undefined" | 
| SSHORT | TIFFTag.TIFF_SSHORT | short | "SShort" | 
| SLONG | TIFFTag.TIFF_SLONG | int | "SLong" | 
| SRATIONAL | TIFFTag.TIFF_SRATIONAL | int[2]{numerator, denominator} | "SRational" | 
| FLOAT | TIFFTag.TIFF_FLOAT | float | "Float" | 
| DOUBLE | TIFFTag.TIFF_DOUBLE | double | "Double" | 
| IFD | TIFFTag.TIFF_IFD_POINTER | long | "IFDPointer" | 
- Since:
- 9
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs a data array usingcreateArrayForType()and invokesTIFFField(TIFFTag,int,int,Object)with the supplied parameters and the created array.Constructs aTIFFFieldwith arbitrary data.TIFFField(TIFFTag tag, int type, long offset, TIFFDirectory dir) Constructs aTIFFFieldwith an IFD offset and contents.Constructs aTIFFFieldwith a single non-negative integral value.
- 
Method SummaryModifier and TypeMethodDescriptionclone()Clones the field and all the information contained therein.static ObjectcreateArrayForType(int dataType, int count) Creates an array appropriate for the indicated data type.static TIFFFieldcreateFromMetadataNode(TIFFTagSet tagSet, Node node) Creates aTIFFFieldfrom a TIFF native image metadata node.byte[]Returns the data as an uninterpreted array ofbytes.char[]ReturnsTIFFTag.TIFF_SHORTdata as an array ofchars (unsigned 16-bit integers).doublegetAsDouble(int index) Returns data in any format as adouble.double[]ReturnsTIFFTag.TIFF_DOUBLEdata as an array ofdoubles (64-bit floating-point values).floatgetAsFloat(int index) Returns data in any format as afloat.float[]ReturnsTIFFTag.TIFF_FLOATdata as an array offloats (32-bit floating-point values).intgetAsInt(int index) Returns data in any format as anint.int[]ReturnsTIFFTag.TIFF_SLONGdata as an array ofints (signed 32-bit integers).longgetAsLong(int index) Returns data in any format as along.long[]ReturnsTIFFTag.TIFF_LONGorTIFF_IFD_POINTERdata as an array oflongs (signed 64-bit integers).Returns theTIFFFieldas a node named either"TIFFField"or"TIFFIFD"as described in the TIFF native image metadata specification.long[]getAsRational(int index) Returns a TIFFTag.TIFF_RATIONAL data item as a two-element array of ints.long[][]ReturnsTIFFTag.TIFF_RATIONALdata as an array of 2-element arrays oflongs.short[]ReturnsTIFFTag.TIFF_SSHORTdata as an array ofshorts (signed 16-bit integers).int[]getAsSRational(int index) Returns aTIFFTag.TIFF_SRATIONALdata item as a two-element array ofints.int[][]ReturnsTIFFTag.TIFF_SRATIONALdata as an array of 2-element arrays ofints.getAsString(int index) Returns aTIFFTag.TIFF_ASCIIvalue as aString.intgetCount()Returns the number of data items present in the field.getData()Returns a reference to the data object associated with the field.Returns the associatedTIFFDirectory, if available.getTag()Retrieves the tag associated with this field.intRetrieves the tag number in the range[0,65535].intgetType()Returns the type of the data stored in the field.static intgetTypeByName(String typeName) Returns the data type constant corresponding to the supplied data type name.static StringgetTypeName(int dataType) Returns the name of the supplied data type constant.getValueAsString(int index) Returns aStringcontaining a human-readable version of the data item.booleanReturns whether the field has aTIFFDirectory.booleanIndicates whether the value associated with the field is of integral data type.
- 
Constructor Details- 
TIFFFieldConstructs aTIFFFieldwith arbitrary data. Thetypeparameter must be a value for whichtag.isDataTypeOK()returnstrue. Thedataparameter must be an array of a Java type appropriate for the type of the TIFF field.Note that the value (data) of the TIFFFieldwill always be the actual field value regardless of the number of bytes required for that value. This is the case despite the fact that the TIFF IFD Entry corresponding to the field may actually contain the offset to the value of the field rather than the value itself (the latter occurring if and only if the value fits into 4 bytes). In other words, the value of the field will already have been read from the TIFF stream. (An exception to this case may occur when the field represents the contents of a non-baseline IFD. In that case the data will be along[]containing the offset to the IFD and theTIFFDirectoryreturned bygetDirectory()will be its contents.)- Parameters:
- tag- The tag to associated with this field.
- type- One of the- TIFFTag.TIFF_*constants indicating the data type of the field as written to the TIFF stream.
- count- The number of data values.
- data- The actual data content of the field.
- Throws:
- NullPointerException- if- tag == null.
- IllegalArgumentException- if- typeis not one of the- TIFFTag.TIFF_*data type constants.
- IllegalArgumentException- if- typeis an unacceptable data type for the supplied- TIFFTag.
- IllegalArgumentException- if- count < 0.
- IllegalArgumentException- if- count < 1and- typeis- TIFF_RATIONALor- TIFF_SRATIONAL.
- IllegalArgumentException- if- count != 1and- typeis- TIFF_IFD_POINTER.
- NullPointerException- if- data == null.
- IllegalArgumentException- if- datais an instance of a class incompatible with the specified type.
- IllegalArgumentException- if the size of the data array is wrong.
- IllegalArgumentException- if the type of the data array is- TIFF_LONG,- TIFF_RATIONAL, or- TIFF_IFD_POINTERand any of the elements is negative or greater than- 0xffffffff.
 
- 
TIFFFieldConstructs a data array usingcreateArrayForType()and invokesTIFFField(TIFFTag,int,int,Object)with the supplied parameters and the created array.- Parameters:
- tag- The tag to associated with this field.
- type- One of the- TIFFTag.TIFF_*constants indicating the data type of the field as written to the TIFF stream.
- count- The number of data values.
- Throws:
- NullPointerException- if- tag == null.
- IllegalArgumentException- if- typeis not one of the- TIFFTag.TIFF_*data type constants.
- IllegalArgumentException- if- typeis an unacceptable data type for the supplied- TIFFTag.
- IllegalArgumentException- if- count < 0.
- IllegalArgumentException- if- count < 1and- typeis- TIFF_RATIONALor- TIFF_SRATIONAL.
- IllegalArgumentException- if- count != 1and- typeis- TIFF_IFD_POINTER.
- See Also:
 
- 
TIFFFieldConstructs aTIFFFieldwith a single non-negative integral value. The field will have typeTIFF_SHORTifvalueis in[0,0xffff], and typeTIFF_LONGifvalueis in[0x10000,0xffffffff]. The count of the field will be unity.- Parameters:
- tag- The tag to associate with this field.
- value- The value to associate with this field.
- Throws:
- NullPointerException- if- tag == null.
- IllegalArgumentException- if- valueis not in- [0,0xffffffff].
- IllegalArgumentException- if- valueis in- [0,0xffff]and- TIFF_SHORTis an unacceptable type for the- TIFFTag, or if- valueis in- [0x10000,0xffffffff]and- TIFF_LONGis an unacceptable type for the- TIFFTag.
 
- 
TIFFFieldConstructs aTIFFFieldwith an IFD offset and contents. The offset will be stored as the data of this field aslong[] {offset}. The directory will not be cloned. The count of the field will be unity.- Parameters:
- tag- The tag to associated with this field.
- type- One of the constants- TIFFTag.TIFF_LONGor- TIFFTag.TIFF_IFD_POINTER.
- offset- The IFD offset.
- dir- The directory.
- Throws:
- NullPointerException- if- tag == null.
- IllegalArgumentException- if- typeis an unacceptable data type for the supplied- TIFFTag.
- IllegalArgumentException- if- typeis neither- TIFFTag.TIFF_LONGnor- TIFFTag.TIFF_IFD_POINTER.
- IllegalArgumentException- if- offset <= 0.
- NullPointerException- if- dir == null.
- See Also:
 
 
- 
- 
Method Details- 
createFromMetadataNodeCreates aTIFFFieldfrom a TIFF native image metadata node. If the value of the"number"attribute of the node is not found intagSetthen a newTIFFTagwith nameTIFFTag.UNKNOWN_TAG_NAMEwill be created and assigned to the field.- Parameters:
- tagSet- The- TIFFTagSetto which the- TIFFTagof the field belongs.
- node- A native TIFF image metadata- TIFFFieldnode.
- Returns:
- A new TIFFField.
- Throws:
- IllegalArgumentException- If the- Nodeparameter content does not adhere to the- TIFFFieldelement structure defined by the TIFF native image metadata format specification, or if the combination of node attributes and data is not legal per the- TIFFField(TIFFTag,int,int,Object)constructor specification. Note that a cause might be set on such an exception.
 
- 
getTagRetrieves the tag associated with this field.- Returns:
- The associated TIFFTag.
 
- 
getTagNumberpublic int getTagNumber()Retrieves the tag number in the range[0,65535].- Returns:
- The tag number.
 
- 
getTypepublic int getType()Returns the type of the data stored in the field. For a TIFF 6.0 stream, the value will equal one of theTIFFTag.TIFF_*constants. For future revisions of TIFF, higher values are possible.- Returns:
- The data type of the field value.
 
- 
getTypeNameReturns the name of the supplied data type constant.- Parameters:
- dataType- One of the- TIFFTag.TIFF_*constants indicating the data type of the field as written to the TIFF stream.
- Returns:
- The type name corresponding to the supplied type constant.
- Throws:
- IllegalArgumentException- if- dataTypeis not one of the- TIFFTag.TIFF_*data type constants.
 
- 
getTypeByNameReturns the data type constant corresponding to the supplied data type name. If the name is unknown-1will be returned.- Parameters:
- typeName- The type name.
- Returns:
- One of the TIFFTag.TIFF_*constants or-1if the name is not recognized.
 
- 
createArrayForTypeCreates an array appropriate for the indicated data type.- Parameters:
- dataType- One of the- TIFFTag.TIFF_*data type constants.
- count- The number of values in the array.
- Returns:
- An array appropriate for the specified data type.
- Throws:
- IllegalArgumentException- if- dataTypeis not one of the- TIFFTag.TIFF_*data type constants.
- IllegalArgumentException- if- count < 0.
- IllegalArgumentException- if- count < 1and- typeis- TIFF_RATIONALor- TIFF_SRATIONAL.
- IllegalArgumentException- if- count != 1and- typeis- TIFF_IFD_POINTER.
 
- 
getAsNativeNodeReturns theTIFFFieldas a node named either"TIFFField"or"TIFFIFD"as described in the TIFF native image metadata specification. The node will be named"TIFFIFD"if and only ifhasDirectory()returnstrueand the field's type is eitherTIFFTag.TIFF_LONGorTIFFTag.TIFF_IFD_POINTER.- Returns:
- a Nodenamed"TIFFField"or"TIFFIFD".
 
- 
isIntegralpublic boolean isIntegral()Indicates whether the value associated with the field is of integral data type.- Returns:
- Whether the field type is integral.
 
- 
getCountpublic int getCount()Returns the number of data items present in the field. ForTIFFTag.TIFF_ASCIIfields, the value returned is the number ofStrings, not the total length of the data as in the file representation.- Returns:
- The number of data items present in the field.
 
- 
getDataReturns a reference to the data object associated with the field.- Returns:
- The data object of the field.
 
- 
getAsBytespublic byte[] getAsBytes()Returns the data as an uninterpreted array ofbytes. The type of the field must be one ofTIFFTag.TIFF_BYTE,TIFF_SBYTE, orTIFF_UNDEFINED.For data in TIFFTag.TIFF_BYTEformat, the application must take care when promoting the data to longer integral types to avoid sign extension.- Returns:
- The data as an uninterpreted array of bytes.
- Throws:
- ClassCastException- if the field is not of type- TIFF_BYTE,- TIFF_SBYTE, or- TIFF_UNDEFINED.
 
- 
getAsCharspublic char[] getAsChars()ReturnsTIFFTag.TIFF_SHORTdata as an array ofchars (unsigned 16-bit integers).- Returns:
- The data as an array of chars.
- Throws:
- ClassCastException- if the field is not of type- TIFF_SHORT.
 
- 
getAsShortspublic short[] getAsShorts()ReturnsTIFFTag.TIFF_SSHORTdata as an array ofshorts (signed 16-bit integers).- Returns:
- The data as an array of shorts.
- Throws:
- ClassCastException- if the field is not of type- TIFF_SSHORT.
 
- 
getAsIntspublic int[] getAsInts()ReturnsTIFFTag.TIFF_SLONGdata as an array ofints (signed 32-bit integers).- Returns:
- The data as an array of ints.
- Throws:
- ClassCastException- if the field is not of type- TIFF_SHORT,- TIFF_SSHORT, or- TIFF_SLONG.
 
- 
getAsLongspublic long[] getAsLongs()ReturnsTIFFTag.TIFF_LONGorTIFF_IFD_POINTERdata as an array oflongs (signed 64-bit integers).- Returns:
- The data as an array of longs.
- Throws:
- ClassCastException- if the field is not of type- TIFF_LONGor- TIFF_IFD_POINTER.
 
- 
getAsFloatspublic float[] getAsFloats()ReturnsTIFFTag.TIFF_FLOATdata as an array offloats (32-bit floating-point values).- Returns:
- The data as an array of floats.
- Throws:
- ClassCastException- if the field is not of type- TIFF_FLOAT.
 
- 
getAsDoublespublic double[] getAsDoubles()ReturnsTIFFTag.TIFF_DOUBLEdata as an array ofdoubles (64-bit floating-point values).- Returns:
- The data as an array of doubles.
- Throws:
- ClassCastException- if the field is not of type- TIFF_DOUBLE.
 
- 
getAsSRationalspublic int[][] getAsSRationals()ReturnsTIFFTag.TIFF_SRATIONALdata as an array of 2-element arrays ofints.- Returns:
- The data as an array of signed rationals.
- Throws:
- ClassCastException- if the field is not of type- TIFF_SRATIONAL.
 
- 
getAsRationalspublic long[][] getAsRationals()ReturnsTIFFTag.TIFF_RATIONALdata as an array of 2-element arrays oflongs.- Returns:
- The data as an array of unsigned rationals.
- Throws:
- ClassCastException- if the field is not of type- TIFF_RATIONAL.
 
- 
getAsIntpublic int getAsInt(int index) Returns data in any format as anint.TIFFTag.TIFF_BYTEvalues are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255].TIFF_SBYTEdata will be returned in the range [-128, 127].A TIFF_UNDEFINEDvalue is treated as though it were aTIFF_BYTE.Data in TIFF_SLONG,TIFF_LONG,TIFF_FLOAT,TIFF_DOUBLEorTIFF_IFD_POINTERformat are simply cast tointand may suffer from truncation.Data in TIFF_SRATIONALorTIFF_RATIONALformat are evaluated by dividing the numerator into the denominator using double-precision arithmetic and then casting toint. Loss of precision and truncation may occur.Data in TIFF_ASCIIformat will be parsed as by theDouble.parseDoublemethod, with the result case toint.- Parameters:
- index- The index of the data.
- Returns:
- The data at the given index as an int.
 
- 
getAsLongpublic long getAsLong(int index) Returns data in any format as along.TIFFTag.TIFF_BYTEandTIFF_UNDEFINEDdata are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255].TIFF_SBYTEdata will be returned in the range [-128, 127].Data in TIFF_FLOATandTIFF_DOUBLEare simply cast tolongand may suffer from truncation.Data in TIFF_SRATIONALorTIFF_RATIONALformat are evaluated by dividing the numerator into the denominator using double-precision arithmetic and then casting tolong. Loss of precision and truncation may occur.Data in TIFF_ASCIIformat will be parsed as by theDouble.parseDoublemethod, with the result cast tolong.- Parameters:
- index- The index of the data.
- Returns:
- The data at the given index as a long.
 
- 
getAsFloatpublic float getAsFloat(int index) Returns data in any format as afloat.TIFFTag.TIFF_BYTEandTIFF_UNDEFINEDdata are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255].TIFF_SBYTEdata will be returned in the range [-128, 127].Data in TIFF_SLONG,TIFF_LONG,TIFF_DOUBLE, orTIFF_IFD_POINTERformat are simply cast tofloatand may suffer from truncation.Data in TIFF_SRATIONALorTIFF_RATIONALformat are evaluated by dividing the numerator into the denominator using double-precision arithmetic and then casting tofloat.Data in TIFF_ASCIIformat will be parsed as by theDouble.parseDoublemethod, with the result cast tofloat.- Parameters:
- index- The index of the data.
- Returns:
- The data at the given index as a float.
 
- 
getAsDoublepublic double getAsDouble(int index) Returns data in any format as adouble.TIFFTag.TIFF_BYTEandTIFF_UNDEFINEDdata are treated as unsigned; that is, no sign extension will take place and the returned value will be in the range [0, 255].TIFF_SBYTEdata will be returned in the range [-128, 127].Data in TIFF_SRATIONALorTIFF_RATIONALformat are evaluated by dividing the numerator into the denominator using double-precision arithmetic.Data in TIFF_ASCIIformat will be parsed as by theDouble.parseDoublemethod.- Parameters:
- index- The index of the data.
- Returns:
- The data at the given index as a double.
 
- 
getAsStringReturns aTIFFTag.TIFF_ASCIIvalue as aString.- Parameters:
- index- The index of the data.
- Returns:
- The data at the given index as a String.
- Throws:
- ClassCastException- if the field is not of type- TIFF_ASCII.
 
- 
getAsSRationalpublic int[] getAsSRational(int index) Returns aTIFFTag.TIFF_SRATIONALdata item as a two-element array ofints.- Parameters:
- index- The index of the data.
- Returns:
- The data at the given index as a signed rational.
- Throws:
- ClassCastException- if the field is not of type- TIFF_SRATIONAL.
 
- 
getAsRationalpublic long[] getAsRational(int index) Returns a TIFFTag.TIFF_RATIONAL data item as a two-element array of ints.- Parameters:
- index- The index of the data.
- Returns:
- The data at the given index as an unsigned rational.
- Throws:
- ClassCastException- if the field is not of type- TIFF_RATIONAL.
 
- 
getValueAsStringReturns aStringcontaining a human-readable version of the data item. Data of typeTIFFTag.TIFF_RATIONALorTIFF_SRATIONALare represented as a pair of integers separated by a'/'character. If the numerator of aTIFFTag.TIFF_RATIONALorTIFF_SRATIONALis an integral multiple of the denominator, then the value is represented as"q/1"whereqis the quotient of the numerator and denominator.- Parameters:
- index- The index of the data.
- Returns:
- The data at the given index as a String.
- Throws:
- ClassCastException- if the field is not of one of the legal field types.
 
- 
hasDirectorypublic boolean hasDirectory()Returns whether the field has aTIFFDirectory.- Returns:
- true if and only if getDirectory() returns non-null.
 
- 
getDirectoryReturns the associatedTIFFDirectory, if available. If no directory is set, thennullwill be returned.- Returns:
- the TIFFDirectory instance or null.
 
- 
cloneClones the field and all the information contained therein.- Overrides:
- clonein class- Object
- Returns:
- A clone of this TIFFField.
- Throws:
- CloneNotSupportedException- if the instance cannot be cloned.
- See Also:
 
 
-