1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package entagged.audioformats.mp4.util;
20
21 import java.io.UnsupportedEncodingException;
22
23 import entagged.audioformats.generic.TagField;
24 import entagged.audioformats.generic.TagTextField;
25 import entagged.audioformats.generic.Utils;
26
27 public class Mp4TagTextField extends Mp4TagField implements TagTextField {
28
29 protected String content;
30
31 public Mp4TagTextField(String id, byte[] raw)
32 throws UnsupportedEncodingException {
33 super(id, raw);
34 }
35
36 public Mp4TagTextField(String id, String content) {
37 super(id);
38 this.content = content;
39 }
40
41 protected void build(byte[] raw) throws UnsupportedEncodingException {
42 int dataSize = Utils.getNumberBigEndian(raw, 0, 3);
43 this.content = Utils
44 .getString(raw, 16, dataSize - 8 - 8, getEncoding());
45 }
46
47
48 public void copyContent(TagField field) {
49 if (field instanceof Mp4TagTextField) {
50 this.content = ((Mp4TagTextField) field).getContent();
51 }
52 }
53
54 public String getContent() {
55 return content;
56 }
57
58
59 protected byte[] getDataBytes() throws UnsupportedEncodingException {
60 return content.getBytes(getEncoding());
61 }
62
63 public String getEncoding() {
64 return "ISO-8859-1";
65 }
66
67 public byte[] getRawContent() throws UnsupportedEncodingException {
68 byte[] data = getDataBytes();
69 byte[] b = new byte[4 + 4 + 4 + 4 + 4 + 4 + data.length];
70
71 int offset = 0;
72 Utils.copy(Utils.getSizeBigEndian(b.length), b, offset);
73 offset += 4;
74
75 Utils.copy(Utils.getDefaultBytes(getId()), b, offset);
76 offset += 4;
77
78 Utils.copy(Utils.getSizeBigEndian(4 + 4 + 4 + 4 + data.length), b,
79 offset);
80 offset += 4;
81
82 Utils.copy(Utils.getDefaultBytes("data"), b, offset);
83 offset += 4;
84
85 Utils.copy(new byte[] { 0, 0, 0, (byte) (isBinary() ? 0 : 1) }, b,
86 offset);
87 offset += 4;
88
89 Utils.copy(new byte[] { 0, 0, 0, 0 }, b, offset);
90 offset += 4;
91
92 Utils.copy(data, b, offset);
93 offset += data.length;
94
95 return b;
96 }
97
98 public boolean isBinary() {
99 return false;
100 }
101
102 public boolean isEmpty() {
103 return this.content.trim().equals("");
104 }
105
106 public void setContent(String s) {
107 this.content = s;
108 }
109
110 public void setEncoding(String s) {
111
112 }
113
114 public String toString() {
115 return content;
116 }
117 }