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 java.io.UnsupportedEncodingException;
22 import entagged.audioformats.generic.TagField;
23 import entagged.audioformats.generic.TagTextField;
24
25
26 public class ApeTagTextField extends ApeTagField implements TagTextField {
27
28 private String content;
29
30 public ApeTagTextField(String id, String content) {
31 super(id, false);
32 this.content = content;
33 }
34
35 public boolean isEmpty() {
36 return this.content.equals("");
37 }
38
39 public String toString() {
40 return this.content;
41 }
42
43 public void copyContent(TagField field) {
44 if(field instanceof ApeTagTextField) {
45 this.content = ((ApeTagTextField)field).getContent();
46 }
47 }
48
49 public String getContent() {
50 return this.content;
51 }
52
53 public String getEncoding() {
54 return "UTF-8";
55 }
56 public void setEncoding(String s) {
57
58 }
59
60 public void setContent(String s) {
61 this.content = s;
62 }
63
64 public byte[] getRawContent() throws UnsupportedEncodingException {
65 byte[] idBytes = getBytes(getId(), "ISO-8859-1");
66 byte[] contentBytes = getBytes(content, getEncoding());
67 byte[] buf = new byte[4 + 4 + idBytes.length + 1 + contentBytes.length];
68 byte[] flags = {0x00,0x00,0x00,0x00};
69
70 int offset = 0;
71 copy(getSize(contentBytes.length), buf, offset);offset += 4;
72 copy(flags, buf, offset); offset += 4;
73 copy(idBytes, buf, offset); offset += idBytes.length;
74 buf[offset] = 0; offset += 1;
75 copy(contentBytes, buf, offset); offset += contentBytes.length;
76
77 return buf;
78 }
79 }