EMMA Coverage Report (generated Tue Mar 14 21:50:42 EST 2006)
[all classes][org.farng.mp3.lyrics3]

COVERAGE SUMMARY FOR SOURCE FILE [FieldBodyIMG.java]

nameclass, %method, %block, %line, %
FieldBodyIMG.java0%   (0/1)0%   (0/19)0%   (0/447)0%   (0/98)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FieldBodyIMG0%   (0/1)0%   (0/19)0%   (0/447)0%   (0/98)
FieldBodyIMG (): void 0%   (0/1)0%   (0/8)0%   (0/3)
FieldBodyIMG (FieldBodyIMG): void 0%   (0/1)0%   (0/32)0%   (0/6)
FieldBodyIMG (ObjectLyrics3Image): void 0%   (0/1)0%   (0/13)0%   (0/4)
FieldBodyIMG (RandomAccessFile): void 0%   (0/1)0%   (0/11)0%   (0/4)
FieldBodyIMG (String): void 0%   (0/1)0%   (0/11)0%   (0/4)
addImage (ObjectLyrics3Image): void 0%   (0/1)0%   (0/6)0%   (0/2)
equals (Object): boolean 0%   (0/1)0%   (0/20)0%   (0/6)
getIdentifier (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getSize (): int 0%   (0/1)0%   (0/28)0%   (0/5)
getValue (): String 0%   (0/1)0%   (0/3)0%   (0/1)
isSubsetOf (Object): boolean 0%   (0/1)0%   (0/31)0%   (0/7)
iterator (): Iterator 0%   (0/1)0%   (0/4)0%   (0/1)
read (RandomAccessFile): void 0%   (0/1)0%   (0/43)0%   (0/10)
readString (String): void 0%   (0/1)0%   (0/64)0%   (0/16)
setValue (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
setupObjectList (): void 0%   (0/1)0%   (0/1)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/36)0%   (0/4)
write (RandomAccessFile): void 0%   (0/1)0%   (0/87)0%   (0/18)
writeString (): String 0%   (0/1)0%   (0/43)0%   (0/7)

1package org.farng.mp3.lyrics3;
2 
3import org.farng.mp3.InvalidTagException;
4import org.farng.mp3.TagConstant;
5import org.farng.mp3.TagOptionSingleton;
6import org.farng.mp3.object.ObjectLyrics3Image;
7 
8import java.io.RandomAccessFile;
9import java.util.ArrayList;
10import java.util.Iterator;
11 
12/**
13 * Link to an image files (BMP or JPG format). Image lines include filename, description and timestamp separated by
14 * delimiter - two ASCII chars 124 ("||"). Description and timestamp are optional, but if timestamp is used, and there
15 * is no description, two delimiters ("||||") should be used between the filename and the timestamp. Multiple images are
16 * allowed by using a [CR][LF] delimiter between each image line. No [CR][LF] is needed after the last image line.
17 * Number of images is not limited (except by the field size).<BR><B>Filename</B> can be in one of these formats: <UL>
18 * <LI>Filename only - when the image is located in the same path as the MP3 file (preferred, since if you move the mp3
19 * file this will still be correct) <LI>Relative Path + Filename - when the image is located in a subdirectory below the
20 * MP3 file (i.e. images\cover.jpg) <LI>Full path + Filename - when the image is located in a totally different path or
21 * drive. This will not work if the image is moved or drive letters has changed, and so should be avoided if possible
22 * (i.e. c:\images\artist.jpg)</LI></UL><B>Description</B> can be up to 250 chars long.<BR><B>Timestamp</B> must be
23 * formatted like the lyrics timestamp which is "[mm:ss]". If an image has a timestamp, then the visible image will
24 * automatically switch to that image on the timestamp play time, just the same as the selected lyrics line is switched
25 * based on timestamps.
26 *
27 * @author Eric Farng
28 * @version $Revision: 1.4 $
29 */
30public class FieldBodyIMG extends AbstractLyrics3v2FieldBody {
31 
32    private ArrayList images = new ArrayList();
33 
34    /**
35     * Creates a new FieldBodyIMG object.
36     */
37    public FieldBodyIMG() {
38        super();
39    }
40 
41    /**
42     * Creates a new FieldBodyIMG object.
43     */
44    public FieldBodyIMG(final FieldBodyIMG copyObject) {
45        super(copyObject);
46        ObjectLyrics3Image oldObject;
47        for (int i = 0; i < copyObject.images.size(); i++) {
48            oldObject = (ObjectLyrics3Image) copyObject.images.get(i);
49            this.images.add(new ObjectLyrics3Image(oldObject));
50        }
51    }
52 
53    /**
54     * Creates a new FieldBodyIMG object.
55     */
56    public FieldBodyIMG(final String imageString) {
57        readString(imageString);
58    }
59 
60    /**
61     * Creates a new FieldBodyIMG object.
62     */
63    public FieldBodyIMG(final ObjectLyrics3Image image) {
64        this.images.add(image);
65    }
66 
67    /**
68     * Creates a new FieldBodyIMG object.
69     */
70    public FieldBodyIMG(final RandomAccessFile file) throws InvalidTagException, java.io.IOException {
71        this.read(file);
72    }
73 
74    public String getIdentifier() {
75        return "IMG";
76    }
77 
78    public int getSize() {
79        int size = 0;
80        ObjectLyrics3Image image;
81        for (int i = 0; i < this.images.size(); i++) {
82            image = (ObjectLyrics3Image) this.images.get(i);
83            size += (image.getSize() + 2); // add CRLF pair
84        }
85        return size - 2; // cut off trailing crlf pair
86    }
87 
88    public boolean isSubsetOf(final Object object) {
89        if ((object instanceof FieldBodyIMG) == false) {
90            return false;
91        }
92        final ArrayList superset = ((FieldBodyIMG) object).images;
93        for (int i = 0; i < this.images.size(); i++) {
94            if (superset.contains(this.images.get(i)) == false) {
95                return false;
96            }
97        }
98        return super.isSubsetOf(object);
99    }
100 
101    public void setValue(final String value) {
102        readString(value);
103    }
104 
105    public String getValue() {
106        return writeString();
107    }
108 
109    public void addImage(final ObjectLyrics3Image image) {
110        this.images.add(image);
111    }
112 
113    public boolean equals(final Object obj) {
114        if ((obj instanceof FieldBodyIMG) == false) {
115            return false;
116        }
117        final FieldBodyIMG fieldBodyIMG = (FieldBodyIMG) obj;
118        if (this.images.equals(fieldBodyIMG.images) == false) {
119            return false;
120        }
121        return super.equals(obj);
122    }
123 
124    public Iterator iterator() {
125        return this.images.iterator();
126    }
127 
128    protected void setupObjectList() {
129//        throw new UnsupportedOperationException();
130    }
131 
132    public void read(final RandomAccessFile file) throws InvalidTagException, java.io.IOException {
133        final String imageString;
134        byte[] buffer = new byte[5];
135 
136        // read the 5 character size
137        file.read(buffer, 0, 5);
138        final int size = Integer.parseInt(new String(buffer, 0, 5));
139        if ((size == 0) && (TagOptionSingleton.getInstance().isLyrics3KeepEmptyFieldIfRead() == false)) {
140            throw new InvalidTagException("Lyircs3v2 Field has size of zero.");
141        }
142        buffer = new byte[size];
143 
144        // read the SIZE length description
145        file.read(buffer);
146        imageString = new String(buffer);
147        readString(imageString);
148    }
149 
150    public String toString() {
151        String str = getIdentifier() + " : ";
152        for (int i = 0; i < this.images.size(); i++) {
153            str += (this.images.get(i).toString() + " ; ");
154        }
155        return str;
156    }
157 
158    public void write(final RandomAccessFile file) throws java.io.IOException {
159        final int size;
160        int offset = 0;
161        byte[] buffer = new byte[5];
162        String str;
163        size = getSize();
164        str = Integer.toString(size);
165        for (int i = 0; i < (5 - str.length()); i++) {
166            buffer[i] = (byte) '0';
167        }
168        offset += (5 - str.length());
169        for (int i = 0; i < str.length(); i++) {
170            buffer[i + offset] = (byte) str.charAt(i);
171        }
172        offset += str.length();
173        file.write(buffer, 0, 5);
174        if (size > 0) {
175            str = writeString();
176            buffer = new byte[str.length()];
177            for (int i = 0; i < str.length(); i++) {
178                buffer[i] = (byte) str.charAt(i);
179            }
180            file.write(buffer);
181        }
182    }
183 
184    /**
185     * @param imageString
186     */
187    private void readString(final String imageString) {
188        // now read each picture and put in the vector;
189        ObjectLyrics3Image image;
190        String token;
191        int offset = 0;
192        int delim = imageString.indexOf(TagConstant.SEPERATOR_LINE);
193        this.images = new ArrayList();
194        while (delim >= 0) {
195            token = imageString.substring(offset, delim);
196            image = new ObjectLyrics3Image("Image");
197            image.setFilename(token);
198            this.images.add(image);
199            offset = delim + TagConstant.SEPERATOR_LINE.length();
200            delim = imageString.indexOf(TagConstant.SEPERATOR_LINE, offset);
201        }
202        if (offset < imageString.length()) {
203            token = imageString.substring(offset);
204            image = new ObjectLyrics3Image("Image");
205            image.setFilename(token);
206            this.images.add(image);
207        }
208    }
209 
210    private String writeString() {
211        String str = "";
212        ObjectLyrics3Image image;
213        for (int i = 0; i < this.images.size(); i++) {
214            image = (ObjectLyrics3Image) this.images.get(i);
215            str += (image.writeString() + TagConstant.SEPERATOR_LINE);
216        }
217        if (str.length() > 2) {
218            return str.substring(0, str.length() - 2);
219        }
220        return str;
221    }
222}

[all classes][org.farng.mp3.lyrics3]
EMMA 2.0.5312 (C) Vladimir Roubtsov