|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.siefkes.nlstego.util.BitArray
public class BitArray
This class provides read access to an array of bits (booleans).
| Constructor Summary | |
|---|---|
BitArray(byte[] myBytes)
Creates a new instance. |
|
BitArray(InputStream in)
Creates a new instance, reading the data to wrap from an input stream. |
|
BitArray(int byteLength)
Creates a new instance. |
|
| Method Summary | |
|---|---|
int |
byteLength()
Returns the length of this array, in bytes. |
boolean |
get(int byteIndex,
int bitIndex)
Returns the value of a bit. |
byte |
getByte(int byteIndex)
Returns the value of a byte. |
byte[] |
getBytes()
Returns the internal byte array wrapped by this instance. |
boolean |
hasNext()
Checks whether there are more bits to read or set from this array. |
long |
length()
Returns the length of this array, in bits. |
boolean |
next()
Returns the next unread or unset bit from this array. |
void |
set(int byteIndex,
int bitIndex,
boolean value)
Modifies the value of a bit. |
void |
setNext(boolean value)
Returns the next unread or unset bit from this array. |
String |
toString()
Returns a string representation of this object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public BitArray(int byteLength)
byteLength - the length of the internal array of bytes (in bytes)public BitArray(byte[] myBytes)
myBytes - the array of bytes to wrap; any changes to this array
will immediately affect the wrapping bit array
public BitArray(InputStream in)
throws IOException
in - the contents of this input stream will be wrapped
IOException - if an I/O error occurs| Method Detail |
|---|
public int byteLength()
public boolean get(int byteIndex,
int bitIndex)
throws ArrayIndexOutOfBoundsException
byteIndex - the index of the byte to read from, must by in the range
from 0 to byteLength() - 1}bitIndex - the index of the bit within the byte, must in in the
range from 0 (highest-order bit) to 7 (lowest-order bit)
true for 1,
false for 0
ArrayIndexOutOfBoundsException - if one of the indexes is outside
the allowed range
public byte getByte(int byteIndex)
throws ArrayIndexOutOfBoundsException
byteIndex - the index of the byte to get, must by in the range
from 0 to byteLength() - 1}
ArrayIndexOutOfBoundsException - if the index is outside the
allowed rangepublic byte[] getBytes()
public long length()
public boolean hasNext()
false, the next call to next()
or setNext(boolean) will throw an exception.
true iff there are more bits to read or set
public boolean next()
throws ArrayIndexOutOfBoundsException
true for 1,
false for 0
ArrayIndexOutOfBoundsException - if all bits from this array
have already been read or set
public void set(int byteIndex,
int bitIndex,
boolean value)
throws ArrayIndexOutOfBoundsException
byteIndex - the index of the byte to modify, must by in the range
from 0 to byteLength() - 1}bitIndex - the index of the bit within the byte, must in in the
range from 0 (highest-order bit) to 7 (lowest-order bit)value - the new value of the specified bit: true for 1,
false for 0
ArrayIndexOutOfBoundsException - if one of the indexes is outside
the allowed range
public void setNext(boolean value)
throws ArrayIndexOutOfBoundsException
value - the new value of the bit: true for 1,
false for 0
ArrayIndexOutOfBoundsException - if all bits from this array
have already been read or setpublic String toString()
toString in class Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||