| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
package org.jaudiotagger.tag.datatype; |
| 25 | |
|
| 26 | |
import org.jaudiotagger.tag.InvalidDataTypeException; |
| 27 | |
import org.jaudiotagger.tag.id3.AbstractTagFrameBody; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
public class BooleanByte extends AbstractDataType |
| 33 | |
{ |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 0 | int bitPosition = -1; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public BooleanByte(String identifier, AbstractTagFrameBody frameBody, int bitPosition) |
| 47 | |
{ |
| 48 | 0 | super(identifier, frameBody); |
| 49 | 0 | if ((bitPosition < 0) || (bitPosition > 7)) |
| 50 | |
{ |
| 51 | 0 | throw new IndexOutOfBoundsException("Bit position needs to be from 0 - 7 : " + bitPosition); |
| 52 | |
} |
| 53 | |
|
| 54 | 0 | this.bitPosition = bitPosition; |
| 55 | 0 | } |
| 56 | |
|
| 57 | |
public BooleanByte(BooleanByte copy) |
| 58 | |
{ |
| 59 | 0 | super(copy); |
| 60 | 0 | this.bitPosition = copy.bitPosition; |
| 61 | 0 | } |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
public int getBitPosition() |
| 67 | |
{ |
| 68 | 0 | return bitPosition; |
| 69 | |
} |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
public int getSize() |
| 75 | |
{ |
| 76 | 0 | return 1; |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
public boolean equals(Object obj) |
| 84 | |
{ |
| 85 | 0 | if ((obj instanceof BooleanByte) == false) |
| 86 | |
{ |
| 87 | 0 | return false; |
| 88 | |
} |
| 89 | |
|
| 90 | 0 | BooleanByte object = (BooleanByte) obj; |
| 91 | |
|
| 92 | 0 | if (this.bitPosition != object.bitPosition) |
| 93 | |
{ |
| 94 | 0 | return false; |
| 95 | |
} |
| 96 | |
|
| 97 | 0 | return super.equals(obj); |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
public void readByteArray(byte[] arr, int offset) throws InvalidDataTypeException |
| 107 | |
{ |
| 108 | 0 | if (arr == null) |
| 109 | |
{ |
| 110 | 0 | throw new NullPointerException("Byte array is null"); |
| 111 | |
} |
| 112 | |
|
| 113 | 0 | if ((offset < 0) || (offset >= arr.length)) |
| 114 | |
{ |
| 115 | 0 | throw new IndexOutOfBoundsException("Offset to byte array is out of bounds: offset = " + offset + ", array.length = " + arr.length); |
| 116 | |
} |
| 117 | |
|
| 118 | 0 | byte newValue = arr[offset]; |
| 119 | |
|
| 120 | 0 | newValue >>= bitPosition; |
| 121 | 0 | newValue &= 0x1; |
| 122 | 0 | this.value = newValue == 1; |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
public String toString() |
| 129 | |
{ |
| 130 | 0 | return "" + value; |
| 131 | |
} |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
public byte[] writeByteArray() |
| 137 | |
{ |
| 138 | |
byte[] retValue; |
| 139 | |
|
| 140 | 0 | retValue = new byte[1]; |
| 141 | |
|
| 142 | 0 | if (value != null) |
| 143 | |
{ |
| 144 | 0 | retValue[0] = (byte) (((Boolean) value).booleanValue() ? 1 : 0); |
| 145 | 0 | retValue[0] <<= bitPosition; |
| 146 | |
} |
| 147 | |
|
| 148 | 0 | return retValue; |
| 149 | |
} |
| 150 | |
} |