All Packages Class Hierarchy This Package Previous Next Index
Class nodeos.Buffer
java.lang.Object
|
+----nodeos.Linkable
|
+----nodeos.Buffer
- public final class Buffer
- extends Linkable
A class for buffers.
Note: There will be an interface or an abstract base class describing
common properties of buffers.
(We would prefer to use an interface here, but Pat pointed
out that the dispatch penalty in Kaffe is very high.)
For now, a buffer is represented by an array of bytes.
It also keeps track of a start index within the buffer, called offset.
Buffers can be dependent on other buffers or have dependents itself.
These buffers form a singly linked list. The first buffer in the list
contains the actual data. A buffer can be made independent, which removes
it from that list and copies the data, if necessary.
The purpose of dependent buffers is to avoid actually copying the data
if a buffer must be dispatched to multiple destinations. Instead, the
buffer is marked as dependent - which can be done in constant time.
Making it independent, which involves copying the data in the buffer,
is done in the application's context.
-
Buffer(byte[])
- Class constructor - makes a buffer out of an array of bytes.
-
Buffer(byte[], int)
- Class constructor - makes a buffer out of an array of bytes with a
given initial offset.
-
Buffer(byte[], int, int)
-
-
Buffer(int)
- Class constructor - allocates a buffer of a given size.
-
getData()
- Return the underlying byte[] array.
-
getLength()
- Return current size of the object.
-
getObject()
- retrieve the object associated with this buffer
-
getStart()
- Return the start offset of the buffer
-
read(byte[], int, int)
-
Read an amount of bytes.
-
reset()
- Resets buffer to initial capacity.
-
setLength(int)
- Sets current size of the object.
-
setObject(Object)
- associate an Object with this buffer
-
toString()
- Print human-readable statistics about this buffer.
-
write(byte[], int, int)
-
Write an amount of bytes.
Buffer
public Buffer(int len)
- Class constructor - allocates a buffer of a given size.
- Parameters:
- len - an int specifying the size of the buffer
Buffer
public Buffer(byte buf[])
- Class constructor - makes a buffer out of an array of bytes.
- Parameters:
- buf - array of bytes used by this buffer.
Buffer
public Buffer(byte buf[],
int offset)
- Class constructor - makes a buffer out of an array of bytes with a
given initial offset.
- Parameters:
- buf - array of bytes used by this buffer.
- offset - initial offset
Buffer
public Buffer(byte buf[],
int offset,
int len) throws IndexOutOfBoundsException
getLength
public final int getLength()
- Return current size of the object.
The size is the number of bytes after the start offset.
- Returns:
- current length of the buffer
toString
public String toString()
- Print human-readable statistics about this buffer.
- Overrides:
- toString in class Object
reset
public Buffer reset()
- Resets buffer to initial capacity.
This resets the offset to zero, restoring its original length.
read
public int read(byte buf[],
int offset,
int amount)
- Read an amount of bytes.
Read an amount of bytes from offset into buf. This routine takes
dependent buffers into account.
- Parameters:
- buf - destination buffer
- offset - offset in destination buffer
- amount - number of bytes to be read.
- Returns:
- actual number of bytes that were read.
write
public int write(byte buf[],
int offset,
int amount)
- Write an amount of bytes.
Write an amount of bytes to offset into buf. This routine does not
take dependent buffers into account. That is, it might overwrite data
in a master, and the data it writes to a dependent buffer might be
overwritten when that buffer is made independent. (XXX)
- Parameters:
- buf - destination buffer
- offset - offset in destination buffer
- amount - number of bytes to be read.
- Returns:
- actual number of bytes that were read.
setLength
public void setLength(int len)
- Sets current size of the object.
The size is the number of bytes after the offset.
getData
public byte[] getData()
- Return the underlying byte[] array.
This returns the byte array upon which the buffer is formed.
Note that Java doesn't have pointer arithmetic; use getStart.
- See Also:
- getStart
getStart
public long getStart()
- Return the start offset of the buffer
- Returns:
- start offset of first valid byte in buffer
- See Also:
- getData
setObject
public void setObject(Object obj)
- associate an Object with this buffer
getObject
public Object getObject()
- retrieve the object associated with this buffer
All Packages Class Hierarchy This Package Previous Next Index