1 | package org.farng.mp3.object; |
2 | |
3 | /** |
4 | * ID3v2 and Lyrics3v2 tags have individual fields <code>AbstractMP3Fragment</code>s Then each fragment is broken down |
5 | * in to individual <code>AbstractMP3Object</code>s |
6 | * |
7 | * @author Eric Farng |
8 | * @version $Revision: 1.5 $ |
9 | */ |
10 | public class ObjectByteArraySizeTerminated extends AbstractMP3Object { |
11 | |
12 | /** |
13 | * Creates a new ObjectByteArraySizeTerminated object. |
14 | */ |
15 | public ObjectByteArraySizeTerminated(final String identifier) { |
16 | this.identifier = identifier; |
17 | } |
18 | |
19 | /** |
20 | * Creates a new ObjectByteArraySizeTerminated object. |
21 | */ |
22 | public ObjectByteArraySizeTerminated(final ObjectByteArraySizeTerminated object) { |
23 | super(object); |
24 | } |
25 | |
26 | public int getSize() { |
27 | int len = 0; |
28 | if (this.value != null) { |
29 | len = ((byte[]) this.value).length; |
30 | } |
31 | return len; |
32 | } |
33 | |
34 | public boolean equals(final Object obj) { |
35 | if (obj instanceof ObjectByteArraySizeTerminated == false) { |
36 | return false; |
37 | } |
38 | return super.equals(obj); |
39 | } |
40 | |
41 | public void readByteArray(final byte[] arr, final int offset) { |
42 | if (arr == null) { |
43 | throw new NullPointerException("Byte array is null"); |
44 | } |
45 | if ((offset < 0) || (offset >= arr.length)) { |
46 | throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + |
47 | offset + |
48 | ", array.length = " + |
49 | arr |
50 | .length); |
51 | } |
52 | final int len = arr.length - offset; |
53 | this.value = new byte[len]; |
54 | System.arraycopy(arr, offset, this.value, 0, len); |
55 | } |
56 | |
57 | public String toString() { |
58 | return getSize() + " bytes"; |
59 | } |
60 | |
61 | public byte[] writeByteArray() { |
62 | return (byte[]) this.value; |
63 | } |
64 | } |