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

COVERAGE SUMMARY FOR SOURCE FILE [AbstractID3v2FrameBody.java]

nameclass, %method, %block, %line, %
AbstractID3v2FrameBody.java100% (1/1)100% (5/5)47%  (59/125)72%  (17.9/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AbstractID3v2FrameBody100% (1/1)100% (5/5)47%  (59/125)72%  (17.9/25)
writeHeader (RandomAccessFile, int): void 100% (1/1)31%  (13/42)56%  (5/9)
readHeader (RandomAccessFile): int 100% (1/1)45%  (29/65)73%  (8/11)
equals (Object): boolean 100% (1/1)91%  (10/11)90%  (0.9/1)
AbstractID3v2FrameBody (): void 100% (1/1)100% (3/3)100% (2/2)
AbstractID3v2FrameBody (AbstractID3v2FrameBody): void 100% (1/1)100% (4/4)100% (2/2)

1package org.farng.mp3.id3;
2 
3import org.farng.mp3.AbstractMP3FragmentBody;
4import org.farng.mp3.InvalidTagException;
5 
6import java.io.IOException;
7import java.io.RandomAccessFile;
8 
9/**
10 * Each ID3v2 frame contains a header and then the payload. This is the super class for the payload
11 *
12 * @author Eric Farng
13 * @version $Revision: 1.4 $
14 */
15public abstract class AbstractID3v2FrameBody extends AbstractMP3FragmentBody {
16 
17    /**
18     * Creates a new AbstractID3v2FrameBody object.
19     */
20    protected AbstractID3v2FrameBody() {
21        super();
22    }
23 
24    /**
25     * Creates a new AbstractID3v2FrameBody object.
26     */
27    protected AbstractID3v2FrameBody(final AbstractID3v2FrameBody copyObject) {
28        super(copyObject);
29    }
30 
31    public boolean equals(final Object obj) {
32        return obj instanceof AbstractID3v2FrameBody && super.equals(obj);
33    }
34 
35    protected int readHeader(final RandomAccessFile file) throws IOException, InvalidTagException {
36        final int size;
37        final byte[] buffer = new byte[3];
38        if (has6ByteHeader()) {
39            // read the 3 byte size
40            file.read(buffer, 0, 3);
41            size = (int) (buffer[0] * Math.pow(2, 16) + buffer[1] * Math.pow(2, 8) + buffer[2]);
42        } else {
43            // read the 4 byte size
44            size = file.readInt();
45 
46            // we need to skip the flag bytes;
47            file.skipBytes(2);
48        }
49        if (size == 0) {
50            throw new InvalidTagException("Found empty frame");
51        }
52        if (size <= 0 || size > file.length()) {
53            throw new InvalidTagException("Invalid size for Frame Body");
54        }
55        return size;
56    }
57 
58    protected void writeHeader(final RandomAccessFile file, final int size) throws IOException {
59        final byte[] buffer = new byte[3];
60        if (has6ByteHeader()) {
61            // write the 3 byte size;
62            buffer[0] = (byte) ((size & 0x00FF0000) >> 16);
63            buffer[1] = (byte) ((size & 0x0000FF00) >> 8);
64            buffer[2] = (byte) (size & 0x000000FF);
65            file.write(buffer);
66        } else {
67            // write the 4 byte size;
68            file.writeInt(size);
69 
70            // need to skip 2 flag bytes
71            file.skipBytes(2);
72        }
73    }
74}

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