< prev index next >

src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFField.java

Print this page




 681         this.data = data;
 682     }
 683 
 684     /**
 685      * Constructs a data array using {@link #createArrayForType
 686      * createArrayForType()} and invokes
 687      * {@link #TIFFField(TIFFTag,int,int,Object)} with the supplied
 688      * parameters and the created array.
 689      *
 690      * @param tag The tag to associated with this field.
 691      * @param type One of the {@code TIFFTag.TIFF_*} constants
 692      * indicating the data type of the field as written to the TIFF stream.
 693      * @param count The number of data values.
 694      * @throws NullPointerException if {@code tag == null}.
 695      * @throws IllegalArgumentException if {@code type} is not
 696      * one of the {@code TIFFTag.TIFF_*} data type constants.
 697      * @throws IllegalArgumentException if {@code type} is an unacceptable
 698      * data type for the supplied {@code TIFFTag}.
 699      * @throws IllegalArgumentException if {@code count < 0}.
 700      * @see #TIFFField(TIFFTag,int,int,Object)





 701      */
 702     public TIFFField(TIFFTag tag, int type, int count) {
 703         this(tag, type, count, createArrayForType(type, count));
 704     }
 705 
 706     /**
 707      * Constructs a {@code TIFFField} with a single non-negative integral
 708      * value. The field will have type {@link TIFFTag#TIFF_SHORT TIFF_SHORT}
 709      * if {@code value} is in {@code [0,0xffff]}, and type
 710      * {@link TIFFTag#TIFF_LONG TIFF_LONG} if {@code value} is in
 711      * {@code [0x10000,0xffffffff]}. The count of the field will be unity.
 712      *
 713      * @param tag The tag to associate with this field.
 714      * @param value The value to associate with this field.
 715      * @throws NullPointerException if {@code tag == null}.
 716      * @throws IllegalArgumentException if {@code value} is not in
 717      * {@code [0,0xffffffff]}.
 718      * @throws IllegalArgumentException if {@code value} is in
 719      * {@code [0,0xffff]} and {@code TIFF_SHORT} is an unacceptable type
 720      * for the {@code TIFFTag}, or if {@code value} is in


 868         for (int i = TIFFTag.MIN_DATATYPE; i <= TIFFTag.MAX_DATATYPE; i++) {
 869             if (typeName.equals(TYPE_NAMES[i])) {
 870                 return i;
 871             }
 872         }
 873 
 874         return -1;
 875     }
 876 
 877     /**
 878      * Creates an array appropriate for the indicated data type.
 879      *
 880      * @param dataType One of the {@code TIFFTag.TIFF_*} data type
 881      * constants.
 882      * @param count The number of values in the array.
 883      * @return An array appropriate for the specified data type.
 884      *
 885      * @throws IllegalArgumentException if {@code dataType} is not
 886      * one of the {@code TIFFTag.TIFF_*} data type constants.
 887      * @throws IllegalArgumentException if {@code count < 0}.





 888      */
 889     public static Object createArrayForType(int dataType, int count) {

 890         if(count < 0) {
 891             throw new IllegalArgumentException("count < 0!");








 892         }

 893         switch (dataType) {
 894         case TIFFTag.TIFF_BYTE:
 895         case TIFFTag.TIFF_SBYTE:
 896         case TIFFTag.TIFF_UNDEFINED:
 897             return new byte[count];
 898         case TIFFTag.TIFF_ASCII:
 899             return new String[count];
 900         case TIFFTag.TIFF_SHORT:
 901             return new char[count];
 902         case TIFFTag.TIFF_LONG:
 903         case TIFFTag.TIFF_IFD_POINTER:
 904             return new long[count];
 905         case TIFFTag.TIFF_RATIONAL:
 906             return new long[count][2];
 907         case TIFFTag.TIFF_SSHORT:
 908             return new short[count];
 909         case TIFFTag.TIFF_SLONG:
 910             return new int[count];
 911         case TIFFTag.TIFF_SRATIONAL:
 912             return new int[count][2];




 681         this.data = data;
 682     }
 683 
 684     /**
 685      * Constructs a data array using {@link #createArrayForType
 686      * createArrayForType()} and invokes
 687      * {@link #TIFFField(TIFFTag,int,int,Object)} with the supplied
 688      * parameters and the created array.
 689      *
 690      * @param tag The tag to associated with this field.
 691      * @param type One of the {@code TIFFTag.TIFF_*} constants
 692      * indicating the data type of the field as written to the TIFF stream.
 693      * @param count The number of data values.
 694      * @throws NullPointerException if {@code tag == null}.
 695      * @throws IllegalArgumentException if {@code type} is not
 696      * one of the {@code TIFFTag.TIFF_*} data type constants.
 697      * @throws IllegalArgumentException if {@code type} is an unacceptable
 698      * data type for the supplied {@code TIFFTag}.
 699      * @throws IllegalArgumentException if {@code count < 0}.
 700      * @see #TIFFField(TIFFTag,int,int,Object)
 701      * @throws IllegalArgumentException if {@code count < 1}
 702      * and {@code type} is {@code TIFF_RATIONAL} or
 703      * {@code TIFF_SRATIONAL}.
 704      * @throws IllegalArgumentException if {@code count != 1}
 705      * and {@code type} is {@code TIFF_IFD_POINTER}.
 706      */
 707     public TIFFField(TIFFTag tag, int type, int count) {
 708         this(tag, type, count, createArrayForType(type, count));
 709     }
 710 
 711     /**
 712      * Constructs a {@code TIFFField} with a single non-negative integral
 713      * value. The field will have type {@link TIFFTag#TIFF_SHORT TIFF_SHORT}
 714      * if {@code value} is in {@code [0,0xffff]}, and type
 715      * {@link TIFFTag#TIFF_LONG TIFF_LONG} if {@code value} is in
 716      * {@code [0x10000,0xffffffff]}. The count of the field will be unity.
 717      *
 718      * @param tag The tag to associate with this field.
 719      * @param value The value to associate with this field.
 720      * @throws NullPointerException if {@code tag == null}.
 721      * @throws IllegalArgumentException if {@code value} is not in
 722      * {@code [0,0xffffffff]}.
 723      * @throws IllegalArgumentException if {@code value} is in
 724      * {@code [0,0xffff]} and {@code TIFF_SHORT} is an unacceptable type
 725      * for the {@code TIFFTag}, or if {@code value} is in


 873         for (int i = TIFFTag.MIN_DATATYPE; i <= TIFFTag.MAX_DATATYPE; i++) {
 874             if (typeName.equals(TYPE_NAMES[i])) {
 875                 return i;
 876             }
 877         }
 878 
 879         return -1;
 880     }
 881 
 882     /**
 883      * Creates an array appropriate for the indicated data type.
 884      *
 885      * @param dataType One of the {@code TIFFTag.TIFF_*} data type
 886      * constants.
 887      * @param count The number of values in the array.
 888      * @return An array appropriate for the specified data type.
 889      *
 890      * @throws IllegalArgumentException if {@code dataType} is not
 891      * one of the {@code TIFFTag.TIFF_*} data type constants.
 892      * @throws IllegalArgumentException if {@code count < 0}.
 893      * @throws IllegalArgumentException if {@code count < 1}
 894      * and {@code type} is {@code TIFF_RATIONAL} or
 895      * {@code TIFF_SRATIONAL}.
 896      * @throws IllegalArgumentException if {@code count != 1}
 897      * and {@code type} is {@code TIFF_IFD_POINTER}.
 898      */
 899     public static Object createArrayForType(int dataType, int count) {
 900 
 901         if(count < 0) {
 902             throw new IllegalArgumentException("count < 0!");
 903         } else if((dataType == TIFFTag.TIFF_RATIONAL
 904                    || dataType == TIFFTag.TIFF_SRATIONAL)
 905                   && count < 1) {
 906             throw new IllegalArgumentException
 907                 ("Type is TIFF_RATIONAL or TIFF_SRATIONAL and count < 1");
 908         } else if (dataType == TIFFTag.TIFF_IFD_POINTER && count != 1) {
 909             throw new IllegalArgumentException
 910                 ("Type is TIFF_IFD_POINTER count != 1");
 911         }
 912 
 913         switch (dataType) {
 914         case TIFFTag.TIFF_BYTE:
 915         case TIFFTag.TIFF_SBYTE:
 916         case TIFFTag.TIFF_UNDEFINED:
 917             return new byte[count];
 918         case TIFFTag.TIFF_ASCII:
 919             return new String[count];
 920         case TIFFTag.TIFF_SHORT:
 921             return new char[count];
 922         case TIFFTag.TIFF_LONG:
 923         case TIFFTag.TIFF_IFD_POINTER:
 924             return new long[count];
 925         case TIFFTag.TIFF_RATIONAL:
 926             return new long[count][2];
 927         case TIFFTag.TIFF_SSHORT:
 928             return new short[count];
 929         case TIFFTag.TIFF_SLONG:
 930             return new int[count];
 931         case TIFFTag.TIFF_SRATIONAL:
 932             return new int[count][2];


< prev index next >