FileDocCategorySizeDatePackage
FlacTag.javaAPI DocJaudiotagger 2.0.413893Wed Dec 07 10:39:30 GMT 2011org.jaudiotagger.tag.flac

FlacTag

public class FlacTag extends Object implements Tag
Flac uses Vorbis Comment for most of its metadata and a Flac Picture Block for images

This class enscapulates the items into a single tag

Fields Summary
private org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag
tag
private List
images
Constructors Summary
public FlacTag()


     
    
        this(VorbisCommentTag.createNewTag(), new ArrayList< MetadataBlockDataPicture >());
    
public FlacTag(org.jaudiotagger.tag.vorbiscomment.VorbisCommentTag tag, List images)

        this.tag = tag;
        this.images = images;
    
Methods Summary
public voidaddField(FieldKey genericKey, java.lang.String value)

        TagField tagfield = createField(genericKey,value);
        addField(tagfield);
    
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 voidaddField(org.jaudiotagger.tag.images.Artwork artwork)

        this.addField(createField(artwork));
    
public voidaddField(TagField field)

        if (field instanceof MetadataBlockDataPicture)
        {
            images.add((MetadataBlockDataPicture) field);
        }
        else
        {
            tag.addField(field);
        }
    
public TagFieldcreateArtworkField(byte[] imageData, int pictureType, java.lang.String mimeType, java.lang.String description, int width, int height, int colourDepth, int indexedColouredCount)

        return new MetadataBlockDataPicture(imageData, pictureType, mimeType, description, width, height, colourDepth, indexedColouredCount);
    
public TagFieldcreateField(FieldKey genericKey, java.lang.String value)

        if (genericKey.equals(FieldKey.COVER_ART))
        {
            throw new UnsupportedOperationException(ErrorMessage.ARTWORK_CANNOT_BE_CREATED_WITH_THIS_METHOD.getMsg());
        }
        else
        {
            return tag.createField(genericKey, value);
        }
    
public TagFieldcreateField(org.jaudiotagger.tag.vorbiscomment.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 (vorbisCommentFieldKey.equals(VorbisCommentFieldKey.COVERART))
        {
            throw new UnsupportedOperationException(ErrorMessage.ARTWORK_CANNOT_BE_CREATED_WITH_THIS_METHOD.getMsg());
        }
        return tag.createField(vorbisCommentFieldKey,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 (vorbisCommentFieldKey.equals(VorbisCommentFieldKey.COVERART.getFieldName()))
        {
            throw new UnsupportedOperationException(ErrorMessage.ARTWORK_CANNOT_BE_CREATED_WITH_THIS_METHOD.getMsg());
        }
        return tag.createField(vorbisCommentFieldKey,value);
    
public TagFieldcreateField(org.jaudiotagger.tag.images.Artwork artwork)
Create artwork field

return

        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 createField buffered image from the image");
            }

            return new MetadataBlockDataPicture(artwork.getBinaryData(),
                    artwork.getPictureType(),
                    artwork.getMimeType(),
                    artwork.getDescription(),
                    artwork.getWidth(),
                    artwork.getHeight(),
                    0,
                    0);
        }
    
public TagFieldcreateLinkedArtworkField(java.lang.String url)
Create Link to Image File, not recommended because if either flac or image file is moved link will be broken.

param
url
return

        //Add to image list
        return new MetadataBlockDataPicture(Utils.getDefaultBytes(url, TextEncoding.CHARSET_ISO_8859_1), PictureTypes.DEFAULT_ID, MetadataBlockDataPicture.IMAGE_IS_URL, "", 0, 0, 0, 0);
    
public voiddeleteArtworkField()
Delete all instance of artwork Field

throws
KeyNotFoundException

        this.deleteField(FieldKey.COVER_ART);
    
public voiddeleteField(FieldKey fieldKey)
Delete any instance of tag fields with this key

param
fieldKey

        if (fieldKey.equals(FieldKey.COVER_ART))
        {
            images.clear();
        }
        else
        {
            tag.deleteField(fieldKey);
        }
    
public voiddeleteField(java.lang.String id)

          if (id.equals(FieldKey.COVER_ART.name()))
          {
              images.clear();
          }
          else
          {
              tag.deleteField(id);
          }
      
public java.util.ListgetArtworkList()

         
        List<Artwork>  artworkList  = new ArrayList<Artwork>(images.size());

        for(MetadataBlockDataPicture coverArt:images)
        {
            Artwork artwork= ArtworkFactory.createArtworkFromMetadataBlockDataPicture(coverArt);
            artworkList.add(artwork);
        }
        return artworkList;
    
public intgetFieldCount()

        return tag.getFieldCount() + images.size();
    
public intgetFieldCountIncludingSubValues()

       return getFieldCount();
    
public java.util.IteratorgetFields()

        return tag.getFields();
    
public java.util.ListgetFields(FieldKey id)

        if (id.equals(FieldKey.COVER_ART))
        {
            List<TagField> castImages = new ArrayList<TagField>();
            for (MetadataBlockDataPicture image : images)
            {
                castImages.add(image);
            }
            return castImages;
        }
        else
        {
            return tag.getFields(id);
        }
     
public java.util.ListgetFields(java.lang.String id)

        if (id.equals(FieldKey.COVER_ART.name()))
        {
            List<TagField> castImages = new ArrayList<TagField>();
            for (MetadataBlockDataPicture image : images)
            {
                castImages.add(image);
            }
            return castImages;
        }
        else
        {
            return tag.getFields(id);
        }
    
public java.lang.StringgetFirst(java.lang.String id)

        if (id.equals(FieldKey.COVER_ART.name()))
        {
            throw new UnsupportedOperationException(ErrorMessage.ARTWORK_CANNOT_BE_CREATED_WITH_THIS_METHOD.getMsg());
        }
        else
        {
            return tag.getFirst(id);
        }
    
public java.lang.StringgetFirst(FieldKey id)

        return getValue(id,0);
    
public org.jaudiotagger.tag.images.ArtworkgetFirstArtwork()

        List<Artwork> artwork = getArtworkList();
        if(artwork.size()>0)
        {
            return artwork.get(0);
        }
        return null;
    
public TagFieldgetFirstField(java.lang.String id)

        if (id.equals(FieldKey.COVER_ART.name()))
        {
            if (images.size() > 0)
            {
                return images.get(0);
            }
            else
            {
                return null;
            }
        }
        else
        {
            return tag.getFirstField(id);
        }
    
public TagFieldgetFirstField(FieldKey genericKey)

        if (genericKey == null)
        {
            throw new KeyNotFoundException();
        }

        if(genericKey == FieldKey.COVER_ART )
        {
            return getFirstField(FieldKey.COVER_ART.name());
        }
        else
        {
            return tag.getFirstField(genericKey);            
        }
    
public java.util.ListgetImages()

return
images

        return images;
    
public java.lang.StringgetSubValue(FieldKey id, int n, int m)
The m parameter is effectively ignored

param
id
param
n
param
m
return

        return getValue(id,n);
    
public java.lang.StringgetValue(FieldKey id, int index)

        if (id.equals(FieldKey.COVER_ART))
        {
            throw new UnsupportedOperationException(ErrorMessage.ARTWORK_CANNOT_BE_RETRIEVED_WITH_THIS_METHOD.getMsg());
        }
        else
        {
            return tag.getValue(id, index);
        }
    
public org.jaudiotagger.tag.vorbiscomment.VorbisCommentTaggetVorbisCommentTag()

return
the vorbis tag (this is what handles text metadata)

        return tag;
    
public booleanhasCommonFields()

        return tag.hasCommonFields();
    
public booleanhasField(FieldKey genericKey)

param
genericKey
return

        if (genericKey==FieldKey.COVER_ART)
        {
            return images.size() > 0;
        }
        else
        {
            return tag.hasField(genericKey);
        }
    
public booleanhasField(org.jaudiotagger.tag.vorbiscomment.VorbisCommentFieldKey vorbisFieldKey)

param
vorbisFieldKey
return

        return tag.hasField(vorbisFieldKey);
    
public booleanhasField(java.lang.String id)

       if (id.equals(FieldKey.COVER_ART.name()))
       {
           return images.size() > 0;
       }
       else
       {
           return tag.hasField(id);
       }
   
public booleanisEmpty()
Determines whether the tag has no fields specified.

If there are no images we return empty if either there is no VorbisTag or if there is a VorbisTag but it is empty

return
true if tag contains no field.

        return (tag == null || tag.isEmpty()) && images.size() == 0;
    
public booleansetEncoding(java.lang.String enc)

        return tag.setEncoding(enc);
    
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 voidsetField(TagField field)

param
field
throws
FieldDataInvalidException

        if (field instanceof MetadataBlockDataPicture)
        {
            if (images.size() == 0)
            {
                images.add(0, (MetadataBlockDataPicture) field);
            }
            else
            {
                images.set(0, (MetadataBlockDataPicture) field);
            }
        }
        else
        {
            tag.setField(field);
        }
    
public voidsetField(org.jaudiotagger.tag.images.Artwork artwork)

        this.setField(createField(artwork));
    
public voidsetField(FieldKey genericKey, java.lang.String value)

        TagField tagfield = createField(genericKey,value);
        setField(tagfield);