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

VorbisCommentCreator

public class VorbisCommentCreator extends org.jaudiotagger.audio.generic.AbstractTagCreator
Create the raw packet data for a Vorbis Comment Tag

Fields Summary
Constructors Summary
Methods Summary
public java.nio.ByteBufferconvert(org.jaudiotagger.tag.Tag tag, int padding)
Convert tagdata to rawdata ready for writing to file

param
tag
param
padding
return
throws
UnsupportedEncodingException

        try
        {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            //Vendor
            String vendorString = ((VorbisCommentTag) tag).getVendor();
            int vendorLength = Utils.getUTF8Bytes(vendorString).length;
            baos.write(Utils.getSizeLEInt32(vendorLength));
            baos.write(Utils.getUTF8Bytes(vendorString));

            //User Comment List
            int listLength = tag.getFieldCount() - 1; //Remove Vendor from count         
            baos.write(Utils.getSizeLEInt32(listLength));

            //Add metadata raw content
            Iterator<TagField> it = tag.getFields();
            while (it.hasNext())
            {
                TagField frame = it.next();
                if (frame.getId().equals(VorbisCommentFieldKey.VENDOR.getFieldName()))
                {
                    //this is always stored above so ignore                    
                }
                else
                {
                    baos.write(frame.getRawContent());
                }
            }

            //Put into ByteBuffer
            ByteBuffer buf = ByteBuffer.wrap(baos.toByteArray());
            buf.rewind();
            return buf;
        }
        catch (IOException ioe)
        {
            //Should never happen as not writing to file at this point
            throw new RuntimeException(ioe);
        }