-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathID3v2ChapterFrameData.java
More file actions
204 lines (173 loc) · 4.54 KB
/
Copy pathID3v2ChapterFrameData.java
File metadata and controls
204 lines (173 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package Mp3File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
public class ID3v2ChapterFrameData extends AbstractID3v2FrameData {
protected String id;
protected int startTime;
protected int endTime;
protected int startOffset;
protected int endOffset;
protected ArrayList<ID3v2Frame> subframes = new ArrayList<>();
public ID3v2ChapterFrameData(boolean unsynchronisation) {
super(unsynchronisation);
}
public ID3v2ChapterFrameData(boolean unsynchronisation, String id, int startTime,
int endTime, int startOffset, int endOffset) {
super(unsynchronisation);
this.id = id;
this.startTime = startTime;
this.endTime = endTime;
this.startOffset = startOffset;
this.endOffset = endOffset;
}
public ID3v2ChapterFrameData(boolean unsynchronisation, byte[] bytes)
throws InvalidDataException {
super(unsynchronisation);
synchroniseAndUnpackFrameData(bytes);
}
@Override
protected void unpackFrameData(byte[] bytes) throws InvalidDataException {
ByteBuffer bb = ByteBuffer.wrap(bytes);
id = ByteBufferUtils.extractNullTerminatedString(bb);
bb.position(id.length() + 1);
startTime = bb.getInt();
endTime = bb.getInt();
startOffset = bb.getInt();
endOffset = bb.getInt();
for (int offset = bb.position(); offset < bytes.length; ) {
ID3v2Frame frame = new ID3v2Frame(bytes, offset);
offset += frame.getLength();
subframes.add(frame);
}
}
public void addSubframe(String id, AbstractID3v2FrameData frame) {
subframes.add(new ID3v2Frame(id, frame.toBytes()));
}
@Override
protected byte[] packFrameData() {
ByteBuffer bb = ByteBuffer.allocate(getLength());
bb.put(id.getBytes());
bb.put((byte) 0);
bb.putInt(startTime);
bb.putInt(endTime);
bb.putInt(startOffset);
bb.putInt(endOffset);
for (ID3v2Frame frame : subframes) {
try {
bb.put(frame.toBytes());
} catch (NotSupportedException e) {
e.printStackTrace();
}
}
return bb.array();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getStartTime() {
return startTime;
}
public void setStartTime(int startTime) {
this.startTime = startTime;
}
public int getEndTime() {
return endTime;
}
public void setEndTime(int endTime) {
this.endTime = endTime;
}
public int getStartOffset() {
return startOffset;
}
public void setStartOffset(int startOffset) {
this.startOffset = startOffset;
}
public int getEndOffset() {
return endOffset;
}
public void setEndOffset(int endOffset) {
this.endOffset = endOffset;
}
public ArrayList<ID3v2Frame> getSubframes() {
return subframes;
}
public void setSubframes(ArrayList<ID3v2Frame> subframes) {
this.subframes = subframes;
}
@Override
protected int getLength() {
int length = 1;
length += 16;
if (id != null)
length += id.length();
if (subframes != null) {
for (ID3v2Frame frame : subframes) {
length += frame.getLength();
}
}
return length;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ID3v2ChapterFrameData [id=");
builder.append(id);
builder.append(", startTime=");
builder.append(startTime);
builder.append(", endTime=");
builder.append(endTime);
builder.append(", startOffset=");
builder.append(startOffset);
builder.append(", endOffset=");
builder.append(endOffset);
builder.append(", subframes=");
builder.append(subframes);
builder.append("]");
return builder.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + endOffset;
result = prime * result + endTime;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + startOffset;
result = prime * result + startTime;
result = prime * result
+ ((subframes == null) ? 0 : subframes.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ID3v2ChapterFrameData other = (ID3v2ChapterFrameData) obj;
if (endOffset != other.endOffset)
return false;
if (endTime != other.endTime)
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (startOffset != other.startOffset)
return false;
if (startTime != other.startTime)
return false;
if (subframes == null) {
if (other.subframes != null)
return false;
} else if (!subframes.equals(other.subframes))
return false;
return true;
}
}