* @return
* @throws UnsupportedEncodingException
*/
public ByteBuffer convert(Tag tag, int paddingSize) throws UnsupportedEncodingException {
// //logger.info("Convert flac tag:padding:" + paddingSize);
FlacTag flacTag = (FlacTag) tag;
int tagLength = 0;
ByteBuffer vorbiscomment = null;
if (flacTag.getVorbisCommentTag() != null) {
vorbiscomment = creator.convert(flacTag.getVorbisCommentTag());
tagLength = vorbiscomment.capacity() + MetadataBlockHeader.HEADER_LENGTH;
}
for (MetadataBlockDataPicture image : flacTag.getImages()) {
tagLength += image.getBytes().length + MetadataBlockHeader.HEADER_LENGTH;
}
// //logger.info("Convert flac tag:taglength:" + tagLength);
ByteBuffer buf = ByteBuffer.allocate(tagLength + paddingSize);
MetadataBlockHeader vorbisHeader;
//If there are other metadata blocks
if (flacTag.getVorbisCommentTag() != null) {
if ((paddingSize > 0) || (flacTag.getImages().size() > 0)) {
vorbisHeader = new MetadataBlockHeader(false, BlockType.VORBIS_COMMENT, vorbiscomment.capacity());
} else {
vorbisHeader = new MetadataBlockHeader(true, BlockType.VORBIS_COMMENT, vorbiscomment.capacity());
}
buf.put(vorbisHeader.getBytes());
buf.put(vorbiscomment);
}
//Images
ListIterator<MetadataBlockDataPicture> li = flacTag.getImages().listIterator();
while (li.hasNext()) {
MetadataBlockDataPicture imageField = li.next();
MetadataBlockHeader imageHeader;
if (paddingSize > 0 || li.hasNext()) {