1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package entagged.audioformats.ape.util;
20
21 import entagged.audioformats.ape.ApeTag;
22 import entagged.audioformats.generic.AbstractTagCreator;
23 import entagged.audioformats.*;
24
25 import java.nio.ByteBuffer;
26 import java.io.UnsupportedEncodingException;
27 import java.util.Iterator;
28 import java.util.List;
29
30 public class ApeTagCreator extends AbstractTagCreator {
31
32 public void create(Tag tag, ByteBuffer buf, List fields, int tagSize, int paddingSize) throws UnsupportedEncodingException {
33 byte[] b;
34
35
36 buf.put( "APETAGEX".getBytes() );
37
38
39 buf.put( new byte[] {(byte)0xD0,0x07,0x00,0x00} );
40
41
42 int size = tagSize - 32;
43 b = new byte[4];
44 b[3] = (byte) ( ( size & 0xFF000000 ) >>> 24 );
45 b[2] = (byte) ( ( size & 0x00FF0000 ) >>> 16 );
46 b[1] = (byte) ( ( size & 0x0000FF00 ) >>> 8 );
47 b[0] = (byte) ( size & 0x000000FF );
48 buf.put(b);
49
50
51 int listLength = fields.size();
52 b = new byte[4];
53 b[3] = (byte) ( ( listLength & 0xFF000000 ) >>> 24 );
54 b[2] = (byte) ( ( listLength & 0x00FF0000 ) >>> 16 );
55 b[1] = (byte) ( ( listLength & 0x0000FF00 ) >>> 8 );
56 b[0] = (byte) ( listLength & 0x000000FF );
57 buf.put( b );
58
59
60 buf.put( new byte[] {0x00,0x00,0x00,(byte)0xA0} );
61
62
63
64 buf.put( new byte[] {0,0,0,0,0,0,0,0} );
65
66
67 Iterator it = fields.iterator();
68 while(it.hasNext()) {
69 buf.put((byte[]) it.next());
70 }
71
72
73 buf.put( "APETAGEX".getBytes() );
74
75
76 buf.put( new byte[] {(byte)0xD0,0x07,0x00,0x00} );
77
78
79 b = new byte[4];
80 b[3] = (byte) ( ( size & 0xFF000000 ) >>> 24 );
81 b[2] = (byte) ( ( size & 0x00FF0000 ) >>> 16 );
82 b[1] = (byte) ( ( size & 0x0000FF00 ) >>> 8 );
83 b[0] = (byte) ( size & 0x000000FF );
84 buf.put(b);
85
86
87 b = new byte[4];
88 b[3] = (byte) ( ( listLength & 0xFF000000 ) >>> 24 );
89 b[2] = (byte) ( ( listLength & 0x00FF0000 ) >>> 16 );
90 b[1] = (byte) ( ( listLength & 0x0000FF00 ) >>> 8 );
91 b[0] = (byte) ( listLength & 0x000000FF );
92 buf.put( b );
93
94
95 buf.put( new byte[] {0x00,0x00,0x00,(byte)0x80} );
96
97
98
99 buf.put( new byte[] {0,0,0,0,0,0,0,0} );
100
101
102 }
103
104 protected Tag getCompatibleTag(Tag tag) {
105 if(! (tag instanceof ApeTag)) {
106 ApeTag apeTag = new ApeTag();
107 apeTag.merge(tag);
108 return apeTag;
109 }
110 return tag;
111 }
112
113 protected int getFixedTagLength(Tag tag) {
114 return 64;
115 }
116 }