|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.arizona.cs.mbel.ByteBuffer
This class is used for temporary storage and manipulation of a stream of bytes. All of the signature classes parse themselves out of ByteBuffers, and the emitter makes large use of them for storing intermediate chunks of the final module file. This class is vaguely modelled after java.nio.ByteBuffer, but it has some extra functionality that makes it specifically useful to MBEL. The concept behind a ByteBuffer is that it is an infinitely large 0-based array of bytes. There is a current byte index pointer given by getPosition(). The user can also set the current position using setPosition(int). Setting the position to a very high value will not grow the underlying array, but writing to it will (i.e. space is not allocated until needed). Both reading and writing advance the current position pointer by the specified amount. Since one main use of the ByteBuffer is as a convenient way to write an array of bytes, the ByteBuffer maintains the index of the greatest position that has been written to. Everything up to this point is returned when you call toByteArray().
Constructor Summary | |
ByteBuffer(byte[] init)
Makes a ByteBuffer that is initially intended to be read from, not written to. |
|
ByteBuffer(int capacity)
Makes a ByteBuffer that is initially intended for writing. |
Method Summary | |
void |
back()
Decrements the current position by 1 (if >0). |
void |
concat(ByteBuffer buf)
Concatenates the given ByteBuffer to the end of this ByteBuffer, starting from 0 and ending at buf.getLast(), inclusive. |
byte |
get()
Returns the byte stored in this ByteBuffer at the current position. |
int |
getCapacity()
Returns the current maximum capacity of the underlying array. |
long |
getDWORD()
Returns a 4-byte unsigned little-endian integer, starting at the current position. |
int |
getLast()
Returns the index of the last position written to (initially -1). |
int |
getPosition()
Returns the index of the current position in the ByteBuffer. |
int |
getWORD()
Returns a 2-byte unsigned little-endian integer, starting at the current position. |
void |
pad(int align)
Pads this ByteBuffer with 0s up to the next multiple of 'align'. |
byte |
peek()
Returns the byte stored in this ByteBuffer at the current position. |
void |
put(byte data)
Writes a single byte to this ByteBuffer, at the current position. |
void |
put(byte[] data)
Writes the given byte array to this ByteBuffer, starting at the current position. |
void |
put(int b)
Writes the lowest 8 bits of the given int to this ByteBuffer, at the current position. |
void |
putDWORD(long uint32)
Writes an unsigned little-endian int32 to this ByteBuffer, starting at the current position. |
void |
putINT16(int int16)
Writes a signed little-endian int16 to this ByteBuffer, starting at the current position. |
void |
putINT32(int int32)
Writes a signed little-endian int32 to this ByteBuffer, starting at the current position. |
void |
putINT64(long int64)
Writes a signed little-endian int64 to this ByteBuffer, starting at the current position. |
void |
putR4(float r4)
Writes a float32 to this ByteBuffer, starting at the current position. |
void |
putR8(double r8)
Writes a float64 to this ByteBuffer, starting at the current position. |
void |
putTOKEN(long token)
Writes metadata token encoded in a long to this ByteBuffer, starting at the current position. |
void |
putWORD(int uint16)
Writes an unsigned little-endian int16 to this ByteBuffer, starting at the current position. |
void |
setPosition(int pos)
Sets the current position of this ByteBuffer. |
byte[] |
toByteArray()
Returns the contents of this ByteBuffer as a single contiguous byte array. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ByteBuffer(byte[] init)
init
- the initial bytes to put into the array, starting from index 0 (if null, and empty ByteBuffer is created)public ByteBuffer(int capacity)
capacity
- the minimum capacity of this ByteBuffer (for convenience)Method Detail |
public int getCapacity()
public int getPosition()
public int getLast()
public byte get()
public int getWORD()
public long getDWORD()
public byte peek()
public void setPosition(int pos)
pos
- the new position (if <0, ignored)public void back()
public byte[] toByteArray()
public void pad(int align)
align
- the value to align to (if <=0, ignored)public void put(int b)
public void put(byte data)
public void put(byte[] data)
data
- the bytes to write in this buffer (if null, writes nothing)public void putINT16(int int16)
public void putWORD(int uint16)
public void putINT32(int int32)
public void putDWORD(long uint32)
public void putTOKEN(long token)
public void putINT64(long int64)
public void putR4(float r4)
public void putR8(double r8)
public void concat(ByteBuffer buf)
buf
- the ByteBuffer to concatenate to the end of this one (if null, ignored)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |