|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.catalina.cluster.io.XByteBuffer
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.
Transfer package:
Field Summary | |
protected byte[] |
buf
Variable to hold the data |
protected int |
bufSize
Current length of data in the buffer |
static byte[] |
END_DATA
This is the package footer, 7 bytes (TLF2003) |
static org.apache.commons.logging.Log |
log
|
static byte[] |
START_DATA
This is a package header, 7 bytes (FLT2002) |
Constructor Summary | |
XByteBuffer()
Constructs a new XByteBuffer with an initial size of 1024 bytes |
|
XByteBuffer(int size)
Constructs a new XByteBuffer |
Method Summary | |
boolean |
append(byte[] b,
int off,
int len)
Appends the data to the buffer. |
void |
clear()
Resets the buffer |
int |
countPackages()
Internal mechanism to make a check if a complete package exists within the buffer |
static byte[] |
createDataPackage(byte[] indata,
int compressed)
Creates a complete data package |
boolean |
doesPackageExist()
Method to check if a package exists in this byte buffer. |
ClusterData |
extractPackage(boolean clearFromBuffer)
Extracts the message bytes from a package. |
static int |
firstIndexOf(byte[] src,
int srcOff,
byte[] find)
Similar to a String.IndexOf, but uses pure bytes |
byte[] |
getBytes()
Returns the bytes in the buffer, in its exact length |
static byte[] |
toBytes(int n)
Converts an integer to four bytes |
static byte[] |
toBytes(long n)
Converts an long to eight bytes |
static int |
toInt(byte[] b,
int off)
Convert four bytes to an int |
static long |
toLong(byte[] b,
int off)
Convert eight bytes to a long |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static org.apache.commons.logging.Log log
public static final byte[] START_DATA
public static final byte[] END_DATA
protected byte[] buf
protected int bufSize
Constructor Detail |
public XByteBuffer(int size)
size
- - the initial size of the byte bufferpublic XByteBuffer()
Method Detail |
public byte[] getBytes()
public void clear()
public boolean append(byte[] b, int off, int len)
b
- - bytes to be appendedoff
- - the offset to extract data fromlen
- - the number of bytes to append.
public int countPackages()
public boolean doesPackageExist()
public ClusterData extractPackage(boolean clearFromBuffer) throws java.io.IOException
clearFromBuffer
- - if true, the package will be removed from the byte buffer
java.io.IOException
public static int toInt(byte[] b, int off)
b
- - the byte array containing the four bytesoff
- - the offset
java.lang.ArrayIndexOutOfBoundsException
public static long toLong(byte[] b, int off)
b
- - the byte array containing the four bytesoff
- - the offset
java.lang.ArrayIndexOutOfBoundsException
public static byte[] toBytes(int n)
n
- - the integer
public static byte[] toBytes(long n)
n
- - the long
public static int firstIndexOf(byte[] src, int srcOff, byte[] find)
src
- - the source bytes to be searchedsrcOff
- - offset on the source bufferfind
- - the string to be found within src
public static byte[] createDataPackage(byte[] indata, int compressed) throws java.io.IOException
indata
- - the message data to be contained within the packagecompressed
- - compression flag for the indata buffer
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |