| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
package org.jaudiotagger.tag.datatype; |
| 25 | |
|
| 26 | |
import org.jaudiotagger.audio.generic.Utils; |
| 27 | |
import org.jaudiotagger.tag.InvalidDataTypeException; |
| 28 | |
import org.jaudiotagger.tag.id3.AbstractTagFrameBody; |
| 29 | |
|
| 30 | |
public class ID3v2LyricLine extends AbstractDataType |
| 31 | |
{ |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | 0 | String text = ""; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | long timeStamp = 0; |
| 41 | |
|
| 42 | |
public ID3v2LyricLine(String identifier, AbstractTagFrameBody frameBody) |
| 43 | |
{ |
| 44 | 0 | super(identifier, frameBody); |
| 45 | 0 | } |
| 46 | |
|
| 47 | |
public ID3v2LyricLine(ID3v2LyricLine copy) |
| 48 | |
{ |
| 49 | 0 | super(copy); |
| 50 | 0 | this.text = copy.text; |
| 51 | 0 | this.timeStamp = copy.timeStamp; |
| 52 | 0 | } |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
public int getSize() |
| 58 | |
{ |
| 59 | 0 | return text.length() + 1 + 4; |
| 60 | |
} |
| 61 | |
|
| 62 | |
public void setText(String text) |
| 63 | |
{ |
| 64 | 0 | this.text = text; |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
public String getText() |
| 71 | |
{ |
| 72 | 0 | return text; |
| 73 | |
} |
| 74 | |
|
| 75 | |
public void setTimeStamp(long timeStamp) |
| 76 | |
{ |
| 77 | 0 | this.timeStamp = timeStamp; |
| 78 | 0 | } |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
public long getTimeStamp() |
| 84 | |
{ |
| 85 | 0 | return timeStamp; |
| 86 | |
} |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
public boolean equals(Object obj) |
| 93 | |
{ |
| 94 | 0 | if (!(obj instanceof ID3v2LyricLine)) |
| 95 | |
{ |
| 96 | 0 | return false; |
| 97 | |
} |
| 98 | |
|
| 99 | 0 | ID3v2LyricLine object = (ID3v2LyricLine) obj; |
| 100 | |
|
| 101 | 0 | if (!this.text.equals(object.text)) |
| 102 | |
{ |
| 103 | 0 | return false; |
| 104 | |
} |
| 105 | |
|
| 106 | 0 | return this.timeStamp == object.timeStamp && super.equals(obj); |
| 107 | |
|
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException |
| 117 | |
{ |
| 118 | 0 | if (arr == null) |
| 119 | |
{ |
| 120 | 0 | throw new NullPointerException("Byte array is null"); |
| 121 | |
} |
| 122 | |
|
| 123 | 0 | if ((offset < 0) || (offset >= arr.length)) |
| 124 | |
{ |
| 125 | 0 | throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + offset + ", array.length = " + arr.length); |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | 0 | text = Utils.getString(arr, offset, arr.length - offset - 4, "ISO-8859-1"); |
| 130 | |
|
| 131 | |
|
| 132 | 0 | timeStamp = 0; |
| 133 | |
|
| 134 | 0 | for (int i = arr.length - 4; i < arr.length; i++) |
| 135 | |
{ |
| 136 | 0 | timeStamp <<= 8; |
| 137 | 0 | timeStamp += arr[i]; |
| 138 | |
} |
| 139 | 0 | } |
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
public String toString() |
| 145 | |
{ |
| 146 | 0 | return timeStamp + " " + text; |
| 147 | |
} |
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
public byte[] writeByteArray() |
| 153 | |
{ |
| 154 | |
int i; |
| 155 | 0 | byte[] arr = new byte[getSize()]; |
| 156 | |
|
| 157 | 0 | for (i = 0; i < text.length(); i++) |
| 158 | |
{ |
| 159 | 0 | arr[i] = (byte) text.charAt(i); |
| 160 | |
} |
| 161 | |
|
| 162 | 0 | arr[i++] = 0; |
| 163 | 0 | arr[i++] = (byte) ((timeStamp & 0xFF000000) >> 24); |
| 164 | 0 | arr[i++] = (byte) ((timeStamp & 0x00FF0000) >> 16); |
| 165 | 0 | arr[i++] = (byte) ((timeStamp & 0x0000FF00) >> 8); |
| 166 | 0 | arr[i++] = (byte) (timeStamp & 0x000000FF); |
| 167 | |
|
| 168 | 0 | return arr; |
| 169 | |
} |
| 170 | |
} |