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 ObjectBooleanByte extends AbstractMP3Object { |
11 | |
12 | int bitPosition = -1; |
13 | |
14 | /** |
15 | * Creates a new ObjectBooleanByte object. |
16 | */ |
17 | public ObjectBooleanByte(final String identifier, final int bitPosition) { |
18 | if ((bitPosition < 0) || (bitPosition > 7)) { |
19 | throw new IndexOutOfBoundsException("Bit position needs to be from 0 - 7 : " + bitPosition); |
20 | } |
21 | this.bitPosition = bitPosition; |
22 | this.identifier = identifier; |
23 | } |
24 | |
25 | /** |
26 | * Creates a new ObjectBooleanByte object. |
27 | */ |
28 | public ObjectBooleanByte(final ObjectBooleanByte copyObject) { |
29 | super(copyObject); |
30 | this.bitPosition = copyObject.bitPosition; |
31 | } |
32 | |
33 | public int getBitPosition() { |
34 | return this.bitPosition; |
35 | } |
36 | |
37 | public int getSize() { |
38 | return 1; |
39 | } |
40 | |
41 | public boolean equals(final Object obj) { |
42 | if ((obj instanceof ObjectBooleanByte) == false) { |
43 | return false; |
44 | } |
45 | final ObjectBooleanByte objectBooleanByte = (ObjectBooleanByte) obj; |
46 | if (this.bitPosition != objectBooleanByte.bitPosition) { |
47 | return false; |
48 | } |
49 | return super.equals(obj); |
50 | } |
51 | |
52 | public void readByteArray(final byte[] arr, final int offset) { |
53 | if (arr == null) { |
54 | throw new NullPointerException("Byte array is null"); |
55 | } |
56 | if ((offset < 0) || (offset >= arr.length)) { |
57 | throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + |
58 | offset + |
59 | ", array.length = " + |
60 | arr |
61 | .length); |
62 | } |
63 | byte newValue = arr[offset]; |
64 | newValue >>= this.bitPosition; |
65 | newValue &= 0x1; |
66 | this.value = new Boolean(newValue == 1); |
67 | } |
68 | |
69 | public String toString() { |
70 | return "" + this.value; |
71 | } |
72 | |
73 | public byte[] writeByteArray() { |
74 | final byte[] retValue; |
75 | retValue = new byte[1]; |
76 | if (this.value != null) { |
77 | retValue[0] = (byte) (((Boolean) this.value).booleanValue() ? 1 : 0); |
78 | retValue[0] <<= this.bitPosition; |
79 | } |
80 | return retValue; |
81 | } |
82 | } |