1 | package org.farng.mp3.lyrics3; |
2 | |
3 | import org.farng.mp3.AbstractMP3Tag; |
4 | import org.farng.mp3.TagException; |
5 | import org.farng.mp3.TagNotFoundException; |
6 | import org.farng.mp3.id3.ID3v1; |
7 | |
8 | import java.io.IOException; |
9 | import java.io.RandomAccessFile; |
10 | |
11 | /** |
12 | * Super class for both Lyrics3v2 and Lyrics3v2 tags |
13 | * |
14 | * @author Eric Farng |
15 | * @version $Revision: 1.3 $ |
16 | */ |
17 | public abstract class AbstractLyrics3 extends AbstractMP3Tag { |
18 | |
19 | /** |
20 | * Creates a new AbstractLyrics3 object. |
21 | */ |
22 | public AbstractLyrics3() { |
23 | super(); |
24 | } |
25 | |
26 | /** |
27 | * Creates a new AbstractLyrics3 object. |
28 | */ |
29 | public AbstractLyrics3(final AbstractLyrics3 copyObject) { |
30 | super(copyObject); |
31 | } |
32 | |
33 | public void append(final RandomAccessFile file) throws IOException, TagException { |
34 | AbstractLyrics3 oldTag; |
35 | try { |
36 | oldTag = new Lyrics3v2(file); |
37 | oldTag.append(this); |
38 | oldTag.write(file); |
39 | } catch (TagNotFoundException ex) { |
40 | try { |
41 | oldTag = new Lyrics3v1(file); |
42 | oldTag.append(this); |
43 | oldTag.write(file); |
44 | } catch (TagNotFoundException ex2) { |
45 | this.write(file); |
46 | } |
47 | } |
48 | } |
49 | |
50 | public void delete(final RandomAccessFile file) throws IOException { |
51 | long filePointer; |
52 | ID3v1 id3v1tag = new ID3v1(); |
53 | if (seek(file)) { |
54 | id3v1tag = id3v1tag.getID3tag(file); |
55 | seek(file); |
56 | filePointer = file.getFilePointer(); |
57 | |
58 | // cut off the "LYRICSBEGIN" |
59 | filePointer -= 11; |
60 | file.setLength(filePointer); |
61 | file.seek(file.length()); |
62 | if (id3v1tag != null) { |
63 | id3v1tag.write(file); |
64 | } |
65 | } |
66 | } |
67 | |
68 | public void overwrite(final RandomAccessFile file) throws IOException, TagException { |
69 | AbstractLyrics3 oldTag; |
70 | try { |
71 | oldTag = new Lyrics3v2(file); |
72 | oldTag.overwrite(this); |
73 | oldTag.write(file); |
74 | } catch (TagNotFoundException ex) { |
75 | try { |
76 | oldTag = new Lyrics3v1(file); |
77 | oldTag.overwrite(this); |
78 | oldTag.write(file); |
79 | } catch (TagNotFoundException ex2) { |
80 | this.write(file); |
81 | } |
82 | } |
83 | } |
84 | } |