FileDocCategorySizeDatePackage
VorbisCommentTagField.javaAPI DocJaudiotagger 2.0.48401Wed Mar 30 16:12:06 BST 2011org.jaudiotagger.tag.vorbiscomment

VorbisCommentTagField

public class VorbisCommentTagField extends Object implements org.jaudiotagger.tag.TagTextField
This class represents the name and content of a tag entry in ogg-files.
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.
private static final String
ERRONEOUS_ID
If id is invalid
Constructors Summary
public VorbisCommentTagField(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, "UTF-8");
        int i = field.indexOf("=");
        if (i == -1)
        {
            //Beware that ogg ID, must be capitalized and contain no space..
            this.id = ERRONEOUS_ID;
            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 VorbisCommentTagField(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(TITLE.getFieldName()) || id.equals(ALBUM.getFieldName()) || id.equals(ARTIST.getFieldName())
                || id.equals(GENRE.getFieldName()) || id.equals(TRACKNUMBER.getFieldName()) || id.equals(DATE.getFieldName())
        || id.equals(DESCRIPTION.getFieldName()) || id.equals(COMMENT.getFieldName());

    
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();
        }
    
protected byte[]getBytes(java.lang.String s, java.lang.String encoding)
This method will try to return the byte representation of the given string after it has been converted to the given encoding.

param
s The string whose converted bytes should be returned.
param
encoding The encoding type to which the string should be converted.
return
If encoding is supported the byte data of the given string is returned in that encoding.
throws
UnsupportedEncodingException If the requested encoding is not available.

        return s.getBytes(encoding);
    
public java.lang.StringgetContent()

see
TagTextField#getContent()

        return content;
    
public java.lang.StringgetEncoding()

see
TagTextField#getEncoding()

        return VorbisHeader.CHARSET_UTF_8;
    
public java.lang.StringgetId()

see
TagField#getId()

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

see
TagField#getRawContent()

        byte[] size = new byte[VorbisCommentReader.FIELD_COMMENT_LENGTH_LENGTH];
        byte[] idBytes = Utils.getDefaultBytes(this.id, "ISO-8859-1");
        byte[] contentBytes = getBytes(this.content, "UTF-8");
        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)

        if (b)
        {
            // Only throw if binary = true requested.
            throw new UnsupportedOperationException("OggTagFields cannot be changed to binary.\n" + "binary data should be stored elsewhere" + " according to Vorbis_I_spec.");
        }
    
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)

        if (s == null || !s.equalsIgnoreCase("UTF-8"))
        {
            throw new UnsupportedOperationException("The encoding of OggTagFields cannot be " + "changed.(specified to be UTF-8)");
        }
    
public java.lang.StringtoString()

        return getContent();