FileDocCategorySizeDatePackage
VorbisCommentTag.javaAPI DocJaudiotagger 2.0.424391Wed Dec 07 10:32:24 GMT 2011org.jaudiotagger.tag.vorbiscomment

VorbisCommentTag

public class VorbisCommentTag extends org.jaudiotagger.audio.generic.AbstractTag
This is the logical representation of Vorbis Comment Data

Fields Summary
private static EnumMap
tagFieldToOggField
public static final String
DEFAULT_VENDOR
Constructors Summary
VorbisCommentTag()
Only used within Package, hidden because it doesnt set Vendor which should be done when created by end user


                            
    
    

    
Methods Summary
public voidaddField(TagField field)
Add Field

Overidden because there can only be one vendor set

param
field

        if (field.getId().equals(VorbisCommentFieldKey.VENDOR.getFieldName()))
        {
            super.setField(field);
        }
        else
        {
            super.addField(field);
        }
    
public voidaddField(org.jaudiotagger.tag.images.Artwork artwork)
Add artwork field

param
artwork
throws
FieldDataInvalidException

        this.addField(createField(artwork));
    
public voidaddField(java.lang.String vorbisCommentKey, java.lang.String value)
Create and add field with name of vorbisCommentkey

param
vorbisCommentKey
param
value
throws
KeyNotFoundException
throws
FieldDataInvalidException

        TagField tagfield = createField(vorbisCommentKey,value);
        addField(tagfield);
    
public TagFieldcreateField(org.jaudiotagger.tag.images.Artwork artwork)
Create Artwork field

param
artwork
return
throws
FieldDataInvalidException

        try
        {
            char[] testdata = Base64Coder.encode(createMetadataBlockDataPicture(artwork).getRawContent());
            String base64image = new String(testdata);
            TagField imageTagField  = createField(VorbisCommentFieldKey.METADATA_BLOCK_PICTURE, base64image);
            return imageTagField;
        }
        catch(UnsupportedEncodingException uee)
        {
            throw new RuntimeException(uee);
        }
    
public TagFieldcreateField(FieldKey genericKey, java.lang.String value)
Create Tag Field using generic key

        if (genericKey == null)
        {
            throw new KeyNotFoundException();
        }
        return createField(tagFieldToOggField.get(genericKey), value);
    
public TagFieldcreateField(VorbisCommentFieldKey vorbisCommentFieldKey, java.lang.String value)
Create Tag Field using ogg key

param
vorbisCommentFieldKey
param
value
return
throws
org.jaudiotagger.tag.KeyNotFoundException
throws
org.jaudiotagger.tag.FieldDataInvalidException

        if (value == null)
        {
            throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
        }
        if (vorbisCommentFieldKey == null)
        {
            throw new KeyNotFoundException();
        }

        return new VorbisCommentTagField(vorbisCommentFieldKey.getFieldName(), value);
    
public TagFieldcreateField(java.lang.String vorbisCommentFieldKey, java.lang.String value)
Create Tag Field using ogg key

This method is provided to allow you to create key of any value because VorbisComment allows arbitary keys.

param
vorbisCommentFieldKey
param
value
return

        if (value == null)
        {
            throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg());
        }
        return new VorbisCommentTagField(vorbisCommentFieldKey, value);
    
private org.jaudiotagger.audio.flac.metadatablock.MetadataBlockDataPicturecreateMetadataBlockDataPicture(org.jaudiotagger.tag.images.Artwork artwork)
Create MetadataBlockPicture field, this is the preferred way of storing artwork in VorbisComment tag now but has to be base encoded to be stored in VorbisComment

return
MetadataBlockDataPicture

          if(artwork.isLinked())
          {
               return new MetadataBlockDataPicture(
                      Utils.getDefaultBytes(artwork.getImageUrl(), TextEncoding.CHARSET_ISO_8859_1),
                      artwork.getPictureType(),
                      MetadataBlockDataPicture.IMAGE_IS_URL,
                      "",
                      0,
                      0,
                      0,
                      0);
          }
          else
          {
              if(!artwork.setImageFromData())
              {
                  throw new FieldDataInvalidException("Unable to create MetadataBlockDataPicture from buffered");
              }
              return new MetadataBlockDataPicture(artwork.getBinaryData(),
                      artwork.getPictureType(),
                      artwork.getMimeType(),
                      artwork.getDescription(),
                      artwork.getWidth(),
                      artwork.getHeight(),
                      0,
                      0);
          }
      
public static org.jaudiotagger.tag.vorbiscomment.VorbisCommentTagcreateNewTag()
Use to construct a new tag properly initialized

return

        VorbisCommentTag tag = new VorbisCommentTag();
        tag.setVendor(DEFAULT_VENDOR);
        return tag;
    
public voiddeleteArtworkField()
Delete all instance of artwork Field

throws
KeyNotFoundException

        //New Method
        this.deleteField(VorbisCommentFieldKey.METADATA_BLOCK_PICTURE);

        //Old Method
        this.deleteField(VorbisCommentFieldKey.COVERART);
        this.deleteField(VorbisCommentFieldKey.COVERARTMIME);
    
public voiddeleteField(FieldKey genericKey)
Delete fields with this generic key

param
genericKey

        if (genericKey == null)
        {
            throw new KeyNotFoundException();
        }
        VorbisCommentFieldKey vorbisCommentFieldKey = tagFieldToOggField.get(genericKey);
        deleteField(vorbisCommentFieldKey);
    
public voiddeleteField(VorbisCommentFieldKey vorbisCommentFieldKey)
Delete fields with this vorbisCommentFieldKey

param
vorbisCommentFieldKey
throws
org.jaudiotagger.tag.KeyNotFoundException

        if (vorbisCommentFieldKey == null)
        {
            throw new KeyNotFoundException();
        }
        super.deleteField(vorbisCommentFieldKey.getFieldName());
    
public java.util.Listget(VorbisCommentFieldKey vorbisCommentKey)
Retrieve the first value that exists for this vorbis comment key

param
vorbisCommentKey
return
throws
org.jaudiotagger.tag.KeyNotFoundException

        if (vorbisCommentKey == null)
        {
            throw new KeyNotFoundException();
        }
        return super.getFields(vorbisCommentKey.getFieldName());
    
public byte[]getArtworkBinaryData()
Retrieve artwork raw data when using the deprecated COVERART format

return

        String base64data = this.getFirst(VorbisCommentFieldKey.COVERART);
        byte[] rawdata = Base64Coder.decode(base64data.toCharArray());
        return rawdata;
    
public java.util.ListgetArtworkList()

return
list of artwork images

        List<Artwork>  artworkList  = new ArrayList<Artwork>(1);

        //Read Old Format
        if(getArtworkBinaryData()!=null & getArtworkBinaryData().length>0)
        {
            Artwork artwork= ArtworkFactory.getNew();
            artwork.setMimeType(getArtworkMimeType());
            artwork.setBinaryData(getArtworkBinaryData());
            artworkList.add(artwork);
        }

        //New Format (Supports Multiple Images)
        List<TagField> metadataBlockPics = this.get(VorbisCommentFieldKey.METADATA_BLOCK_PICTURE);
        for(TagField tagField:metadataBlockPics)
        {

            try
            {
                byte[] imageBinaryData = Base64Coder.decode(((TagTextField)tagField).getContent());
                MetadataBlockDataPicture coverArt = new MetadataBlockDataPicture(ByteBuffer.wrap(imageBinaryData));
                Artwork artwork=ArtworkFactory.createArtworkFromMetadataBlockDataPicture(coverArt);
                artworkList.add(artwork);
            }
            catch(IOException ioe)
            {
                throw new RuntimeException(ioe);
            }
            catch(InvalidFrameException ife)
            {
                throw new RuntimeException(ife);
            }
        }
        return artworkList;
    
public java.lang.StringgetArtworkMimeType()
Retrieve artwork mimeType when using deprecated COVERART format

return
mimetype

        return this.getFirst(VorbisCommentFieldKey.COVERARTMIME);
    
public java.util.ListgetFields(FieldKey genericKey)
Maps the generic key to the ogg key and return the list of values for this field

param
genericKey

        VorbisCommentFieldKey vorbisCommentFieldKey = tagFieldToOggField.get(genericKey);
        if (vorbisCommentFieldKey == null)
        {
            throw new KeyNotFoundException();
        }
        return super.getFields(vorbisCommentFieldKey.getFieldName());
    
public java.lang.StringgetFirst(VorbisCommentFieldKey vorbisCommentKey)
Retrieve the first value that exists for this vorbis comment key

param
vorbisCommentKey
return
throws
org.jaudiotagger.tag.KeyNotFoundException

        if (vorbisCommentKey == null)
        {
            throw new KeyNotFoundException();
        }
        return super.getFirst(vorbisCommentKey.getFieldName());
    
public TagFieldgetFirstField(FieldKey genericKey)

        if (genericKey == null)
        {
            throw new KeyNotFoundException();
        }
        return getFirstField(tagFieldToOggField.get(genericKey).getFieldName());
    
public java.lang.StringgetValue(FieldKey genericKey, int index)

        VorbisCommentFieldKey vorbisCommentFieldKey = tagFieldToOggField.get(genericKey);
        if (vorbisCommentFieldKey == null)
        {
            throw new KeyNotFoundException();
        }
        return super.getItem(vorbisCommentFieldKey.getFieldName(),index);
    
public java.lang.StringgetVendor()

return
the vendor, generically known as the encoder

        return getFirst(VENDOR.getFieldName());
    
public booleanhasField(FieldKey genericKey)

param
genericKey
return

        VorbisCommentFieldKey vorbisFieldKey = tagFieldToOggField.get(genericKey);
        return getFields(vorbisFieldKey.getFieldName()).size() != 0;
    
public booleanhasField(VorbisCommentFieldKey vorbisFieldKey)

param
vorbisFieldKey
return

        return getFields(vorbisFieldKey.getFieldName()).size() != 0;
    
protected booleanisAllowedEncoding(java.lang.String enc)

        return enc.equals(VorbisHeader.CHARSET_UTF_8);
    
public booleanisEmpty()
Is this tag empty

Overridden because check for size of one because there is always a vendor tag unless just created an empty vorbis tag as part of flac tag in which case size could be zero

see
org.jaudiotagger.tag.Tag#isEmpty()

        return fields.size() <= 1;
    
public voidsetArtworkField(byte[] data, java.lang.String mimeType)
Create artwork field using the non-standard COVERART tag

Actually create two fields , the data field and the mimetype. Its is not recommended that you use this method anymore.

param
data raw image data
param
mimeType mimeType of data

return

        char[] testdata = Base64Coder.encode(data);
        String base64image = new String(testdata);
        VorbisCommentTagField dataField = new VorbisCommentTagField(VorbisCommentFieldKey.COVERART.getFieldName(), base64image);
        VorbisCommentTagField mimeField = new VorbisCommentTagField(VorbisCommentFieldKey.COVERARTMIME.getFieldName(), mimeType);

        setField(dataField);
        setField(mimeField);

    
public voidsetField(org.jaudiotagger.tag.images.Artwork artwork)
Create and set artwork field

return

        //Set field
        this.setField(createField(artwork));

        //If worked okay above then that should be first artwork and if we still had old coverart format
        //that should be removed
        if(this.getFirst(VorbisCommentFieldKey.COVERART).length()>0)
        {
            this.deleteField(VorbisCommentFieldKey.COVERART);
            this.deleteField(VorbisCommentFieldKey.COVERARTMIME);
        }
    
public voidsetField(java.lang.String vorbisCommentKey, java.lang.String value)
Create and set field with name of vorbisCommentkey

param
vorbisCommentKey
param
value
throws
KeyNotFoundException
throws
FieldDataInvalidException

        TagField tagfield = createField(vorbisCommentKey,value);
        setField(tagfield);
    
public voidsetVendor(java.lang.String vendor)
Set the vendor, known as the encoder generally

We dont want this to be blank, when written to file this field is written to a different location to all other fields but user of library can just reat it as another field

param
vendor

        if (vendor == null)
        {
            vendor = DEFAULT_VENDOR;
        }
        super.setField(new VorbisCommentTagField(VENDOR.getFieldName(), vendor));
    
public java.lang.StringtoString()

        return "OGG " + super.toString();