com.ericsson.tic.vi
Class RawBuffer

java.lang.Object
  extended by com.ericsson.tic.vi.RawBuffer

public class RawBuffer
extends Object

This is a buffer which stores char arrays. Buffer overflow leads to the oldest data beeing overwritten. The buffer is synchronized for writing only. Only one consumer is allowed. Consumer is assumed to read the full contents of the buffer before making another call to swap.

Version:
1.0 (2008-12-04)
Author:
Sami Matilainen

Field Summary
private  int capacity
          The capacity/height of the buffer.
private  Object lock
          Lock used for synchronizing the buffer while writing and swapping
private  int readFront
          Pointer.
private  int readRear
          Pointer.
private  char[][] readSide
          The read side of the buffer.
private  char[][] temp
          A temp.
private  int width
          The width of the buffer.
private  int writeFront
          Pointer.
private  int writeRear
          Pointer.
private  char[][] writeSide
          The write side of the buffer.
 
Constructor Summary
RawBuffer(int width, int capacity)
          Creates a new double-sided, circular, buffer.
 
Method Summary
 void deposit(char[] line)
          Deposits a line of text into the buffer on the write side.
 void deposit(char[] line, int dataLength)
          Deposits a line of text into the buffer on the write side.
 boolean empty()
          Determine wheter the buffer is empty or not.
 char[] fetch()
          Fetches a line of text from the read side of the buffer.
 int getWidth()
          Get the width of this buffer.
 void swap()
          Swaps the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writeSide

private char[][] writeSide
The write side of the buffer.


readSide

private char[][] readSide
The read side of the buffer.


temp

private char[][] temp
A temp. buffer used for swaps.


width

private int width
The width of the buffer.


capacity

private int capacity
The capacity/height of the buffer. Actual capacity is capacity-1


readRear

private int readRear
Pointer.


writeRear

private int writeRear
Pointer.


writeFront

private int writeFront
Pointer.


readFront

private int readFront
Pointer.


lock

private Object lock
Lock used for synchronizing the buffer while writing and swapping

Constructor Detail

RawBuffer

public RawBuffer(int width,
                 int capacity)
Creates a new double-sided, circular, buffer. Buffer overflow leads to the oldest data beeing overwritten.

Parameters:
width - The width of the buffer.
capacity - Capacity of the buffer.
Method Detail

getWidth

public int getWidth()
Get the width of this buffer.

Returns:
The width of this buffer.

swap

public void swap()
Swaps the buffer.


fetch

public char[] fetch()
             throws Exception
Fetches a line of text from the read side of the buffer.

Returns:
A line from the buffer.
Throws:
If - the buffer is empty.
Exception

empty

public boolean empty()
Determine wheter the buffer is empty or not.

Returns:
True if and only if the read side of the buffer is empty.

deposit

public void deposit(char[] line)
Deposits a line of text into the buffer on the write side.

Parameters:
line - The line of text to be deposited.

deposit

public void deposit(char[] line,
                    int dataLength)
Deposits a line of text into the buffer on the write side. This version is optimized to read only relevant chars.

Parameters:
line - The line of text to be deposited.
dataLength - The amount of characters to be read