Enum Type

java.lang.Object
java.lang.Enum<Type>
org.apache.sis.storage.geotiff.Type
All Implemented Interfaces:
Serializable, Comparable<Type>, java.lang.constant.Constable

enum Type extends Enum<Type>
The types of values in a TIFF header. Provides also some support for reading a value of a given type.

Note on naming convention: the values in this enumeration are not necessarily named as the TIFF type names. This enumeration rather match the Java primitive type names.

Since:
0.8
Version:
1.2
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    8-bits byte that contains a 7-bit ASCII code.
    An 8-bits signed (twos-complement) integer.
    Double precision (8-bytes) IEEE format.
    Single precision (4-bytes) IEEE format.
    A 32-bits (4-bytes) signed (twos-complement) integer.
    A 64-bits (8-bytes) signed (twos-complement) integer.
    Two signed integers: the first represents the numerator of a fraction; the second, the denominator.
    A 16-bits (2-bytes) signed (twos-complement) integer.
    A 8-bits unsigned integer.
    32-bits (4-bytes) unsigned integer.
    A 64-bits (8-bytes) unsigned integer.
    An 8-bits byte that may contain anything, depending on the definition of the field.
    Two unsigned integers: the first represents the numerator of a fraction; the second, the denominator.
    A 16-bits (2-bytes) unsigned integer.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) final int
    The TIFF numerical code for this type.
    private static final Type[]
    All types known to this enumeration in an array where the index is the GeoTIFF numerical code.
    (package private) final boolean
    Whether this type is an unsigned integer.
    (package private) final int
    The size of this type, in number of bytes.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Type(int code, int size, boolean isUnsigned)
    Creates a new enumeration
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) final String
    Formats an error message for a value that cannot be converted.
    (package private) static void
    ensureSingleton(double previous, double actual, long count)
    Same as ensureSingleton(long, long, long) but with floating-point values.
    (package private) static void
    ensureSingleton(long previous, long actual, long count)
    Invoked by read(…) method implementations for verifying that the count argument value is 1.
    readArray(ChannelDataInput input, int count)
    Reads an arbitrary number of values as a Java array.
    double
    readDouble(ChannelDataInput input, long count)
    Reads a single value and returns it as a double type, performing conversion if needed.
    final int
    readInt(ChannelDataInput input, long count)
    Reads a single value and returns it as a signed int type, performing conversion if needed.
    long
    readLong(ChannelDataInput input, long count)
    Reads a single value and returns it as a long type, performing conversion if needed.
    readObject(ChannelDataInput input, long count)
    Returns the value as a Vector, a Number (only for fractions) or a String instance.
    final short
    readShort(ChannelDataInput input, long count)
    Reads a single value and returns it as a signed short type, performing conversion if needed.
    readString(ChannelDataInput input, long length, Charset charset)
    Reads the value as strings.
    final long
    readUnsignedLong(ChannelDataInput input, long count)
    Reads a single value which is expected to be positive.
    final Vector
    readVector(ChannelDataInput input, long count)
    Reads an arbitrary number of values as a wrapper around a Java array of primitive type.
    (package private) static String
    toString(long numerator, long denominator)
    Formats a rational number.
    (package private) static Type
    valueOf(int code)
    Returns the type for the given GeoTIFF code, or null if the given type is unknown.
    static Type
    Returns the enum constant of this type with the specified name.
    static Type[]
    Returns an array containing the constants of this enum type, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • UNDEFINED

      public static final Type UNDEFINED
      An 8-bits byte that may contain anything, depending on the definition of the field.
      • TIFF name: UNDEFINED
      • TIFF code: 7
    • BYTE

      public static final Type BYTE
      An 8-bits signed (twos-complement) integer.
      • TIFF name: SBYTE
      • TIFF code: 6
    • UBYTE

      public static final Type UBYTE
      A 8-bits unsigned integer.
      • TIFF name: BYTE
      • TIFF code: 1
    • SHORT

      public static final Type SHORT
      A 16-bits (2-bytes) signed (twos-complement) integer.
      • TIFF name: SSHORT
      • TIFF code: 8
    • USHORT

      public static final Type USHORT
      A 16-bits (2-bytes) unsigned integer.
      • TIFF name: SHORT
      • TIFF code: 3
    • INT

      public static final Type INT
      A 32-bits (4-bytes) signed (twos-complement) integer.
      • TIFF name: SLONG
      • TIFF code: 9
    • UINT

      public static final Type UINT
      32-bits (4-bytes) unsigned integer.
      • TIFF name: LONG
      • TIFF code: 4
    • LONG

      public static final Type LONG
      A 64-bits (8-bytes) signed (twos-complement) integer.
      • TIFF code: 17
    • ULONG

      public static final Type ULONG
      A 64-bits (8-bytes) unsigned integer.
      • TIFF code: 16
    • FLOAT

      public static final Type FLOAT
      Single precision (4-bytes) IEEE format.
      • TIFF name: FLOAT
      • TIFF code: 11
    • DOUBLE

      public static final Type DOUBLE
      Double precision (8-bytes) IEEE format.
      • TIFF name: DOUBLE
      • TIFF code: 12
    • RATIONAL

      public static final Type RATIONAL
      Two signed integers: the first represents the numerator of a fraction; the second, the denominator.
      • TIFF name: SRATIONAL
      • TIFF code: 10
    • URATIONAL

      public static final Type URATIONAL
      Two unsigned integers: the first represents the numerator of a fraction; the second, the denominator.
      • TIFF name: RATIONAL
      • TIFF code: 5
    • ASCII

      public static final Type ASCII
      8-bits byte that contains a 7-bit ASCII code. In a string of ASCII characters, the last byte must be NUL (binary zero). The string length (including the NUL byte) is the count field before the string. NUL bytes may also appear in the middle of the string for separating its content into multi-strings.
      • TIFF name: ASCII
      • TIFF code: 2
  • Field Details

    • code

      final int code
      The TIFF numerical code for this type.
    • size

      final int size
      The size of this type, in number of bytes.
    • isUnsigned

      final boolean isUnsigned
      Whether this type is an unsigned integer.
    • FROM_CODES

      private static final Type[] FROM_CODES
      All types known to this enumeration in an array where the index is the GeoTIFF numerical code.
  • Constructor Details

    • Type

      private Type(int code, int size, boolean isUnsigned)
      Creates a new enumeration
  • Method Details

    • values

      public static Type[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static Type valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • valueOf

      static Type valueOf(int code)
      Returns the type for the given GeoTIFF code, or null if the given type is unknown.
      Parameters:
      code - the GeoTIFF numerical code.
      Returns:
      the enumeration value that represent the given type, or null if unknown.
    • toString

      static String toString(long numerator, long denominator)
      Formats a rational number. This is a helper method for RATIONAL and URATIONAL types.
    • ensureSingleton

      static void ensureSingleton(long previous, long actual, long count)
      Invoked by read(…) method implementations for verifying that the count argument value is 1. All read methods other than readArray(…) expect exactly one value, except methods in ASCII enumeration value which are treated differently.

      While exactly one value is expected, we are tolerant to longer arrays provided that all values are the same. This is seen in practice where a value expected to apply to the image is repeated for each band.

      Parameters:
      previous - the previous value.
      actual - the actual value.
      count - the number of values to read.
      Throws:
      IllegalArgumentException - if count does not have the expected value.
    • ensureSingleton

      static void ensureSingleton(double previous, double actual, long count)
      Same as ensureSingleton(long, long, long) but with floating-point values.
    • canNotConvert

      final String canNotConvert(String value)
      Formats an error message for a value that cannot be converted.
    • readShort

      public final short readShort(ChannelDataInput input, long count) throws IOException
      Reads a single value and returns it as a signed short type, performing conversion if needed. This method should be invoked when the caller expects a single value.
      Parameters:
      input - the input from where to read the value.
      count - the amount of values (normally exactly 1).
      Returns:
      the value as a short.
      Throws:
      IOException - if an error occurred while reading the stream.
      NumberFormatException - if the value was stored in ASCII and cannot be parsed.
      ArithmeticException - if the value cannot be represented in the Java signed short type.
      IllegalArgumentException - if the value is not a singleton.
      UnsupportedOperationException - if this type is UNDEFINED.
    • readInt

      public final int readInt(ChannelDataInput input, long count) throws IOException
      Reads a single value and returns it as a signed int type, performing conversion if needed. This method should be invoked when the caller expects a single value.
      Parameters:
      input - the input from where to read the value.
      count - the amount of values (normally exactly 1).
      Returns:
      the value as an int.
      Throws:
      IOException - if an error occurred while reading the stream.
      NumberFormatException - if the value was stored in ASCII and cannot be parsed.
      ArithmeticException - if the value cannot be represented in the Java signed int type.
      IllegalArgumentException - if the value is not a singleton.
      UnsupportedOperationException - if this type is UNDEFINED.
    • readUnsignedLong

      public final long readUnsignedLong(ChannelDataInput input, long count) throws IOException
      Reads a single value which is expected to be positive. A negative value may be an encoding error in the big TIFF file, or if it was really the intended value then something greater than what we can support.
      Throws:
      IOException - if an error occurred while reading the stream.
      NumberFormatException - if the value was stored in ASCII and cannot be parsed.
      ArithmeticException - if the value cannot be represented in the Java signed long type.
      IllegalArgumentException - if the value is not a singleton.
      UnsupportedOperationException - if this type is UNDEFINED.
    • readLong

      public long readLong(ChannelDataInput input, long count) throws IOException
      Reads a single value and returns it as a long type, performing conversion if needed. This method should be invoked when the caller expect a single value.

      If the value is an ASCII type, then this method will parse the text as a number. This support of ASCII type is required for supporting the encoding used in the tags added by GDAL.

      Parameters:
      input - the input from where to read the value.
      count - the amount of values (normally exactly 1).
      Returns:
      the value as a long.
      Throws:
      IOException - if an error occurred while reading the stream.
      NumberFormatException - if the value was stored in ASCII and cannot be parsed.
      ArithmeticException - if the value cannot be represented in the Java signed long type.
      IllegalArgumentException - if the value is not a singleton.
      UnsupportedOperationException - if this type is UNDEFINED.
    • readDouble

      public double readDouble(ChannelDataInput input, long count) throws IOException
      Reads a single value and returns it as a double type, performing conversion if needed. This method should be invoked when the caller expect a single value.

      If the value is an ASCII type, then this method will parse the text as a number. This support of ASCII type is required for supporting the encoding used in the tags added by GDAL.

      Parameters:
      input - the input from where to read the value.
      count - the amount of values (normally exactly 1).
      Returns:
      the value as a double.
      Throws:
      IOException - if an error occurred while reading the stream.
      NumberFormatException - if the value was stored in ASCII and cannot be parsed.
      IllegalArgumentException - if the value is not a singleton.
      UnsupportedOperationException - if this type is UNDEFINED.
    • readString

      public String[] readString(ChannelDataInput input, long length, Charset charset) throws IOException
      Reads the value as strings. There is usually exactly one string, but an arbitrary amount is allowed.
      Parameters:
      input - the input from where to read the value.
      length - the string length, including the final NUL byte.
      charset - the character encoding (normally US ASCII).
      Returns:
      the value as a string.
      Throws:
      IOException - if an error occurred while reading the stream.
      ArithmeticException - if the given length is too large.
      UnsupportedOperationException - if this type is UNDEFINED.
    • readObject

      public Object readObject(ChannelDataInput input, long count) throws IOException
      Returns the value as a Vector, a Number (only for fractions) or a String instance. This method should be overridden by all enumeration values that do no override readArray(ChannelDataInput, int).
      Parameters:
      input - the input from where to read the values.
      count - the amount of values.
      Returns:
      the value as a Java array or a String, or null if undefined.
      Throws:
      IOException - if an error occurred while reading the stream.
    • readArray

      public Object readArray(ChannelDataInput input, int count) throws IOException
      Reads an arbitrary number of values as a Java array.
      Parameters:
      input - the input from where to read the values.
      count - the amount of values.
      Returns:
      the value as a Java array. May be an empty array.
      Throws:
      IOException - if an error occurred while reading the stream.
      UnsupportedOperationException - if this type is UNDEFINED.
    • readVector

      public final Vector readVector(ChannelDataInput input, long count) throws IOException
      Reads an arbitrary number of values as a wrapper around a Java array of primitive type. This wrapper provide a more convenient way to access array elements than the object returned by readArray(ChannelDataInput, int).
      Parameters:
      input - the input from where to read the values.
      count - the amount of values.
      Returns:
      the value as a wrapper around a Java array of primitive type.
      Throws:
      IOException - if an error occurred while reading the stream.
      ArithmeticException - if the given count is too large.
      NumberFormatException - if the value was stored in ASCII and cannot be parsed.
      UnsupportedOperationException - if this type is UNDEFINED.