FileDocCategorySizeDatePackage
Mp4TagField.javaAPI DocJaudiotagger 2.0.46782Wed Mar 30 16:12:10 BST 2011org.jaudiotagger.tag.mp4

Mp4TagField

public abstract class Mp4TagField extends Object implements org.jaudiotagger.tag.TagField
This abstract class represents a link between piece of data, and how it is stored as an mp4 atom

Note there isnt a one to one correspondance between a tag field and a box because some fields are represented by multiple boxes, for example many of the MusicBrainz fields use the '----' box, which in turn uses one of mean, name and data box. So an instance of a tag field maps to one item of data such as 'Title', but it may have to read multiple boxes to do this.

There are various subclasses that represent different types of fields

Fields Summary
public static Logger
logger
protected String
id
protected org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader
parentHeader
Constructors Summary
protected Mp4TagField(String id)


      
    
        this.id = id;
    
protected Mp4TagField(ByteBuffer data)
Used by subclasses that canot identify their id until after they have been built such as ReverseDnsField

param
data
throws
UnsupportedEncodingException

        build(data);
    
protected Mp4TagField(org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader parentHeader, ByteBuffer data)
Used by reverese dns when reading from file, so can identify when there is a data atom

param
parentHeader
param
data
throws
UnsupportedEncodingException

        this.parentHeader = parentHeader;
        build(data);
    
protected Mp4TagField(String id, ByteBuffer data)

        this(id);
        build(data);
    
Methods Summary
protected abstract voidbuild(java.nio.ByteBuffer data)
Processes the data and sets the position of the data buffer to just after the end of this fields data ready for processing next field.

param
data
throws
UnsupportedEncodingException

protected abstract byte[]getDataBytes()

return
the data as it is held on file
throws
UnsupportedEncodingException

public abstract org.jaudiotagger.tag.mp4.field.Mp4FieldTypegetFieldType()

return
the field type of this field

public java.lang.StringgetId()

return
field identifier

        return id;
    
protected byte[]getIdBytes()

return
field identifier as it will be held within the file

        return Utils.getDefaultBytes(getId(), "ISO-8859-1");
    
public byte[]getRawContent()
Convert back to raw content, includes parent and data atom as views as one thing externally

return
throws
UnsupportedEncodingException

        logger.fine("Getting Raw data for:" + getId());
        try
        {
            //Create Data Box
            byte[] databox = getRawContentDataOnly();

            //Wrap in Parent box
            ByteArrayOutputStream outerbaos = new ByteArrayOutputStream();
            outerbaos.write(Utils.getSizeBEInt32(Mp4BoxHeader.HEADER_LENGTH + databox.length));
            outerbaos.write(Utils.getDefaultBytes(getId(), "ISO-8859-1"));
            outerbaos.write(databox);
            return outerbaos.toByteArray();
        }
        catch (IOException ioe)
        {
            //This should never happen as were not actually writing to/from a file
            throw new RuntimeException(ioe);
        }
    
public byte[]getRawContentDataOnly()
Get raw content for the data component only

return
throws
UnsupportedEncodingException

        logger.fine("Getting Raw data for:" + getId());
        try
        {
            //Create Data Box
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] data = getDataBytes();
            baos.write(Utils.getSizeBEInt32(Mp4DataBox.DATA_HEADER_LENGTH + data.length));
            baos.write(Utils.getDefaultBytes(Mp4DataBox.IDENTIFIER, "ISO-8859-1"));
            baos.write(new byte[]{0});
            baos.write(new byte[]{0, 0, (byte) getFieldType().getFileClassId()});
            baos.write(new byte[]{0, 0, 0, 0});
            baos.write(data);
            return baos.toByteArray();
        }
        catch (IOException ioe)
        {
            //This should never happen as were not actually writing to/from a file
            throw new RuntimeException(ioe);
        }
    
public voidisBinary(boolean b)

        /* One cannot choose if an arbitrary block can be binary or not */
    
public booleanisCommon()

        return id.equals(Mp4FieldKey.ARTIST.getFieldName()) || id.equals(Mp4FieldKey.ALBUM.getFieldName()) || id.equals(Mp4FieldKey.TITLE.getFieldName()) || id.equals(Mp4FieldKey.TRACK.getFieldName()) || id.equals(Mp4FieldKey.DAY.getFieldName()) || id.equals(Mp4FieldKey.COMMENT.getFieldName()) || id.equals(Mp4FieldKey.GENRE.getFieldName());