{
ID3v2OutputFrame frame = (ID3v2OutputFrame) frames.get(i);
String frame_id = frame.longFrameID;
if (frame_id.length() != 4)
throw new ID3WriteException("frame_id has bad length: "
+ frame_id + " (" + frame_id.length() + ")");
if (filter != null && filter.filter(frame_id))
{
continue;
}
// baos.write(frame_id );
baos.write((byte) frame_id.charAt(0));
baos.write((byte) frame_id.charAt(1));
baos.write((byte) frame_id.charAt(2));
baos.write((byte) frame_id.charAt(3));
int length = frame.bytes.length;
if (id3v2_version == 4)
{
baos.write((byte) (0x7f & (length >> 21)));
baos.write((byte) (0x7f & (length >> 14)));
baos.write((byte) (0x7f & (length >> 7)));
baos.write((byte) (0x7f & (length)));
} else if (id3v2_version == 3)
{
baos.write((byte) (0xff & (length >> 24)));
baos.write((byte) (0xff & (length >> 16)));
baos.write((byte) (0xff & (length >> 8)));
baos.write((byte) (0xff & (length)));
} else
throw new ID3WriteException("id3v2_version: " + id3v2_version);
// int flags = frame.flags;
int flags = 0;
if (id3v2_version == 4)
{
if (frame.flags.getTagAlterPreservation())
flags |= FRAME_FLAG_ID3v24_TAG_ALTER_PRESERVATION;
if (frame.flags.getFileAlterPreservation())
flags |= FRAME_FLAG_ID3v24_FILE_ALTER_PRESERVATION;
if (frame.flags.getReadOnly())
flags |= FRAME_FLAG_ID3v24_READ_ONLY;
if (frame.flags.getGroupingIdentity())
flags |= FRAME_FLAG_ID3v24_GROUPING_IDENTITY;
if (frame.flags.getCompression())
flags |= FRAME_FLAG_ID3v24_COMPRESSION;
if (frame.flags.getEncryption())
flags |= FRAME_FLAG_ID3v24_ENCRYPTION;
if (frame.flags.getUnsynchronisation())
flags |= FRAME_FLAG_ID3v24_UNSYNCHRONISATION;
if (frame.flags.getDataLengthIndicator())
flags |= FRAME_FLAG_ID3v24_DATA_LENGTH_INDICATOR;
} else if (id3v2_version == 3)
{
if (frame.flags.getTagAlterPreservation())
flags |= FRAME_FLAG_ID3v23_TAG_ALTER_PRESERVATION;
if (frame.flags.getFileAlterPreservation())
flags |= FRAME_FLAG_ID3v23_FILE_ALTER_PRESERVATION;
if (frame.flags.getReadOnly())
flags |= FRAME_FLAG_ID3v23_READ_ONLY;
if (frame.flags.getGroupingIdentity())
flags |= FRAME_FLAG_ID3v23_GROUPING_IDENTITY;
if (frame.flags.getCompression())
flags |= FRAME_FLAG_ID3v23_COMPRESSION;
if (frame.flags.getEncryption())
flags |= FRAME_FLAG_ID3v23_ENCRYPTION;
} else
throw new ID3WriteException("id3v2_version: " + id3v2_version);
baos.write((byte) (0xff & (flags >> 8)));
baos.write((byte) (0xff & (flags)));
baos.write(frame.bytes);