641 * parameters and the created array. 642 * 643 * @param tag The tag to associated with this field. 644 * @param type One of the {@code TIFFTag.TIFF_*} constants 645 * indicating the data type of the field as written to the TIFF stream. 646 * @param count The number of data values. 647 * @throws NullPointerException if {@code tag == null}. 648 * @throws IllegalArgumentException if {@code type} is not 649 * one of the {@code TIFFTag.TIFF_*} data type constants. 650 * @throws IllegalArgumentException if {@code type} is an unacceptable 651 * data type for the supplied {@code TIFFTag}. 652 * @throws IllegalArgumentException if {@code count < 0}. 653 * @see #TIFFField(TIFFTag,int,int,Object) 654 */ 655 public TIFFField(TIFFTag tag, int type, int count) { 656 this(tag, type, count, createArrayForType(type, count)); 657 } 658 659 /** 660 * Constructs a {@code TIFFField} with a single non-negative integral 661 * value. 662 * The field will have type 663 * {@link TIFFTag#TIFF_SHORT TIFF_SHORT} if 664 * {@code val < 65536} and type 665 * {@link TIFFTag#TIFF_LONG TIFF_LONG} otherwise. The count 666 * of the field will be unity. 667 * 668 * @param tag The tag to associate with this field. 669 * @param value The value to associate with this field. 670 * @throws NullPointerException if {@code tag == null}. 671 * @throws IllegalArgumentException if the derived type is unacceptable 672 * for the supplied {@code TIFFTag}. 673 * @throws IllegalArgumentException if {@code value < 0}. 674 */ 675 public TIFFField(TIFFTag tag, int value) { 676 if(tag == null) { 677 throw new NullPointerException("tag == null!"); 678 } 679 if (value < 0) { 680 throw new IllegalArgumentException("value < 0!"); 681 } 682 683 this.tag = tag; 684 this.tagNumber = tag.getNumber(); 685 this.count = 1; 686 687 if (value < 65536) { 688 if (!tag.isDataTypeOK(TIFFTag.TIFF_SHORT)) { 689 throw new IllegalArgumentException("Illegal data type " 690 + TIFFTag.TIFF_SHORT + " for " + tag.getName() + " tag"); 691 } 692 this.type = TIFFTag.TIFF_SHORT; 693 char[] cdata = new char[1]; 694 cdata[0] = (char)value; 695 this.data = cdata; 696 } else { 697 if (!tag.isDataTypeOK(TIFFTag.TIFF_LONG)) { 698 throw new IllegalArgumentException("Illegal data type " 699 + TIFFTag.TIFF_LONG + " for " + tag.getName() + " tag"); 700 } 701 this.type = TIFFTag.TIFF_LONG; 702 long[] ldata = new long[1]; 703 ldata[0] = value; 704 this.data = ldata; 705 } 706 } 707 708 /** 709 * Constructs a {@code TIFFField} with an IFD offset and contents. 710 * The offset will be stored as the data of this field as 711 * {@code long[] {offset}}. The directory will not be cloned. The count 712 * of the field will be unity. 713 * 714 * @param tag The tag to associated with this field. 715 * @param type One of the constants {@code TIFFTag.TIFF_LONG} or 716 * {@code TIFFTag.TIFF_IFD_POINTER}. 717 * @param offset The IFD offset. 718 * @param dir The directory. 719 * | 641 * parameters and the created array. 642 * 643 * @param tag The tag to associated with this field. 644 * @param type One of the {@code TIFFTag.TIFF_*} constants 645 * indicating the data type of the field as written to the TIFF stream. 646 * @param count The number of data values. 647 * @throws NullPointerException if {@code tag == null}. 648 * @throws IllegalArgumentException if {@code type} is not 649 * one of the {@code TIFFTag.TIFF_*} data type constants. 650 * @throws IllegalArgumentException if {@code type} is an unacceptable 651 * data type for the supplied {@code TIFFTag}. 652 * @throws IllegalArgumentException if {@code count < 0}. 653 * @see #TIFFField(TIFFTag,int,int,Object) 654 */ 655 public TIFFField(TIFFTag tag, int type, int count) { 656 this(tag, type, count, createArrayForType(type, count)); 657 } 658 659 /** 660 * Constructs a {@code TIFFField} with a single non-negative integral 661 * value. The field will have type {@link TIFFTag#TIFF_SHORT TIFF_SHORT} 662 * if {@code value} is in {@code [0,0xffff]}, and type 663 * {@link TIFFTag#TIFF_LONG TIFF_LONG} if {@code value} is in 664 * {@code [0x10000,0xffffffff]}. The count of the field will be unity. 665 * 666 * @param tag The tag to associate with this field. 667 * @param value The value to associate with this field. 668 * @throws NullPointerException if {@code tag == null}. 669 * @throws IllegalArgumentException if {@code value} is not in 670 * {@code [0,0xffffffff]}. 671 * @throws IllegalArgumentException if {@code value} is in 672 * {@code [0,0xffff]} and {@code TIFF_SHORT} is an unacceptable type 673 * for the {@code TIFFTag}, or if {@code value} is in 674 * {@code [0x10000,0xffffffff]} and {@code TIFF_LONG} is an unacceptable 675 * type for the {@code TIFFTag}. 676 */ 677 public TIFFField(TIFFTag tag, long value) { 678 if(tag == null) { 679 throw new NullPointerException("tag == null!"); 680 } 681 if (value < 0) { 682 throw new IllegalArgumentException("value < 0!"); 683 } 684 if (value > 0xffffffffL) { 685 throw new IllegalArgumentException("value > 0xffffffff!"); 686 } 687 688 this.tag = tag; 689 this.tagNumber = tag.getNumber(); 690 this.count = 1; 691 692 if (value < 65536) { 693 if (!tag.isDataTypeOK(TIFFTag.TIFF_SHORT)) { 694 throw new IllegalArgumentException("Illegal data type " 695 + getTypeName(TIFFTag.TIFF_SHORT) + " for tag " 696 + "\"" + tag.getName() + "\""); 697 } 698 this.type = TIFFTag.TIFF_SHORT; 699 char[] cdata = new char[1]; 700 cdata[0] = (char)value; 701 this.data = cdata; 702 } else { 703 if (!tag.isDataTypeOK(TIFFTag.TIFF_LONG)) { 704 throw new IllegalArgumentException("Illegal data type " 705 + getTypeName(TIFFTag.TIFF_LONG) + " for tag " 706 + "\"" + tag.getName() + "\""); 707 } 708 this.type = TIFFTag.TIFF_LONG; 709 long[] ldata = new long[1]; 710 ldata[0] = value; 711 this.data = ldata; 712 } 713 } 714 715 /** 716 * Constructs a {@code TIFFField} with an IFD offset and contents. 717 * The offset will be stored as the data of this field as 718 * {@code long[] {offset}}. The directory will not be cloned. The count 719 * of the field will be unity. 720 * 721 * @param tag The tag to associated with this field. 722 * @param type One of the constants {@code TIFFTag.TIFF_LONG} or 723 * {@code TIFFTag.TIFF_IFD_POINTER}. 724 * @param offset The IFD offset. 725 * @param dir The directory. 726 * |