VorbisCommentTag tag = new VorbisCommentTag();
byte[] b = new byte[FIELD_VENDOR_LENGTH_LENGTH];
System.arraycopy(rawdata, FIELD_VENDOR_LENGTH_POS, b, FIELD_VENDOR_LENGTH_POS, FIELD_VENDOR_LENGTH_LENGTH);
int pos = FIELD_VENDOR_LENGTH_LENGTH;
int vendorStringLength = Utils.getIntLE(b);
b = new byte[vendorStringLength];
System.arraycopy(rawdata, pos, b, 0, vendorStringLength);
pos += vendorStringLength;
tag.setVendor(new String(b, VorbisHeader.CHARSET_UTF_8));
logger.config("Vendor is:"+tag.getVendor());
b = new byte[FIELD_USER_COMMENT_LIST_LENGTH];
System.arraycopy(rawdata, pos, b, 0, FIELD_USER_COMMENT_LIST_LENGTH);
pos += FIELD_USER_COMMENT_LIST_LENGTH;
int userComments = Utils.getIntLE(b);
logger.config("Number of user comments:" + userComments);
for (int i = 0; i < userComments; i++)
{
b = new byte[FIELD_COMMENT_LENGTH_LENGTH];
System.arraycopy(rawdata, pos, b, 0, FIELD_COMMENT_LENGTH_LENGTH);
pos += FIELD_COMMENT_LENGTH_LENGTH;
int commentLength = Utils.getIntLE(b);
logger.config("Next Comment Length:" + commentLength);
if(commentLength> JAUDIOTAGGER_MAX_COMMENT_LENGTH)
{
logger.warning(ErrorMessage.VORBIS_COMMENT_LENGTH_TOO_LARGE.getMsg(commentLength));
break;
}
else if(commentLength>rawdata.length)
{
logger.warning(ErrorMessage.VORBIS_COMMENT_LENGTH_LARGE_THAN_HEADER.getMsg(commentLength,rawdata.length));
break;
}
else
{
b = new byte[commentLength];
System.arraycopy(rawdata, pos, b, 0, commentLength);
pos += commentLength;
VorbisCommentTagField fieldComment = new VorbisCommentTagField(b);
logger.config("Adding:" + fieldComment.getId());
tag.addField(fieldComment);
}
}
//Check framing bit, only exists when vorbisComment used within OggVorbis
if (isFramingBit)
{
if ((rawdata[pos] & 0x01) != 1)
{
throw new CannotReadException(ErrorMessage.OGG_VORBIS_NO_FRAMING_BIT.getMsg((rawdata[pos] & 0x01)));
}
}
return tag;