1 | package org.farng.mp3.object; |
2 | |
3 | /** |
4 | * ID3v2 and Lyrics3v2 tags have individual fields <code>AbstractMP3Fragment</code>s Then each fragment is broken down |
5 | * in to individual <code>AbstractMP3Object</code>s |
6 | * |
7 | * @author Eric Farng |
8 | * @version $Revision: 1.5 $ |
9 | */ |
10 | public class ObjectID3v2LyricLine extends AbstractMP3Object { |
11 | |
12 | String text = ""; |
13 | long timeStamp = 0; |
14 | |
15 | /** |
16 | * Creates a new ObjectID3v2LyricLine object. |
17 | */ |
18 | public ObjectID3v2LyricLine(final String identifier) { |
19 | this.identifier = identifier; |
20 | } |
21 | |
22 | /** |
23 | * Creates a new ObjectID3v2LyricLine object. |
24 | */ |
25 | public ObjectID3v2LyricLine(final ObjectID3v2LyricLine copyObject) { |
26 | super(copyObject); |
27 | this.text = new String(copyObject.text); |
28 | this.timeStamp = copyObject.timeStamp; |
29 | } |
30 | |
31 | public int getSize() { |
32 | return this.text.length() + 1 + 4; |
33 | } |
34 | |
35 | public void setText(final String text) { |
36 | this.text = text; |
37 | } |
38 | |
39 | public String getText() { |
40 | return this.text; |
41 | } |
42 | |
43 | public void setTimeStamp(final long timeStamp) { |
44 | this.timeStamp = timeStamp; |
45 | } |
46 | |
47 | public long getTimeStamp() { |
48 | return this.timeStamp; |
49 | } |
50 | |
51 | public boolean equals(final Object obj) { |
52 | if ((obj instanceof ObjectID3v2LyricLine) == false) { |
53 | return false; |
54 | } |
55 | final ObjectID3v2LyricLine objectID3v2LyricLine = (ObjectID3v2LyricLine) obj; |
56 | if (this.text.equals(objectID3v2LyricLine.text) == false) { |
57 | return false; |
58 | } |
59 | if (this.timeStamp != objectID3v2LyricLine.timeStamp) { |
60 | return false; |
61 | } |
62 | return super.equals(obj); |
63 | } |
64 | |
65 | public void readByteArray(final byte[] arr, final int offset) { |
66 | if (arr == null) { |
67 | throw new NullPointerException("Byte array is null"); |
68 | } |
69 | if ((offset < 0) || (offset >= arr.length)) { |
70 | throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + |
71 | offset + |
72 | ", array.length = " + |
73 | arr |
74 | .length); |
75 | } |
76 | this.text = new String(arr, offset, arr.length - offset - 4); |
77 | this.timeStamp = 0; |
78 | for (int i = arr.length - 4; i < arr.length; i++) { |
79 | this.timeStamp <<= 8; |
80 | this.timeStamp += arr[i]; |
81 | } |
82 | } |
83 | |
84 | public String toString() { |
85 | return this.timeStamp + " " + this.text; |
86 | } |
87 | |
88 | public byte[] writeByteArray() { |
89 | int i; |
90 | final byte[] arr = new byte[getSize()]; |
91 | for (i = 0; i < this.text.length(); i++) { |
92 | arr[i] = (byte) this.text.charAt(i); |
93 | } |
94 | arr[i++] = 0; |
95 | arr[i++] = (byte) ((this.timeStamp & 0xFF000000) >> 24); |
96 | arr[i++] = (byte) ((this.timeStamp & 0x00FF0000) >> 16); |
97 | arr[i++] = (byte) ((this.timeStamp & 0x0000FF00) >> 8); |
98 | arr[i] = (byte) (this.timeStamp & 0x000000FF); |
99 | return arr; |
100 | } |
101 | } |