1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package entagged.audioformats.flac.util;
20
21 import entagged.audioformats.ogg.util.OggTagCreator;
22 import entagged.audioformats.*;
23
24 import java.io.UnsupportedEncodingException;
25 import java.nio.*;
26
27 public class FlacTagCreator {
28
29 public static final int DEFAULT_PADDING = 4000;
30 private static final OggTagCreator creator = new OggTagCreator();
31
32
33 public ByteBuffer convert(Tag tag, int paddingSize) throws UnsupportedEncodingException {
34 ByteBuffer ogg = creator.convert(tag);
35 int tagLength = ogg.capacity() + 4;
36
37 ByteBuffer buf = ByteBuffer.allocate( tagLength + paddingSize );
38
39
40
41
42 byte type = (paddingSize > 0) ? (byte)0x04 : (byte) 0x84;
43 buf.put(type);
44 int commentLength = tagLength - 4;
45 buf.put( new byte[] { (byte)((commentLength & 0xFF0000) >>> 16), (byte)((commentLength & 0xFF00) >>> 8) , (byte)(commentLength&0xFF) } );
46
47
48 buf.put(ogg);
49
50
51 if(paddingSize >=4) {
52 int paddingDataSize = paddingSize - 4;
53 buf.put((byte)0x81);
54 buf.put(new byte[]{ (byte)((paddingDataSize&0xFF0000)>>>16),(byte)((paddingDataSize&0xFF00)>>>8),(byte)(paddingDataSize&0xFF) });
55 for(int i = 0; i< paddingDataSize; i++)
56 buf.put((byte)0);
57 }
58 buf.rewind();
59
60 return buf;
61 }
62
63 public int getTagLength(Tag tag) throws UnsupportedEncodingException {
64 ByteBuffer ogg = creator.convert(tag);
65 return ogg.capacity() + 4;
66 }
67 }