FileDocCategorySizeDatePackage
ID3v1TagField.javaAPI DocJaudiotagger 2.0.46105Wed Mar 30 16:12:06 BST 2011org.jaudiotagger.tag.id3

ID3v1TagField

public class ID3v1TagField extends Object implements org.jaudiotagger.tag.TagTextField
This class encapsulates the name and content of a tag entry in id3 fields
author
@author Raphael Slinckx (KiKiDonK)
author
Christian Laireiter (liree)

Fields Summary
private boolean
common
If true, the id of the current encapsulated tag field is specified as a common field.
Example is "ARTIST" which should be interpreted by any application as the artist of the media content.
Will be set during construction with {@link #checkCommon()}.
private String
content
Stores the content of the tag field.
private String
id
Stores the id (name) of the tag field.
Constructors Summary
public ID3v1TagField(byte[] raw)
Creates an instance.

param
raw Raw byte data of the tagfield.
throws
UnsupportedEncodingException If the data doesn't conform "UTF-8" specification.

        String field = new String(raw, "ISO-8859-1");

        int i = field.indexOf("=");
        if (i == -1)
        {
            //Beware that ogg ID, must be capitalized and contain no space..
            this.id = "ERRONEOUS";
            this.content = field;
        }
        else
        {
            this.id = field.substring(0, i).toUpperCase();
            if (field.length() > i)
            {
                this.content = field.substring(i + 1);
            }
            else
            {
                //We have "XXXXXX=" with nothing after the "="
                this.content = "";
            }
        }
        checkCommon();
    
public ID3v1TagField(String fieldId, String fieldContent)
Creates an instance.

param
fieldId ID (name) of the field.
param
fieldContent Content of the field.

        this.id = fieldId.toUpperCase();
        this.content = fieldContent;
        checkCommon();
    
Methods Summary
private voidcheckCommon()
This method examines the ID of the current field and modifies {@link #common}in order to reflect if the tag id is a commonly used one.

        this.common = id.equals(ID3v1FieldKey.TITLE.name()) || id.equals(ID3v1FieldKey.ALBUM.name()) || id.equals(ID3v1FieldKey.ARTIST.name()) || id.equals(ID3v1FieldKey.GENRE.name()) || id.equals(ID3v1FieldKey.YEAR.name()) || id.equals(ID3v1FieldKey.COMMENT.name()) || id.equals(ID3v1FieldKey.TRACK.name());
    
protected voidcopy(byte[] src, byte[] dst, int dstOffset)
This method will copy all bytes of src to dst at the specified location.

param
src bytes to copy.
param
dst where to copy to.
param
dstOffset at which position of dst the data should be copied.

        //        for (int i = 0; i < src.length; i++)
        //            dst[i + dstOffset] = src[i];
        /*
         * Heared that this method is optimized and does its job very near of
         * the system.
         */
        System.arraycopy(src, 0, dst, dstOffset, src.length);
    
public voidcopyContent(org.jaudiotagger.tag.TagField field)

see
TagField#copyContent(TagField)

        if (field instanceof TagTextField)
        {
            this.content = ((TagTextField) field).getContent();
        }
    
public java.lang.StringgetContent()

see
TagTextField#getContent()

        return content;
    
public java.lang.StringgetEncoding()

see
TagTextField#getEncoding()

        return "ISO-8859-1";
    
public java.lang.StringgetId()

see
TagField#getId()

        return this.id;
    
public byte[]getRawContent()

see
TagField#getRawContent()

        byte[] size = new byte[4];
        byte[] idBytes = this.id.getBytes("ISO-8859-1");
        byte[] contentBytes = Utils.getDefaultBytes(this.content, "ISO-8859-1");
        byte[] b = new byte[4 + idBytes.length + 1 + contentBytes.length];

        int length = idBytes.length + 1 + contentBytes.length;
        size[3] = (byte) ((length & 0xFF000000) >> 24);
        size[2] = (byte) ((length & 0x00FF0000) >> 16);
        size[1] = (byte) ((length & 0x0000FF00) >> 8);
        size[0] = (byte) (length & 0x000000FF);

        int offset = 0;
        copy(size, b, offset);
        offset += 4;
        copy(idBytes, b, offset);
        offset += idBytes.length;
        b[offset] = (byte) 0x3D;
        offset++;// "="
        copy(contentBytes, b, offset);

        return b;
    
public booleanisBinary()

see
TagField#isBinary()

        return false;
    
public voidisBinary(boolean b)

see
TagField#isBinary(boolean)

        //Do nothing, always false
    
public booleanisCommon()

see
TagField#isCommon()

        return common;
    
public booleanisEmpty()

see
TagField#isEmpty()

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

see
TagTextField#setContent(String)

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

see
TagTextField#setEncoding(String)

        //Do nothing, encoding is always ISO-8859-1 for this tag
    
public java.lang.StringtoString()

        return getContent();