FileDocCategorySizeDatePackage
NumberFixedLength.javaAPI DocJaudiotagger 2.0.45452Wed Jun 08 12:05:40 BST 2011org.jaudiotagger.tag.datatype

NumberFixedLength

public class NumberFixedLength extends AbstractDataType
Represents a number held as a fixed number of digits.

The bitorder in ID3v2 is most significant bit first (MSB). The byteorder in multibyte numbers is most significant byte first (e.g. $12345678 would be encoded $12 34 56 78), also known as big endian and network byte order.

In ID3Specification would be denoted as $xx xx this denotes exactly two bytes required

Fields Summary
Constructors Summary
public NumberFixedLength(String identifier, org.jaudiotagger.tag.id3.AbstractTagFrameBody frameBody, int size)
Creates a new ObjectNumberFixedLength datatype.

param
identifier
param
frameBody
param
size the number of significant places that the number is held to
throws
IllegalArgumentException

        super(identifier, frameBody);
        if (size < 0)
        {
            throw new IllegalArgumentException("Length is less than zero: " + size);
        }
        this.size = size;

    
public NumberFixedLength(NumberFixedLength copy)

        super(copy);
        this.size = copy.size;
    
Methods Summary
public booleanequals(java.lang.Object obj)

param
obj
return
true if obj equivalent to this

        if (!(obj instanceof NumberFixedLength))
        {
            return false;
        }
        NumberFixedLength object = (NumberFixedLength) obj;
        return this.size == object.size && super.equals(obj);
    
public intgetSize()
Return size

return
the size of this number

        return size;
    
public voidreadByteArray(byte[] arr, int offset)
Read the number from the byte array

param
arr
param
offset
throws
NullPointerException
throws
IndexOutOfBoundsException

        if (arr == null)
        {
            throw new NullPointerException("Byte array is null");
        }
        if ((offset < 0) || (offset >= arr.length))
        {
            throw new InvalidDataTypeException("Offset to byte array is out of bounds: offset = " + offset + ", array.length = " + arr.length);
        }

        if(offset + size > arr.length)
        {
            throw new InvalidDataTypeException("Offset plus size to byte array is out of bounds: offset = "
                    + offset + ", size = "+size  +" + arr.length "+ arr.length );
        }

        long lvalue = 0;
        for (int i = offset; i < (offset + size); i++)
        {
            lvalue <<= 8;
            lvalue += (arr[i] & 0xff);
        }
        value = lvalue;
        logger.config("Read NumberFixedlength:" + value);
    
public voidsetSize(int size)
Set Size in Bytes of this Object

param
size in bytes that this number will be held as

        if (size > 0)
        {
            this.size = size;
        }
    
public voidsetValue(java.lang.Object value)

        if (!(value instanceof Number))
        {
            throw new IllegalArgumentException("Invalid value type for NumberFixedLength:" + value.getClass());
        }
        super.setValue(value);
    
public java.lang.StringtoString()

return
String representation of this datatype

        if (value == null)
        {
            return "";
        }
        else
        {
            return value.toString();
        }
    
public byte[]writeByteArray()
Write data to byte array

return
the datatype converted to a byte array

        byte[] arr;
        arr = new byte[size];
        if (value != null)
        {
            //Convert value to long
            long temp = ID3Tags.getWholeNumber(value);

            for (int i = size - 1; i >= 0; i--)
            {
                arr[i] = (byte) (temp & 0xFF);
                temp >>= 8;
            }
        }
        return arr;