this.header = header;
//Double check
if (!header.getId().equals(IDENTIFIER))
{
throw new RuntimeException("Unable to process data box because identifier is:" + header.getId());
}
//Make slice so operations here don't effect position of main buffer
this.dataBuffer = dataBuffer.slice();
//Type
type = Utils.getIntBE(this.dataBuffer, Mp4DataBox.TYPE_POS, Mp4DataBox.TYPE_POS + Mp4DataBox.TYPE_LENGTH - 1);
if (type == Mp4FieldType.TEXT.getFileClassId())
{
content = Utils.getString(this.dataBuffer, PRE_DATA_LENGTH, header.getDataLength() - PRE_DATA_LENGTH, header.getEncoding());
}
else if (type == Mp4FieldType.IMPLICIT.getFileClassId())
{
numbers = new ArrayList<Short>();
for (int i = 0; i < ((header.getDataLength() - PRE_DATA_LENGTH) / NUMBER_LENGTH); i++)
{
short number = Utils.getShortBE(this.dataBuffer, PRE_DATA_LENGTH + (i * NUMBER_LENGTH), PRE_DATA_LENGTH + (i * NUMBER_LENGTH) + (NUMBER_LENGTH - 1));
numbers.add(number);
}
//Make String representation (separate values with slash)
StringBuffer sb = new StringBuffer();
ListIterator<Short> iterator = numbers.listIterator();
while (iterator.hasNext())
{
sb.append(iterator.next());
if (iterator.hasNext())
{
sb.append("/");
}
}
content = sb.toString();
}
else if (type == Mp4FieldType.INTEGER.getFileClassId())
{
//TODO byte data length seems to be 1 for pgap and cpil but 2 for tmpo ?
//Create String representation for display
content = Utils.getIntBE(this.dataBuffer, PRE_DATA_LENGTH, header.getDataLength() - 1) + "";
//But store data for safer writing back to file
bytedata = new byte[header.getDataLength() - PRE_DATA_LENGTH];
int pos = dataBuffer.position();
dataBuffer.position(pos + PRE_DATA_LENGTH);
dataBuffer.get(bytedata);
dataBuffer.position(pos);
//Songbird uses this type for trkn atom (normally implicit type) is used so just added this code so can be used
//by the Mp4TrackField atom
numbers = new ArrayList<Short>();
for (int i = 0; i < ((header.getDataLength() - PRE_DATA_LENGTH) / NUMBER_LENGTH); i++)
{
short number = Utils.getShortBE(this.dataBuffer, PRE_DATA_LENGTH + (i * NUMBER_LENGTH), PRE_DATA_LENGTH + (i * NUMBER_LENGTH) + (NUMBER_LENGTH - 1));
numbers.add(number);
}
}
else if (type == Mp4FieldType.COVERART_JPEG.getFileClassId())
{
content = Utils.getString(this.dataBuffer, PRE_DATA_LENGTH, header.getDataLength() - PRE_DATA_LENGTH, header.getEncoding());
}