| java.lang.Object uk.org.ponder.byteutil.ByteWrap
All known Subclasses: uk.org.ponder.byteutil.AirByteWrap,
ByteWrap | public class ByteWrap (Code) | | A very useful utility class to wrap a sequence of bytes in an array, covering over to
some extent the lack of pointers in the Java language.
|
Field Summary | |
public byte[] | bytes The array holding the bytes represented by this ByteWrap. | public int | offset The offset within the array that the represented bytes begin. | protected int | size The number of bytes starting at offset that form the represented
sequence. |
Constructor Summary | |
public | ByteWrap() The default constructor performs no initialization, for those who wish to use
ByteWraps in the raw. | public | ByteWrap(int length) Constructs a new ByteWrap with the specified length. | public | ByteWrap(byte[] bytes, int offset, int size) Constructs a new ByteWrap wrapping a portion of an already existing array. |
Method Summary | |
public void | ensureCapacity(int requiredsize) Ensures that this ByteWrap has enough capacity in its array to store content
of the specified size, by rebinding it to a larger-sized array if necessary. | public boolean | equals(Object othero) Compares this ByteWrap with another object. | public ByteWrap | imbue(ByteWrap other, int index, int length) Imbues an already existing ByteWrap to wrap a portion of another ByteWrap. | final public static String | intToHex(int tohex) Converts an integer to a string containing a hexadecimal representation.
Parameters: tohex - THe integer to be represented. | final public static String | intToHex(int tohex, int bytes) Converts some number of low-order bytes of an integer into a hexadecimal
representation in a String.
Parameters: tohex - The integer to be converted to hex. Parameters: bytes - The number of low-order bytes (between 1 and 4) to be convertedinto hex. | public int | read_at1(int pos) Reads a byte from the specified position, interpreting
it as the low-order byte of an int .
Parameters: pos - The position from which to read the byte. | public int | read_at2(int pos) Reads two bytes starting at the specified position, interpreting
them as the low-order bytes of an int in the usual
big-endian order.
Parameters: pos - The position from which to read bytes. | public int | read_at3(int pos) Reads three bytes starting at the specified position, interpreting
them as the low-order bytes of an int in the usual
big-endian order.
Parameters: pos - The position from which to read bytes. | public int | read_at4(int pos) Reads the bytes starting at the specified position, interpreting them as a
int in the usual big-endian order.
Parameters: pos - The position from which to read bytes. | public long | read_at8(int pos) Reads the bytes starting at the specified position, interpreting them as a
long in the usual big-endian order.
Parameters: pos - The position from which to read bytes. | public void | shuffle(int fromposition, int amount) Shuffles part of the contents of this ByteWrap forwards, to make space for more
elements at a particular position. | public int | size() Returns the number of elements in the sequence wrapped by this ByteWrap. | public static char | toHex(int nibble) Converts the supplied integer in the range [0..15] into its equivalent
hexadecimal digit.
Parameters: nibble - The integer to be converted. | public String | toString() Represents this ByteWrap as a String for debugging purposes. | public void | write_at(int pos, ByteWrap other) Writes the entire sequence from another ByteWrap to a specified position into
this one. | public void | write_at(int pos, ByteWrap other, int index, int length) Writes a portion of the sequence from another ByteWrap to a specified position into
this one. | public void | write_at1(int pos, int data) Writes the low-order byte of the supplied int at the
specified position in the wrapped sequence.
Parameters: pos - The position to write the byte. Parameters: data - The data to be written. | public void | write_at2(int pos, int data) Writes the two low-order bytes of the supplied int one
byte at a time starting at the specified position in the wrapped
sequence. | public void | write_at3(int pos, int data) Writes the three low-order bytes of the supplied int one
byte at a time starting at the specified position in the wrapped
sequence. | public void | write_at4(int pos, int data) Writes the supplied int one byte at a time starting at the specified
position in the wrapped sequence. | public void | write_at8(int pos, long data) Writes the supplied long one byte at a time starting at the specified
position in the wrapped sequence. |
bytes | public byte[] bytes(Code) | | The array holding the bytes represented by this ByteWrap.
|
offset | public int offset(Code) | | The offset within the array that the represented bytes begin.
|
size | protected int size(Code) | | The number of bytes starting at offset that form the represented
sequence. Making this protected is an oddly inconistent decision, so sue me.
|
ByteWrap | public ByteWrap()(Code) | | The default constructor performs no initialization, for those who wish to use
ByteWraps in the raw.
|
ByteWrap | public ByteWrap(int length)(Code) | | Constructs a new ByteWrap with the specified length. A new array of the correct
length is constructed to represent the sequence, which begins at the beginning of
the array.
Parameters: length - The length of the ByteWrap to be constructed. |
ByteWrap | public ByteWrap(byte[] bytes, int offset, int size)(Code) | | Constructs a new ByteWrap wrapping a portion of an already existing array.
Parameters: bytes - The array holding the sequence to be wrapped. Parameters: offset - The index of the beginning of the sequence to be wrapped. Parameters: size - The length of the sequence to be wrapped. |
ensureCapacity | public void ensureCapacity(int requiredsize)(Code) | | Ensures that this ByteWrap has enough capacity in its array to store content
of the specified size, by rebinding it to a larger-sized array if necessary.
Parameters: requiredsize - The length of the sequence the ByteWrap is required tostore. |
equals | public boolean equals(Object othero)(Code) | | Compares this ByteWrap with another object. It will compare equal to another
ByteWrap wrapping the same sequence of bytes. This method is very inefficient.
Parameters: othero - The ByteWrap to be compared to. true if the other object if the supplied object is aByteWrap wrapping the same sequence of bytes. |
imbue | public ByteWrap imbue(ByteWrap other, int index, int length)(Code) | | Imbues an already existing ByteWrap to wrap a portion of another ByteWrap.
Parameters: other - The other ByteWrap containing the sequence to be wrapped. Parameters: index - The index within the other ByteWrap's sequence of the sequenceto be wrapped. Parameters: length - The length of the sequence to be wrapped. |
intToHex | final public static String intToHex(int tohex)(Code) | | Converts an integer to a string containing a hexadecimal representation.
Parameters: tohex - THe integer to be represented. A string representing the integer's value in hexadecimal. |
intToHex | final public static String intToHex(int tohex, int bytes)(Code) | | Converts some number of low-order bytes of an integer into a hexadecimal
representation in a String.
Parameters: tohex - The integer to be converted to hex. Parameters: bytes - The number of low-order bytes (between 1 and 4) to be convertedinto hex. The required hexadecimal representation. |
read_at1 | public int read_at1(int pos)(Code) | | Reads a byte from the specified position, interpreting
it as the low-order byte of an int .
Parameters: pos - The position from which to read the byte. The byte sequence interpreted as a int |
read_at2 | public int read_at2(int pos)(Code) | | Reads two bytes starting at the specified position, interpreting
them as the low-order bytes of an int in the usual
big-endian order.
Parameters: pos - The position from which to read bytes. The byte sequence interpreted as a int |
read_at3 | public int read_at3(int pos)(Code) | | Reads three bytes starting at the specified position, interpreting
them as the low-order bytes of an int in the usual
big-endian order.
Parameters: pos - The position from which to read bytes. The byte sequence interpreted as a int |
read_at4 | public int read_at4(int pos)(Code) | | Reads the bytes starting at the specified position, interpreting them as a
int in the usual big-endian order.
Parameters: pos - The position from which to read bytes. The byte sequence interpreted as a int |
read_at8 | public long read_at8(int pos)(Code) | | Reads the bytes starting at the specified position, interpreting them as a
long in the usual big-endian order.
Parameters: pos - The position from which to read bytes. The byte sequence interpreted as a long |
shuffle | public void shuffle(int fromposition, int amount)(Code) | | Shuffles part of the contents of this ByteWrap forwards, to make space for more
elements at a particular position. It is assumed there is enough space at the
end of the wrapped array to accommodate the resulting expansion of the sequence.
Parameters: fromposition - The index at which more space is to be made. Parameters: amount - The number of positions forward the data is to be shuffled. |
size | public int size()(Code) | | Returns the number of elements in the sequence wrapped by this ByteWrap.
the number of elements in the sequence wrapped by this ByteWrap. |
toHex | public static char toHex(int nibble)(Code) | | Converts the supplied integer in the range [0..15] into its equivalent
hexadecimal digit.
Parameters: nibble - The integer to be converted. The integer represented as a hexadecimal digit. |
toString | public String toString()(Code) | | Represents this ByteWrap as a String for debugging purposes. If it contains
4 characters or less, it will be compactly represented as a hexadecimal number.
If it is longer, it will be represented in a style similar to UNIX "od" or "dd"
The contents of this ByteWrap as a debug string. |
write_at | public void write_at(int pos, ByteWrap other)(Code) | | Writes the entire sequence from another ByteWrap to a specified position into
this one. The target ByteWrap is assumed to have enough space to accommodate the
data.
Parameters: pos - The position within this ByteWrap to write the sequence. Parameters: other - The ByteWrap wrapping the sequence to be copied. |
write_at | public void write_at(int pos, ByteWrap other, int index, int length)(Code) | | Writes a portion of the sequence from another ByteWrap to a specified position into
this one. The target ByteWrap is assumed to have enough space to accommodate the
data.
Parameters: pos - The position within this ByteWrap to write the sequence. Parameters: other - The ByteWrap wrapping the sequence to be copied. Parameters: index - The index within the other ByteWrap marking the start of the sequenceto be copied. Parameters: length - The length of the sequence to be copied. |
write_at1 | public void write_at1(int pos, int data)(Code) | | Writes the low-order byte of the supplied int at the
specified position in the wrapped sequence.
Parameters: pos - The position to write the byte. Parameters: data - The data to be written. |
write_at2 | public void write_at2(int pos, int data)(Code) | | Writes the two low-order bytes of the supplied int one
byte at a time starting at the specified position in the wrapped
sequence. The data is written in the normal big-endian order.
Parameters: pos - The position to start writing the bytes. Parameters: data - The data to be written. |
write_at3 | public void write_at3(int pos, int data)(Code) | | Writes the three low-order bytes of the supplied int one
byte at a time starting at the specified position in the wrapped
sequence. The data is written in the normal big-endian order.
Parameters: pos - The position to start writing the bytes. Parameters: data - The data to be written. |
write_at4 | public void write_at4(int pos, int data)(Code) | | Writes the supplied int one byte at a time starting at the specified
position in the wrapped sequence. The data is written in the normal big-endian order.
Parameters: pos - The position to start writing the bytes. Parameters: data - The data to be written. |
write_at8 | public void write_at8(int pos, long data)(Code) | | Writes the supplied long one byte at a time starting at the specified
position in the wrapped sequence. The data is written in the normal big-endian order.
Parameters: pos - The position to start writing the bytes. Parameters: data - The data to be written. |
|
|