com.monica.javacom.util
Class MJCStringBuffer

java.lang.Object
  |
  +--com.monica.javacom.util.MJCStringBuffer

public class MJCStringBuffer
extends java.lang.Object

This class provides a buffer functionality. The buffer provides locking, adding of byte arrays, chars, char arrays, Strings, retrieving the buffer in synchronized way. The StringBuffer functionality means that the following types can be added, and a String can be received from the objects added, where the objects will be concatenated in the order of their addition to the buffer.


Constructor Summary
MJCStringBuffer(int maxBufferLength)
          Constructs the buffer.
 
Method Summary
 boolean addToBuffer(byte[] b)
          Adds a byte array to the buffer.
 boolean addToBuffer(byte[] b, int l)
          Adds the first l bytes of the byte array to the buffer.
 boolean addToBuffer(byte[] b, int off, int len)
          Adds a part of byte array specified with offset and length to the buffer.
 boolean addToBuffer(char c)
          Adds a single char to the buffer.
 boolean addToBuffer(char[] c)
          Adds a char array to the buffer.
 boolean addToBuffer(char[] c, int off, int len)
          Adds a part of char array specified with offset and length to the buffer.
 boolean addToBuffer(java.lang.String s)
          Adds a String to the buffer.
 boolean addToBuffer(java.lang.String s, int off, int len)
          Adds a part of a String specified with offset and length to the buffer.
 int available()
          Returns the number of bytes that can still be added to the buffer without rejection.
 boolean clearBuffer()
           
 java.lang.String emptyBuffer()
          Returns the contents of the buffer.
 java.lang.String emptyBuffer(int f)
          Returns the first f bytes of the buffer.
 java.lang.String getBuffer()
          Returns the contents of the buffer.
 int getBufferLength()
          Returns the actual length of the buffer.
 int getMaxBufferLength()
          Returns the maximal length of the contents of the buffer.
 boolean lock()
          Locks the buffer.
 boolean lockStatus()
          Returns the status of the locking of the buffer.
 void unlock()
          Unlocks the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MJCStringBuffer

public MJCStringBuffer(int maxBufferLength)
Constructs the buffer. The length of the contents of the buffer cannot be greater than maxBufferLength.
Parameters:
int - maxBufferLength: the maximal length of the contents of the buffer
Method Detail

lock

public boolean lock()
Locks the buffer. No content altering method can be invoked on a locked buffer.

unlock

public void unlock()
Unlocks the buffer.

getMaxBufferLength

public int getMaxBufferLength()
Returns the maximal length of the contents of the buffer.
Returns:
int: the maximal length of the contents of the buffer

getBufferLength

public int getBufferLength()
Returns the actual length of the buffer.
Returns:
int: the actual length of the contents of the buffer

addToBuffer

public boolean addToBuffer(byte[] b)
Adds a byte array to the buffer.
Parameters:
byte[] - b: the byte array to be added
Returns:
boolean: wether the adding has been successful

addToBuffer

public boolean addToBuffer(byte[] b,
                           int l)
Adds the first l bytes of the byte array to the buffer. Is equivalent to add(b,0,l).
Parameters:
byte - b[]: the byte array to be added
int - l: the length of the byte array
Returns:
boolean: wether the adding has been successful

addToBuffer

public boolean addToBuffer(byte[] b,
                           int off,
                           int len)
Adds a part of byte array specified with offset and length to the buffer.
Parameters:
byte - b[]: the byte array to be added
int - off: the beginning offset of the part (inclusive)
int - len: the length of the part
Returns:
boolean: wether the adding has been successful

addToBuffer

public boolean addToBuffer(char[] c)
Adds a char array to the buffer.
Parameters:
char[] - c: the char array to be added
Returns:
boolean: wether the adding has been successful

addToBuffer

public boolean addToBuffer(char[] c,
                           int off,
                           int len)
Adds a part of char array specified with offset and length to the buffer.
Parameters:
char - b[]: the char array to be added
int - off: the beginning offset of the part (inclusive)
int - len: the length of the part
Returns:
boolean: wether the adding has been successful

addToBuffer

public boolean addToBuffer(char c)
Adds a single char to the buffer.
Parameters:
char - c: the char to be added
Returns:
boolean: wether the adding has been successful

addToBuffer

public boolean addToBuffer(java.lang.String s)
Adds a String to the buffer.
Parameters:
String - s: the String to be added
Returns:
boolean: wether the adding has been successful

addToBuffer

public boolean addToBuffer(java.lang.String s,
                           int off,
                           int len)
Adds a part of a String specified with offset and length to the buffer.
Parameters:
String - s: the String to be added
int - off: the beginning offset of the part (inclusive)
int - len: the length of the part
Returns:
boolean: wether the adding has been successful

emptyBuffer

public java.lang.String emptyBuffer()
Returns the contents of the buffer. After this method is called, the contents of the buffer will be lost.
Returns:
String: the contents of the buffer

emptyBuffer

public java.lang.String emptyBuffer(int f)
Returns the first f bytes of the buffer. If f>getBufferLength() then the whole buffer will be returned. The part of the buffer returned will be lost.
Parameters:
int - f: the length of the requested part of the buffer
Returns:
String: the part of the buffer

getBuffer

public java.lang.String getBuffer()
Returns the contents of the buffer. The contents of the bugger won't be lost.
Returns:
String: the contents of the buffer

lockStatus

public boolean lockStatus()
Returns the status of the locking of the buffer.
Returns:
boolean: the status of the locking of the buffer. True - locked, false - unlocked.

available

public int available()
Returns the number of bytes that can still be added to the buffer without rejection.
Returns:
int: the number of bytes that can still be added to the buffer

clearBuffer

public boolean clearBuffer()