FileDocCategorySizeDatePackage
Mp4TagReverseDnsField.javaAPI DocJaudiotagger 2.0.49394Wed Mar 30 16:12:10 BST 2011org.jaudiotagger.tag.mp4.field

Mp4TagReverseDnsField

public class Mp4TagReverseDnsField extends org.jaudiotagger.tag.mp4.Mp4TagField implements org.jaudiotagger.tag.TagTextField
Represents reverse dns field, used for custom information

Originally only used by Itunes for information that was iTunes specific but now used in a wide range of uses, for example Musicbrainz uses it for many of its fields.

These fields have a more complex setup Box ---- shows this is a reverse dns metadata field Box mean the issuer in the form of reverse DNS domain (e.g com.apple.iTunes) Box name descriptor identifying the type of contents Box data contents

The raw data passed starts from the mean box

Fields Summary
public static final String
IDENTIFIER
protected int
dataSize
private String
issuer
private String
descriptor
protected String
content
Constructors Summary
public Mp4TagReverseDnsField(org.jaudiotagger.audio.mp4.atom.Mp4BoxHeader parentHeader, ByteBuffer data)
Construct from existing file data

param
parentHeader
param
data
throws
UnsupportedEncodingException


                    
          
    
        super(parentHeader, data);
    
public Mp4TagReverseDnsField(org.jaudiotagger.tag.mp4.Mp4FieldKey id, String content)
Newly created Reverse Dns field

param
id
param
content

        super(id.getFieldName());
        this.issuer = id.getIssuer();
        this.descriptor = id.getIdentifier();
        this.content = content;
    
public Mp4TagReverseDnsField(String fieldName, String issuer, String identifier, String content)
Newly created Reverse Dns field bypassing the Mp4TagField enum for creation of temporary reverse dns fields

param
fieldName
param
issuer
param
identifier
param
content

        super(fieldName);
        this.issuer     = issuer;
        this.descriptor = identifier;
        this.content    = content;
    
Methods Summary
protected voidbuild(java.nio.ByteBuffer data)

        //Read mean box, set the issuer and skip over data
        Mp4BoxHeader meanBoxHeader = new Mp4BoxHeader(data);
        Mp4MeanBox meanBox = new Mp4MeanBox(meanBoxHeader, data);
        setIssuer(meanBox.getIssuer());
        data.position(data.position() + meanBoxHeader.getDataLength());

        //Read name box, identify what type of field it is
        Mp4BoxHeader nameBoxHeader = new Mp4BoxHeader(data);
        Mp4NameBox nameBox = new Mp4NameBox(nameBoxHeader, data);
        setDescriptor(nameBox.getName());
        data.position(data.position() + nameBoxHeader.getDataLength());

        //Issue 198:There is not actually a data atom there cannot cant be because no room for one
        if (parentHeader.getDataLength() == meanBoxHeader.getLength() + nameBoxHeader.getLength())
        {
            id = IDENTIFIER + ":" + issuer + ":" + descriptor;
            setContent("");
            logger.warning(ErrorMessage.MP4_REVERSE_DNS_FIELD_HAS_NO_DATA.getMsg(id));
        }
        //Usual Case
        else
        {
            //Read data box, identify the data
            Mp4BoxHeader dataBoxHeader = new Mp4BoxHeader(data);
            Mp4DataBox dataBox = new Mp4DataBox(dataBoxHeader, data);
            setContent(dataBox.getContent());
            data.position(data.position() + dataBoxHeader.getDataLength());

            //Now calculate the id which in order to be unique needs to use all htree values
            id = IDENTIFIER + ":" + issuer + ":" + descriptor;
        }
    
public voidcopyContent(org.jaudiotagger.tag.TagField field)

        if (field instanceof Mp4TagReverseDnsField)
        {
            this.issuer = ((Mp4TagReverseDnsField) field).getIssuer();
            this.descriptor = ((Mp4TagReverseDnsField) field).getDescriptor();
            this.content = ((Mp4TagReverseDnsField) field).getContent();
        }
    
public java.lang.StringgetContent()

return
content

        return content;
    
protected byte[]getDataBytes()

        return content.getBytes(getEncoding());
    
public java.lang.StringgetDescriptor()

return
the descriptor

        return descriptor;
    
public java.lang.StringgetEncoding()

        return Mp4BoxHeader.CHARSET_UTF_8;
    
public Mp4FieldTypegetFieldType()

        //TODO always assuming text at moment but may not always be the case (though dont have any concrete
        //examples)
        return Mp4FieldType.TEXT;
    
public java.lang.StringgetIssuer()

return
the issuer

        return issuer;
    
public byte[]getRawContent()
Convert back to raw content, includes ----,mean,name and data atom as views as one thing externally

return
throws
UnsupportedEncodingException

        try
        {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            //Create Meanbox data
            byte[] issuerRawData = issuer.getBytes(getEncoding());
            baos.write(Utils.getSizeBEInt32(Mp4BoxHeader.HEADER_LENGTH + Mp4MeanBox.PRE_DATA_LENGTH + issuerRawData.length));
            baos.write(Utils.getDefaultBytes(Mp4MeanBox.IDENTIFIER, "ISO-8859-1"));
            baos.write(new byte[]{0, 0, 0, 0});
            baos.write(issuerRawData);

            //Create Namebox data
            byte[] nameRawData = descriptor.getBytes(getEncoding());
            baos.write(Utils.getSizeBEInt32(Mp4BoxHeader.HEADER_LENGTH + Mp4NameBox.PRE_DATA_LENGTH + nameRawData.length));
            baos.write(Utils.getDefaultBytes(Mp4NameBox.IDENTIFIER, "ISO-8859-1"));
            baos.write(new byte[]{0, 0, 0, 0});
            baos.write(nameRawData);

            //Create DataBox data if we have data only
            if (content.length() > 0)
            {
                baos.write(getRawContentDataOnly());
            }
            //Now wrap with reversedns box
            ByteArrayOutputStream outerbaos = new ByteArrayOutputStream();
            outerbaos.write(Utils.getSizeBEInt32(Mp4BoxHeader.HEADER_LENGTH + baos.size()));
            outerbaos.write(Utils.getDefaultBytes(IDENTIFIER, "ISO-8859-1"));
            outerbaos.write(baos.toByteArray());
            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()

        logger.fine("Getting Raw data for:" + getId());
        try
        {
            //Create DataBox data
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] dataRawData = content.getBytes(getEncoding());
            baos.write(Utils.getSizeBEInt32(Mp4BoxHeader.HEADER_LENGTH + Mp4DataBox.PRE_DATA_LENGTH + dataRawData.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(dataRawData);
            return baos.toByteArray();
        }
        catch (IOException ioe)
        {
            //This should never happen as were not actually writing to/from a file
            throw new RuntimeException(ioe);
        }
    
public booleanisBinary()

        return false;
    
public booleanisEmpty()

        return this.content.trim().equals("");
    
public voidsetContent(java.lang.String s)

        this.content = s;
    
public voidsetDescriptor(java.lang.String descriptor)
Set the descriptor for the data (what type of data it is)

param
descriptor

        this.descriptor = descriptor;
    
public voidsetEncoding(java.lang.String s)

        /* Not allowed */
    
public voidsetIssuer(java.lang.String issuer)
Set the issuer, usually reverse dns of the Companies domain

param
issuer

        this.issuer = issuer;
    
public java.lang.StringtoString()

        return content;