/** * Write to Byte Array * * @return the datatype converted to a byte array */ public byte[] writeByteArray() { int size = getSize(); byte[] arr; if (size == 0) { arr = new byte[0]; } else { long temp = ID3Tags.getWholeNumber(value); arr = new byte[size]; // keeps shifting the number downwards and masking the last 8 bist to get the value for the // next byte // to be written for (int i = size - 1; i >= 0; i--) { arr[i] = (byte) (temp & 0xFF); temp >>= 8; } } return arr; }
/** @return the number of bytes required to write this to a file */ public int getSize() { if (value == null) { return 0; } else { int current; long temp = ID3Tags.getWholeNumber(value); int size = 0; for (int i = MINIMUM_NO_OF_DIGITS; i <= MAXIMUM_NO_OF_DIGITS; i++) { current = (byte) temp & 0xFF; if (current != 0) { size = i; } temp >>= MAXIMUM_NO_OF_DIGITS; } return (minLength > size) ? minLength : size; } }