1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package entagged.audioformats.ogg.util;
20
21 import entagged.audioformats.generic.AbstractTagCreator;
22 import entagged.audioformats.generic.Utils;
23 import entagged.audioformats.ogg.*;
24 import entagged.audioformats.*;
25
26 import java.io.UnsupportedEncodingException;
27 import java.nio.*;
28 import java.util.*;
29
30 public class OggTagCreator extends AbstractTagCreator {
31
32
33 public void create(Tag tag, ByteBuffer buf, List fields, int tagSize, int padding) throws UnsupportedEncodingException {
34 String vendorString = ((OggTag)tag).getVendor();
35 int vendorLength = Utils.getUTF8Bytes(vendorString).length;
36 buf.put( new byte[]{(byte)(vendorLength&0xFF), (byte)((vendorLength & 0xFF00) >> 8) , (byte)((vendorLength & 0xFF0000) >> 16), (byte)((vendorLength & 0xFF000000) >> 24) } );
37 buf.put( Utils.getUTF8Bytes(vendorString ) );
38
39
40 int listLength = fields.size();
41 byte[] b = new byte[4];
42 b[3] = (byte) ( ( listLength & 0xFF000000 ) >> 24 );
43 b[2] = (byte) ( ( listLength & 0x00FF0000 ) >> 16 );
44 b[1] = (byte) ( ( listLength & 0x0000FF00 ) >> 8 );
45 b[0] = (byte) ( listLength & 0x000000FF );
46 buf.put( b );
47
48 Iterator it = fields.iterator();
49 while(it.hasNext()) {
50 buf.put((byte[]) it.next());
51 }
52 }
53
54 protected Tag getCompatibleTag(Tag tag) {
55 if(! (tag instanceof OggTag)) {
56 OggTag oggTag = new OggTag();
57 oggTag.merge(tag);
58 return oggTag;
59 }
60 return tag;
61 }
62
63 protected int getFixedTagLength(Tag tag) throws UnsupportedEncodingException {
64 return 8 + Utils.getUTF8Bytes(((OggTag)tag).getVendor()).length;
65 }
66 }