com.tffenterprises.util
Class Buffer

java.lang.Object
  extended by com.tffenterprises.util.Buffer

public class Buffer
extends java.lang.Object

Buffer is a byte buffer that knows how many bytes of real data it contains. This is useful is several byte arrays are to be juggled around, so that data remains neatly encapsulated, and memory allocations kept to a minimum.

One creates a Buffer objects with a certain maximum capacity, and then bytes can be added to it with the setData() methods.


Field Summary
(package private)  byte[] buf
          The byte array that will contain the data.
(package private)  int datalength
          The number of bytes containing valid data.
 
Constructor Summary
Buffer(int max)
          Constructor: create a buffer of fixed capacity, containing a maximum of max bytes.
 
Method Summary
 byte[] getData()
          Returns the data contained in this Buffer.
 int getDataLength()
          Returns the current length of the data contained in this Buffer.
 int getMax()
          Returns the maximum capacity of this Buffer.
 void setData(byte[] data)
          Sets the data in this buffer, copying the entire array to this buffer.
 void setData(byte[] data, int length)
          Sets the data in this buffer, copying length bytes from the byte array to this buffer.
 void setDataLength(int length)
          Change the current length of the data contained in this Buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

byte[] buf
The byte array that will contain the data.


datalength

int datalength
The number of bytes containing valid data.

Constructor Detail

Buffer

public Buffer(int max)
Constructor: create a buffer of fixed capacity, containing a maximum of max bytes.

Parameters:
max - the capacity of the Buffer.
Method Detail

getMax

public int getMax()
Returns the maximum capacity of this Buffer.

Returns:
the maximum capacity of this Buffer.

getData

public byte[] getData()
Returns the data contained in this Buffer.

Returns:
the data contained in this Buffer.

setData

public void setData(byte[] data)
Sets the data in this buffer, copying the entire array to this buffer.

Parameters:
data - the byte array to be copied into this Buffer.

setData

public void setData(byte[] data,
                    int length)
Sets the data in this buffer, copying length bytes from the byte array to this buffer.

Parameters:
data - the byte array to be copied into this Buffer.
length - how many bytes to copy from data to this Buffer.

getDataLength

public int getDataLength()
Returns the current length of the data contained in this Buffer.

Returns:
the current length of the data contained in this Buffer.

setDataLength

public void setDataLength(int length)
Change the current length of the data contained in this Buffer.

Parameters:
length - the new data length.
Throws:
java.lang.IllegalArgumentException - if length is greater than this Buffer's maximum size.