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.


Constructor Index

 o Buffer(byte[])
Class constructor - makes a buffer out of an array of bytes.
 o Buffer(byte[], int)
Class constructor - makes a buffer out of an array of bytes with a given initial offset.
 o Buffer(byte[], int, int)
 o Buffer(int)
Class constructor - allocates a buffer of a given size.

Method Index

 o getData()
Return the underlying byte[] array.
 o getLength()
Return current size of the object.
 o getObject()
retrieve the object associated with this buffer
 o getStart()
Return the start offset of the buffer
 o read(byte[], int, int)
Read an amount of bytes.
 o reset()
Resets buffer to initial capacity.
 o setLength(int)
Sets current size of the object.
 o setObject(Object)
associate an Object with this buffer
 o toString()
Print human-readable statistics about this buffer.
 o write(byte[], int, int)
Write an amount of bytes.

Constructors

 o Buffer
 public Buffer(int len)
Class constructor - allocates a buffer of a given size.

Parameters:
len - an int specifying the size of the buffer
 o 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.
 o 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
 o Buffer
 public Buffer(byte buf[],
               int offset,
               int len) throws IndexOutOfBoundsException

Methods

 o 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
 o toString
 public String toString()
Print human-readable statistics about this buffer.

Overrides:
toString in class Object
 o reset
 public Buffer reset()
Resets buffer to initial capacity. This resets the offset to zero, restoring its original length.

 o 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.
 o 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.
 o setLength
 public void setLength(int len)
Sets current size of the object. The size is the number of bytes after the offset.

 o 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
 o getStart
 public long getStart()
Return the start offset of the buffer

Returns:
start offset of first valid byte in buffer
See Also:
getData
 o setObject
 public void setObject(Object obj)
associate an Object with this buffer

 o getObject
 public Object getObject()
retrieve the object associated with this buffer


All Packages  Class Hierarchy  This Package  Previous  Next  Index