| 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 | |
import java.util.Iterator; |
| 31 | |
import java.util.LinkedList; |
| 32 | |
|
| 33 | |
public class Lyrics3Line extends AbstractDataType |
| 34 | |
{ |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | 0 | private LinkedList<Lyrics3TimeStamp> timeStamp = new LinkedList<Lyrics3TimeStamp>(); |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | 0 | private String lyric = ""; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public Lyrics3Line(String identifier, AbstractTagFrameBody frameBody) |
| 51 | |
{ |
| 52 | 0 | super(identifier, frameBody); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
public Lyrics3Line(Lyrics3Line copy) |
| 56 | |
{ |
| 57 | 0 | super(copy); |
| 58 | 0 | this.lyric = new String(copy.lyric); |
| 59 | |
Lyrics3TimeStamp newTimeStamp; |
| 60 | 0 | for (int i = 0; i < copy.timeStamp.size(); i++) |
| 61 | |
{ |
| 62 | 0 | newTimeStamp = new Lyrics3TimeStamp(copy.timeStamp.get(i)); |
| 63 | 0 | this.timeStamp.add(newTimeStamp); |
| 64 | |
} |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
public void setLyric(String lyric) |
| 68 | |
{ |
| 69 | 0 | this.lyric = lyric; |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
public void setLyric(ID3v2LyricLine line) |
| 73 | |
{ |
| 74 | 0 | this.lyric = line.getText(); |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
public String getLyric() |
| 81 | |
{ |
| 82 | 0 | return lyric; |
| 83 | |
} |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
public int getSize() |
| 89 | |
{ |
| 90 | 0 | int size = 0; |
| 91 | 0 | for (Object aTimeStamp : timeStamp) |
| 92 | |
{ |
| 93 | 0 | size += ((Lyrics3TimeStamp) aTimeStamp).getSize(); |
| 94 | |
} |
| 95 | 0 | return size + lyric.length(); |
| 96 | |
} |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
public void setTimeStamp(Lyrics3TimeStamp time) |
| 102 | |
{ |
| 103 | 0 | timeStamp.clear(); |
| 104 | 0 | timeStamp.add(time); |
| 105 | 0 | } |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
public Iterator<Lyrics3TimeStamp> getTimeStamp() |
| 111 | |
{ |
| 112 | 0 | return timeStamp.iterator(); |
| 113 | |
} |
| 114 | |
|
| 115 | |
public void addLyric(String newLyric) |
| 116 | |
{ |
| 117 | 0 | this.lyric += newLyric; |
| 118 | 0 | } |
| 119 | |
|
| 120 | |
public void addLyric(ID3v2LyricLine line) |
| 121 | |
{ |
| 122 | 0 | this.lyric += line.getText(); |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
public void addTimeStamp(Lyrics3TimeStamp time) |
| 129 | |
{ |
| 130 | 0 | timeStamp.add(time); |
| 131 | 0 | } |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
public boolean equals(Object obj) |
| 138 | |
{ |
| 139 | 0 | if ((obj instanceof Lyrics3Line) == false) |
| 140 | |
{ |
| 141 | 0 | return false; |
| 142 | |
} |
| 143 | 0 | Lyrics3Line object = (Lyrics3Line) obj; |
| 144 | 0 | if (this.lyric.equals(object.lyric) == false) |
| 145 | |
{ |
| 146 | 0 | return false; |
| 147 | |
} |
| 148 | 0 | if (this.timeStamp.equals(object.timeStamp) == false) |
| 149 | |
{ |
| 150 | 0 | return false; |
| 151 | |
} |
| 152 | 0 | return super.equals(obj); |
| 153 | |
} |
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
public boolean hasTimeStamp() |
| 159 | |
{ |
| 160 | 0 | if (timeStamp.isEmpty()) |
| 161 | |
{ |
| 162 | 0 | return false; |
| 163 | |
} |
| 164 | 0 | return true; |
| 165 | |
} |
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
public void readString(String lineString, int offset) |
| 174 | |
{ |
| 175 | 0 | if (lineString == null) |
| 176 | |
{ |
| 177 | 0 | throw new NullPointerException("Image is null"); |
| 178 | |
} |
| 179 | 0 | if ((offset < 0) || (offset >= lineString.length())) |
| 180 | |
{ |
| 181 | 0 | throw new IndexOutOfBoundsException("Offset to line is out of bounds: offset = " + offset + ", line.length()" + lineString.length()); |
| 182 | |
} |
| 183 | 0 | int delim = 0; |
| 184 | |
Lyrics3TimeStamp time; |
| 185 | 0 | timeStamp = new LinkedList<Lyrics3TimeStamp>(); |
| 186 | 0 | delim = lineString.indexOf("[", offset); |
| 187 | 0 | while (delim >= 0) |
| 188 | |
{ |
| 189 | 0 | offset = lineString.indexOf("]", delim) + 1; |
| 190 | 0 | time = new Lyrics3TimeStamp("Time Stamp"); |
| 191 | 0 | time.readString(lineString.substring(delim, offset)); |
| 192 | 0 | timeStamp.add(time); |
| 193 | 0 | delim = lineString.indexOf("[", offset); |
| 194 | |
} |
| 195 | 0 | lyric = lineString.substring(offset); |
| 196 | 0 | } |
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
public String toString() |
| 202 | |
{ |
| 203 | 0 | String str = ""; |
| 204 | 0 | for (Object aTimeStamp : timeStamp) |
| 205 | |
{ |
| 206 | 0 | str += aTimeStamp.toString(); |
| 207 | |
} |
| 208 | 0 | return "timeStamp = " + str + ", lyric = " + lyric + "\n"; |
| 209 | |
} |
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
public String writeString() |
| 215 | |
{ |
| 216 | 0 | String str = ""; |
| 217 | |
Lyrics3TimeStamp time; |
| 218 | 0 | for (Object aTimeStamp : timeStamp) |
| 219 | |
{ |
| 220 | 0 | time = (Lyrics3TimeStamp) aTimeStamp; |
| 221 | 0 | str += time.writeString(); |
| 222 | |
} |
| 223 | 0 | return str + lyric; |
| 224 | |
} |
| 225 | |
|
| 226 | |
public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException |
| 227 | |
{ |
| 228 | 0 | readString(arr.toString(), offset); |
| 229 | 0 | } |
| 230 | |
|
| 231 | |
public byte[] writeByteArray() |
| 232 | |
{ |
| 233 | 0 | return Utils.getDefaultBytes(writeString(), "ISO8859-1"); |
| 234 | |
} |
| 235 | |
} |