J-Sim v1.2.1-p7 API

drcl.util
Class CircularBuffer

java.lang.Object
  extended bydrcl.DrclObj
      extended bydrcl.util.CircularBuffer
All Implemented Interfaces:
java.lang.Cloneable, ObjectDuplicable, java.io.Serializable

public class CircularBuffer
extends DrclObj

A fixed-capacity circular buffer class for byte-stream data. This class is thread-safe.

See Also:
Serialized Form

Constructor Summary
CircularBuffer(int capacity_)
           
 
Method Summary
 int append(byte[] data_)
          Appends data to circular buffers.
 int append(byte[] data_, int length_)
          Appends data to circular buffers.
 int append(byte[] data_, int offset_, int length_)
          Appends data to circular buffers.
 void duplicate(java.lang.Object source_)
          opies the content of the source_ object to this object.
 int getAvailableSpace()
           
 int getCapacity()
           
 int getSize()
          returns the (occupied) size of the circular buffer
 int insert(byte[] data_, int pos_, int length_)
          Inserts data to circular buffers.
 int insert(byte[] data_, int pos_, int dataOffset_, int length_)
          Inserts data to circular buffers.
 byte[] read(int start_, int len_)
          Reads but not removes data from the buffer
 int remove(byte[] buf_, int size_)
          Removes bytes from the circular buffer to the specified buffer.
 int remove(byte[] buf_, int pos_, int size_)
          Removes bytes from the circular buffer to the specified buffer.
 byte[] remove(int size_)
          Removes data from the circular buffer.
 void reset()
           
 void resize(int newSize_, boolean shrink_)
           
 java.lang.String toString()
           
 
Methods inherited from class drcl.DrclObj
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CircularBuffer

public CircularBuffer(int capacity_)
Method Detail

reset

public void reset()

duplicate

public void duplicate(java.lang.Object source_)
Description copied from class: DrclObj
opies the content of the source_ object to this object. he subclass must implement this method to realize DrclObj.clone().

Specified by:
duplicate in interface ObjectDuplicable
Overrides:
duplicate in class DrclObj

append

public int append(byte[] data_)
Appends data to circular buffers.

Returns:
number of bytes that are actually moved to this buffer.

append

public int append(byte[] data_,
                  int length_)
Appends data to circular buffers.

Returns:
number of bytes that are actually moved to this buffer.

append

public int append(byte[] data_,
                  int offset_,
                  int length_)
Appends data to circular buffers. Note that data_ may be null and the buffer still allocates length_ bytes but no data is actually written to the buffer. Nothing is allocated if the buffer capacity would be exceeded or data_ is not null but length_ is greater than the length of data_.

Parameters:
offset_ - starting position in data_.
Returns:
number of bytes that are actually moved to this buffer.

insert

public int insert(byte[] data_,
                  int pos_,
                  int length_)
Inserts data to circular buffers.

Parameters:
pos_ - starting position in data_.
Returns:
number of bytes that are actually moved to this buffer.

insert

public int insert(byte[] data_,
                  int pos_,
                  int dataOffset_,
                  int length_)
Inserts data to circular buffers. Note that data_ may be null and the buffer still allocates length_ bytes but no data is actually written to the buffer. Nothing is allocated if the buffer capacity would be exceeded or data_ is not null but length_ is greater than the length of data_.

Parameters:
pos_ - starting position in data_.
dataOffset_ - offset in data_.
Returns:
number of bytes that are actually moved to this buffer.

remove

public byte[] remove(int size_)
Removes data from the circular buffer.

Parameters:
size_ - # of bytes to be removed from the buffer; removes all if size is less than 0.
Returns:
the removed data.

remove

public int remove(byte[] buf_,
                  int size_)
Removes bytes from the circular buffer to the specified buffer.

Parameters:
size_ - # of bytes to be removed from the buffer; removes all if size is less than 0.
Returns:
the # of bytes being removed.

remove

public int remove(byte[] buf_,
                  int pos_,
                  int size_)
Removes bytes from the circular buffer to the specified buffer.

Parameters:
size_ - # of bytes to be removed from the buffer; removes all if size is less than 0.
pos_ - starting position in buf_.
Returns:
the # of bytes being removed.

read

public byte[] read(int start_,
                   int len_)
Reads but not removes data from the buffer


getSize

public int getSize()
returns the (occupied) size of the circular buffer


getCapacity

public int getCapacity()

getAvailableSpace

public int getAvailableSpace()

toString

public java.lang.String toString()
Overrides:
toString in class DrclObj

resize

public void resize(int newSize_,
                   boolean shrink_)

J-Sim v1.2.1-p7 API

Copyright © 1998-2003 Distributed Real-time Computing Lab (DRCL). All Rights Reserved.     ~ To J-Sim Home ~