| java.lang.Object org.apache.catalina.cluster.io.XByteBuffer
XByteBuffer | public class XByteBuffer (Code) | | The XByteBuffer provides a dual functionality.
One, it stores message bytes and automatically extends the byte buffer if needed.
Two, it can encode and decode packages so that they can be defined and identified
as they come in on a socket.
author: Filip Hanik version: $Revision: 1.8 $, $Date: 2004/05/26 16:32:59 $ |
Method Summary | |
public boolean | append(byte[] b, int off, int len) Appends the data to the buffer. | public void | clear() | public int | countPackages() | public static byte[] | createDataPackage(byte[] indata) | public boolean | doesPackageExist() Method to check if a package exists in this byte buffer. | public byte[] | extractPackage(boolean clearFromBuffer) Extracts the message bytes from a package. | public static int | firstIndexOf(byte[] src, int srcOff, byte[] find) Similar to a String.IndexOf, but uses pure bytes
Parameters: src - - the source bytes to be searched Parameters: srcOff - - offset on the source buffer Parameters: find - - the string to be found within src - the index of the first matching byte. | public byte[] | getBytes() | public static void | main(String[] args) | public static void | printBuf(byte[] b) | public static byte[] | toBytes(int n) | public static byte[] | toBytes(long n) | public static int | toInt(byte[] b, int off) | public static long | toLong(byte[] b, int off) |
DEF_EXT | final static int DEF_EXT(Code) | | Default size to extend the buffer with
|
DEF_SIZE | final static int DEF_SIZE(Code) | | Default size on the initial byte buffer
|
END_DATA | final public static byte[] END_DATA(Code) | | This is the package footer, 7 bytes
|
START_DATA | final public static byte[] START_DATA(Code) | | This is a package header, 7 bytes
|
buf | protected byte[] buf(Code) | | Variable to hold the data
|
bufSize | protected int bufSize(Code) | | Current length of data in the buffer
|
log | public static org.apache.commons.logging.Log log(Code) | | |
XByteBuffer | public XByteBuffer(int size)(Code) | | Constructs a new XByteBuffer
Parameters: size - - the initial size of the byte buffer |
XByteBuffer | public XByteBuffer()(Code) | | Constructs a new XByteBuffer with an initial size of 1024 bytes
|
append | public boolean append(byte[] b, int off, int len)(Code) | | Appends the data to the buffer. If the data is incorrectly formatted, ie, the data should always start with the
header, false will be returned and the data will be discarded.
Parameters: b - - bytes to be appended Parameters: off - - the offset to extract data from Parameters: len - - the number of bytes to append. true if the data was appended correctly. Returns false if the package is incorrect, ie missing header or something, or the length of data is 0 |
clear | public void clear()(Code) | | Resets the buffer
|
countPackages | public int countPackages()(Code) | | Internal mechanism to make a check if a complete package exists
within the buffer
- true if a complete package (header,size,data,footer) exists within the buffer |
createDataPackage | public static byte[] createDataPackage(byte[] indata) throws java.io.IOException(Code) | | Creates a complete data package
Parameters: indata - - the message data to be contained within the package - a full package (header,size,data,footer) |
doesPackageExist | public boolean doesPackageExist()(Code) | | Method to check if a package exists in this byte buffer.
- true if a complete package (header,size,data,footer) exists within the buffer |
extractPackage | public byte[] extractPackage(boolean clearFromBuffer) throws java.io.IOException(Code) | | Extracts the message bytes from a package.
If no package exists, a IllegalStateException will be thrown.
Parameters: clearFromBuffer - - if true, the package will be removed from the byte buffer - returns the actual message bytes (header, size and footer not included). |
firstIndexOf | public static int firstIndexOf(byte[] src, int srcOff, byte[] find)(Code) | | Similar to a String.IndexOf, but uses pure bytes
Parameters: src - - the source bytes to be searched Parameters: srcOff - - offset on the source buffer Parameters: find - - the string to be found within src - the index of the first matching byte. -1 if the find array is not found |
getBytes | public byte[] getBytes()(Code) | | Returns the bytes in the buffer, in its exact length
|
printBuf | public static void printBuf(byte[] b)(Code) | | |
toBytes | public static byte[] toBytes(int n)(Code) | | Converts an integer to four bytes
Parameters: n - - the integer - four bytes in an array |
toBytes | public static byte[] toBytes(long n)(Code) | | Converts an long to eight bytes
Parameters: n - - the long - eight bytes in an array |
toInt | public static int toInt(byte[] b, int off)(Code) | | Convert four bytes to an int
Parameters: b - - the byte array containing the four bytes Parameters: off - - the offset the integer value constructed from the four bytes exception: java.lang.ArrayIndexOutOfBoundsException - |
toLong | public static long toLong(byte[] b, int off)(Code) | | Convert eight bytes to a long
Parameters: b - - the byte array containing the four bytes Parameters: off - - the offset the long value constructed from the eight bytes exception: java.lang.ArrayIndexOutOfBoundsException - |
|
|