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

COVERAGE SUMMARY FOR SOURCE FILE [AbstractID3v2.java]

nameclass, %method, %block, %line, %
AbstractID3v2.java100% (1/1)61%  (27/44)63%  (405/638)57%  (102/179)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AbstractID3v2100% (1/1)61%  (27/44)63%  (405/638)57%  (102/179)
append (RandomAccessFile): void 0%   (0/1)0%   (0/43)0%   (0/17)
appendDuplicateFrameId (String): void 0%   (0/1)0%   (0/12)0%   (0/2)
getDuplicateBytes (): int 0%   (0/1)0%   (0/3)0%   (0/1)
getDuplicateFrameId (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getEmptyFrameBytes (): int 0%   (0/1)0%   (0/3)0%   (0/1)
getFileReadBytes (): int 0%   (0/1)0%   (0/3)0%   (0/1)
getInvalidFrameBytes (): int 0%   (0/1)0%   (0/3)0%   (0/1)
getMajorVersion (): byte 0%   (0/1)0%   (0/3)0%   (0/1)
getPaddingSize (): int 0%   (0/1)0%   (0/3)0%   (0/1)
getRevision (): byte 0%   (0/1)0%   (0/3)0%   (0/1)
incrementDuplicateBytes (int): void 0%   (0/1)0%   (0/7)0%   (0/2)
incrementEmptyFrameBytes (int): void 0%   (0/1)0%   (0/7)0%   (0/2)
overwrite (AbstractMP3Tag): void 0%   (0/1)0%   (0/31)0%   (0/10)
removeFrame (String): void 0%   (0/1)0%   (0/6)0%   (0/2)
removeFrameOfType (String): void 0%   (0/1)0%   (0/19)0%   (0/5)
values (): Collection 0%   (0/1)0%   (0/4)0%   (0/1)
write (AbstractMP3Tag): void 0%   (0/1)0%   (0/34)0%   (0/11)
overwrite (RandomAccessFile): void 100% (1/1)12%  (5/43)18%  (3/17)
delete (RandomAccessFile): void 100% (1/1)57%  (8/14)60%  (3/5)
equals (Object): boolean 100% (1/1)90%  (18/20)83%  (5/6)
<static initializer> 100% (1/1)100% (3/3)100% (1/1)
AbstractID3v2 (): void 100% (1/1)100% (35/35)100% (12/12)
AbstractID3v2 (AbstractID3v2): void 100% (1/1)100% (95/95)100% (25/25)
append (AbstractMP3Tag): void 100% (1/1)100% (36/36)100% (11/11)
byteArrayToSize (byte []): int 100% (1/1)100% (22/22)100% (1/1)
clearFrameMap (): void 100% (1/1)100% (4/4)100% (2/2)
decrementPaddingCounter (): void 100% (1/1)100% (5/5)100% (2/2)
getFrame (String): AbstractID3v2Frame 100% (1/1)100% (6/6)100% (1/1)
getFrameCount (): int 100% (1/1)100% (11/11)100% (4/4)
getFrameIterator (): Iterator 100% (1/1)100% (5/5)100% (1/1)
getFrameOfType (String): Iterator 100% (1/1)100% (34/34)100% (7/7)
getPaddingCounter (): int 100% (1/1)100% (2/2)100% (1/1)
hasFrame (String): boolean 100% (1/1)100% (5/5)100% (1/1)
hasFrameOfType (String): boolean 100% (1/1)100% (25/25)100% (7/7)
incrementInvalidFrameBytes (): void 100% (1/1)100% (7/7)100% (2/2)
incrementPaddingCounter (): void 100% (1/1)100% (5/5)100% (2/2)
iterator (): Iterator 100% (1/1)100% (5/5)100% (1/1)
resetPaddingCounter (): void 100% (1/1)100% (3/3)100% (2/2)
setFileReadBytes (int): void 100% (1/1)100% (4/4)100% (2/2)
setFrame (AbstractID3v2Frame): void 100% (1/1)100% (11/11)100% (3/3)
setMajorVersion (byte): void 100% (1/1)100% (4/4)100% (2/2)
setPaddingSize (int): void 100% (1/1)100% (4/4)100% (2/2)
setRevision (byte): void 100% (1/1)100% (4/4)100% (2/2)
sizeToByteArray (int): byte [] 100% (1/1)100% (39/39)100% (6/6)

1package org.farng.mp3.id3;
2 
3import org.farng.mp3.AbstractMP3Tag;
4import org.farng.mp3.TagException;
5import org.farng.mp3.TagNotFoundException;
6import org.farng.mp3.TagUtility;
7 
8import java.io.IOException;
9import java.io.RandomAccessFile;
10import java.util.Collection;
11import java.util.HashMap;
12import java.util.HashSet;
13import java.util.Iterator;
14import java.util.Map;
15import java.util.Set;
16 
17/**
18 * Superclass for all ID3v2 tags
19 *
20 * @author Eric Farng
21 * @version $Revision: 1.5 $
22 */
23public abstract class AbstractID3v2 extends AbstractID3 {
24 
25    /**
26     * just used to add up the padding. the size written to the file is determined by file pointer
27     */
28    private static int paddingCounter = 0;
29    private Map frameMap = null;
30    private String duplicateFrameId = null;
31    private byte majorVersion = (byte) 0;
32    private byte revision = (byte) 0;
33    private int duplicateBytes = 0;
34    private int emptyFrameBytes = 0;
35    private int fileReadSize = 0;
36    private int invalidFrameBytes = 0;
37    private int padding = 0;
38 
39    /**
40     * Creates a new AbstractID3v2 object.
41     */
42    protected AbstractID3v2() {
43        super();
44        frameMap = new HashMap();
45    }
46 
47    /**
48     * Creates a new AbstractID3v2 object.
49     */
50    protected AbstractID3v2(final AbstractID3v2 copyObject) {
51        super(copyObject);
52        frameMap = new HashMap();
53        duplicateFrameId = copyObject.duplicateFrameId;
54        majorVersion = copyObject.majorVersion;
55        revision = copyObject.revision;
56        duplicateBytes = copyObject.duplicateBytes;
57        emptyFrameBytes = copyObject.emptyFrameBytes;
58        fileReadSize = copyObject.fileReadSize;
59        invalidFrameBytes = copyObject.invalidFrameBytes;
60        padding = copyObject.padding;
61        final Iterator iterator = copyObject.frameMap.keySet().iterator();
62        String identifier;
63        AbstractID3v2Frame newFrame;
64        while (iterator.hasNext()) {
65            identifier = (String) iterator.next();
66            newFrame = (AbstractID3v2Frame) TagUtility.copyObject(copyObject.frameMap.get(identifier));
67            frameMap.put(newFrame.getIdentifier(), newFrame);
68        }
69    }
70 
71    public void setFrame(final AbstractID3v2Frame frame) {
72        if (frame.getBody() != null) {
73            frameMap.put(frame.getIdentifier(), frame);
74        }
75    }
76 
77    public AbstractID3v2Frame getFrame(final String identifier) {
78        return (AbstractID3v2Frame) frameMap.get(identifier);
79    }
80 
81    public int getFrameCount() {
82        int size = 0;
83        if (frameMap != null) {
84            size = frameMap.size();
85        }
86        return size;
87    }
88 
89    public void clearFrameMap() {
90        this.frameMap.clear();
91    }
92 
93    public Iterator getFrameIterator() {
94        return this.frameMap.values().iterator();
95    }
96 
97    public Iterator getFrameOfType(final String identifier) {
98        final Iterator iterator = frameMap.keySet().iterator();
99        final Set result = new HashSet(frameMap.size());
100        String hashSetKey;
101        while (iterator.hasNext()) {
102            hashSetKey = (String) iterator.next();
103            if (hashSetKey.startsWith(identifier)) {
104                result.add(frameMap.get(hashSetKey));
105            }
106        }
107        return result.iterator();
108    }
109 
110    public boolean hasFrame(final String identifier) {
111        return frameMap.containsKey(identifier);
112    }
113 
114    public boolean hasFrameOfType(final String identifier) {
115        final Iterator iterator = frameMap.keySet().iterator();
116        String hashMapKey;
117        boolean found = false;
118        while (iterator.hasNext() && !found) {
119            hashMapKey = (String) iterator.next();
120            if (hashMapKey.startsWith(identifier)) {
121                found = true;
122            }
123        }
124        return found;
125    }
126 
127    public Iterator iterator() {
128        return frameMap.values().iterator();
129    }
130 
131    public void removeFrame(final String identifier) {
132        frameMap.remove(identifier);
133    }
134 
135    public void removeFrameOfType(final String identifier) {
136        final Iterator iterator = getFrameOfType(identifier);
137        while (iterator.hasNext()) {
138            final AbstractID3v2Frame frame = (AbstractID3v2Frame) iterator.next();
139            frameMap.remove(frame.getIdentifier());
140        }
141    }
142 
143    public Collection values() {
144        return frameMap.values();
145    }
146 
147    public void append(final AbstractMP3Tag abstractMP3Tag) {
148        final AbstractID3v2 oldTag = this;
149        final AbstractID3v2 newTag;
150        if (abstractMP3Tag != null) {
151            if (abstractMP3Tag instanceof AbstractID3v2) {
152                newTag = (AbstractID3v2) abstractMP3Tag;
153            } else {
154                newTag = new ID3v2_4(abstractMP3Tag);
155            }
156            final Iterator iterator = newTag.getFrameIterator();
157            AbstractID3v2Frame frame;
158            while (iterator.hasNext()) {
159                frame = (AbstractID3v2Frame) iterator.next();
160                if (!oldTag.hasFrame(frame.getIdentifier())) {
161                    oldTag.setFrame(frame);
162                }
163            }
164        }
165    }
166 
167    public void append(final RandomAccessFile file) throws IOException, TagException {
168        AbstractID3v2 oldTag;
169        try {
170            oldTag = new ID3v2_4(file);
171            oldTag.append(this);
172            oldTag.write(file);
173        } catch (TagNotFoundException ex) {
174            try {
175                oldTag = new ID3v2_3(file);
176                oldTag.append(this);
177                oldTag.write(file);
178            } catch (TagNotFoundException ex2) {
179                try {
180                    oldTag = new ID3v2_2(file);
181                    oldTag.append(this);
182                    oldTag.write(file);
183                } catch (TagNotFoundException ex3) {
184                    write(file);
185                }
186            }
187        }
188    }
189 
190    public void delete(final RandomAccessFile file) throws IOException {
191        // this works by just erasing the "TAG" tag at the beginning
192        // of the file
193        final byte[] buffer = new byte[3];
194        if (seek(file)) {
195            file.seek(0);
196            file.write(buffer);
197        }
198    }
199 
200    public boolean equals(final Object obj) {
201        if (!(obj instanceof AbstractID3v2)) {
202            return false;
203        }
204        final AbstractID3v2 abstractID3v2 = (AbstractID3v2) obj;
205        if (!frameMap.equals(abstractID3v2.frameMap)) {
206            return false;
207        }
208        return super.equals(obj);
209    }
210 
211    public void overwrite(final AbstractMP3Tag abstractMP3Tag) {
212        final AbstractID3v2 oldTag = this;
213        final AbstractID3v2 newTag;
214        if (abstractMP3Tag != null) {
215            if (abstractMP3Tag instanceof AbstractID3v2) {
216                newTag = (AbstractID3v2) abstractMP3Tag;
217            } else {
218                newTag = new ID3v2_4(abstractMP3Tag);
219            }
220            final Iterator iterator = newTag.getFrameIterator();
221            AbstractID3v2Frame frame;
222            while (iterator.hasNext()) {
223                frame = (AbstractID3v2Frame) iterator.next();
224                oldTag.setFrame(frame);
225            }
226        }
227    }
228 
229    public void overwrite(final RandomAccessFile file) throws IOException, TagException {
230        AbstractID3v2 oldTag;
231        try {
232            oldTag = new ID3v2_4(file);
233            oldTag.overwrite(this);
234            oldTag.write(file);
235        } catch (TagNotFoundException ex) {
236            try {
237                oldTag = new ID3v2_3(file);
238                oldTag.overwrite(this);
239                oldTag.write(file);
240            } catch (TagNotFoundException ex2) {
241                try {
242                    oldTag = new ID3v2_2(file);
243                    oldTag.overwrite(this);
244                    oldTag.write(file);
245                } catch (TagNotFoundException ex3) {
246                    write(file);
247                }
248            }
249        }
250    }
251 
252    public void write(final AbstractMP3Tag abstractMP3Tag) {
253        final AbstractID3v2 oldTag = this;
254        final AbstractID3v2 newTag;
255        if (abstractMP3Tag != null) {
256            if (abstractMP3Tag instanceof AbstractID3v2) {
257                newTag = (AbstractID3v2) abstractMP3Tag;
258            } else {
259                newTag = new ID3v2_4(abstractMP3Tag);
260            }
261            final Iterator iterator = newTag.getFrameIterator();
262            oldTag.frameMap.clear();
263            AbstractID3v2Frame frame;
264            while (iterator.hasNext()) {
265                frame = (AbstractID3v2Frame) iterator.next();
266                oldTag.setFrame(frame);
267            }
268        }
269    }
270 
271    protected static int byteArrayToSize(final byte[] buffer) {
272        /**
273         * the decided not to use the top bit of the 4 bytes so we need to
274         * convert the size back and forth
275         */
276        return (buffer[0] << 21) + (buffer[1] << 14) + (buffer[2] << 7) + buffer[3];
277    }
278 
279    protected static byte[] sizeToByteArray(final int size) {
280        final byte[] buffer = new byte[4];
281        buffer[0] = (byte) ((size & 0x0FE00000) >> 21);
282        buffer[1] = (byte) ((size & 0x001FC000) >> 14);
283        buffer[2] = (byte) ((size & 0x00003F80) >> 7);
284        buffer[3] = (byte) (size & 0x0000007F);
285        return buffer;
286    }
287 
288    protected static void resetPaddingCounter() {
289        paddingCounter = 0;
290    }
291 
292    protected static void incrementPaddingCounter() {
293        paddingCounter++;
294    }
295 
296    protected static void decrementPaddingCounter() {
297        paddingCounter--;
298    }
299 
300    protected static int getPaddingCounter() {
301        return paddingCounter;
302    }
303 
304    public byte getMajorVersion() {
305        return majorVersion;
306    }
307 
308    protected void setMajorVersion(final byte majorVersion) {
309        this.majorVersion = majorVersion;
310    }
311 
312    public byte getRevision() {
313        return revision;
314    }
315 
316    protected void setRevision(final byte revision) {
317        this.revision = revision;
318    }
319 
320    public int getDuplicateBytes() {
321        return duplicateBytes;
322    }
323 
324    public String getDuplicateFrameId() {
325        return duplicateFrameId;
326    }
327 
328    public int getEmptyFrameBytes() {
329        return emptyFrameBytes;
330    }
331 
332    public int getFileReadBytes() {
333        return fileReadSize;
334    }
335 
336    protected void setFileReadBytes(final int fileReadSize) {
337        this.fileReadSize = fileReadSize;
338    }
339 
340    protected void setPaddingSize(final int paddingSize) {
341        this.padding = paddingSize;
342    }
343 
344    protected void incrementDuplicateBytes(final int duplicateBytes) {
345        this.duplicateBytes += duplicateBytes;
346    }
347 
348    protected void incrementEmptyFrameBytes(final int emptyFrameBytes) {
349        this.emptyFrameBytes += emptyFrameBytes;
350    }
351 
352    protected void incrementInvalidFrameBytes() {
353        this.invalidFrameBytes++;
354    }
355 
356    protected void appendDuplicateFrameId(final String duplicateFrameId) {
357        this.duplicateFrameId += duplicateFrameId;
358    }
359 
360    public int getInvalidFrameBytes() {
361        return invalidFrameBytes;
362    }
363 
364    public int getPaddingSize() {
365        return padding;
366    }
367}

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