|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.limitless.util.BitDestination
public class BitDestination
This class provides a 'sink' for data trickled in a bit or bits at a time, instead of bytes at a time. This is especially useful for protocols that have complex headers with binary-packed fields. Once all the bits have been processed through this, it provides an array of bytes or ints as desired.
| Field Summary | |
|---|---|
private int |
bitIndex
where the next bit will go in the last byte |
private int |
byteIndex
depth used |
private int |
currentInt
the int being built (bitIndex is how far from the left the next bit will go) |
(package private) static org.apache.log4j.Logger |
logger
Log4J Logger |
private static long[] |
maskHighOrder
The index value to the array indicates the number of bits that you want to REMAIN (it masks off the bits HIGHER than the chosen) |
private java.util.List |
values
this holds each byte as it fills |
| Constructor Summary | |
|---|---|
BitDestination()
|
|
| Method Summary | |
|---|---|
void |
addBits(boolean value)
Add a boolean, if it's true, a 1 is added, and if false, a 0 is added. |
void |
addBits(int value,
int bits)
Add 'bits' of value into the stream. |
void |
addBits(long value,
int bits)
Add 'bits' of value into the stream. |
void |
addBytes(byte[] value)
This adds all the bytes in 'value' to the end of the buffer |
void |
addBytes(byte[] value,
int startingByte,
int bytesToFill)
This adds a sub-set of all the bytes in value to the end of the buffer |
void |
addBytes(java.lang.String value,
int bytesToFill)
This adds the binary representation of the string in 'value' and pads it or chops it as needed to fit into bytesToFill bytes ensuring that the resulting block of data added is exactly bytesToFill bytes long. |
private void |
addRawBits(long value,
int bits)
This does the shifting and applying of a portion of value bits wide into the system. |
byte[] |
asBytes()
Fetch the data as an array of bytes |
int[] |
asInts()
Fetch teh data as an array of ints |
int |
getCurrentBitPosition()
This is seldom used and is how many bits of the last byte have been used so far. |
int |
getCurrentBytePosition()
This is seldom used and is which byte will be used to write the next bits into. |
static void |
main(java.lang.String[] args)
This exercises the class |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
static org.apache.log4j.Logger logger
private static long[] maskHighOrder
private int byteIndex
private int bitIndex
private int currentInt
private java.util.List values
| Constructor Detail |
|---|
public BitDestination()
| Method Detail |
|---|
public byte[] asBytes()
public int[] asInts()
public void addBits(int value,
int bits)
public void addBits(long value,
int bits)
public void addBits(boolean value)
public void addBytes(byte[] value)
public void addBytes(byte[] value,
int startingByte,
int bytesToFill)
public void addBytes(java.lang.String value,
int bytesToFill)
public int getCurrentBytePosition()
public int getCurrentBitPosition()
private void addRawBits(long value,
int bits)
public static void main(java.lang.String[] args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||