FileDocCategorySizeDatePackage
Mp4DataBox.javaAPI DocJaudiotagger 2.0.45623Tue Aug 02 15:48:22 BST 2011org.jaudiotagger.tag.mp4.atom

Mp4DataBox

public class Mp4DataBox extends org.jaudiotagger.audio.mp4.atom.AbstractMp4Box
This box is used within both normal metadat boxes and ---- boxes to hold the actual data.

Format is as follows: :length (4 bytes) :name 'Data' (4 bytes) :atom version (1 byte) :atom type flags (3 bytes) :locale field (4 bytes) //Currently always zero :data

Fields Summary
public static final String
IDENTIFIER
public static final int
VERSION_LENGTH
public static final int
TYPE_LENGTH
public static final int
NULL_LENGTH
public static final int
PRE_DATA_LENGTH
public static final int
DATA_HEADER_LENGTH
public static final int
TYPE_POS
public static final int
TYPE_POS_INCLUDING_HEADER
private int
type
private String
content
public static final int
NUMBER_LENGTH
private List
numbers
private byte[]
bytedata
Constructors Summary
public Mp4DataBox(org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader header, ByteBuffer dataBuffer)

param
header parentHeader info
param
dataBuffer data of box (doesnt include parentHeader data)


                          
        
    
        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());
        }
    
Methods Summary
public byte[]getByteData()
Return raw byte data only vaid for byte fields

return
byte data

        return bytedata;
    
public java.lang.StringgetContent()

        return content;
    
public java.util.ListgetNumbers()
Return numbers, only valid for numeric fields

return
numbers

        return numbers;
    
public intgetType()


        return type;