|
Apache Tomcat 6.0.53 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.catalina.tribes.io.XByteBuffer
public class 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.
THIS CLASS IS NOT THREAD SAFE
Transfer package:
Field Summary | |
---|---|
protected byte[] |
buf
Variable to hold the data |
protected int |
bufSize
Current length of data in the buffer |
protected boolean |
discard
Flag for discarding invalid packages If this flag is set to true, and append(byte[],...) is called, the data added will be inspected, and if it doesn't start with START_DATA it will be thrown away. |
static byte[] |
END_DATA
This is the package footer, 7 bytes (TLF2003) |
static int |
invokecount
|
static Log |
log
|
static byte[] |
START_DATA
This is a package header, 7 bytes (FLT2002) |
Constructor Summary | |
---|---|
XByteBuffer(byte[] data,
boolean discard)
|
|
XByteBuffer(byte[] data,
int size,
boolean discard)
|
|
XByteBuffer(int size,
boolean discard)
Constructs a new XByteBuffer. |
Method Summary | |
---|---|
boolean |
append(boolean i)
|
boolean |
append(byte i)
|
boolean |
append(byte[] b,
int off,
int len)
|
boolean |
append(java.nio.ByteBuffer b,
int len)
Appends the data to the buffer. |
boolean |
append(int i)
|
boolean |
append(long i)
|
void |
clear()
Resets the buffer |
int |
countPackages()
Internal mechanism to make a check if a complete package exists within the buffer |
int |
countPackages(boolean first)
|
static byte[] |
createDataPackage(byte[] data)
|
static byte[] |
createDataPackage(byte[] data,
int doff,
int dlength,
byte[] buffer,
int bufoff)
|
static byte[] |
createDataPackage(ChannelData cdata)
Creates a complete data package |
static java.io.Serializable |
deserialize(byte[] data)
|
static java.io.Serializable |
deserialize(byte[] data,
int offset,
int length)
|
static java.io.Serializable |
deserialize(byte[] data,
int offset,
int length,
java.lang.ClassLoader[] cls)
|
boolean |
doesPackageExist()
Method to check if a package exists in this byte buffer. |
void |
expand(int newcount)
|
XByteBuffer |
extractDataPackage(boolean clearFromBuffer)
Extracts the message bytes from a package. |
ChannelData |
extractPackage(boolean clearFromBuffer)
|
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 |
byte[] |
getBytesDirect()
|
int |
getCapacity()
|
static int |
getDataPackageLength(int datalength)
|
boolean |
getDiscard()
|
int |
getLength()
|
void |
reset()
|
static byte[] |
serialize(java.io.Serializable msg)
Serializes a message into cluster data |
void |
setDiscard(boolean discard)
|
void |
setLength(int size)
|
static boolean |
toBoolean(byte[] b,
int offset)
|
static byte[] |
toBytes(boolean bool)
Deprecated. use toBytes(boolean,byte[],int) |
static byte[] |
toBytes(boolean bool,
byte[] data,
int offset)
|
static byte[] |
toBytes(int n)
Deprecated. use toBytes(int,byte[],int) |
static byte[] |
toBytes(int n,
byte[] b,
int offset)
|
static byte[] |
toBytes(long n)
Deprecated. use toBytes(long,byte[],int) |
static byte[] |
toBytes(long n,
byte[] b,
int offset)
|
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 |
void |
trim(int length)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static Log log
public static final byte[] START_DATA
public static final byte[] END_DATA
protected byte[] buf
protected int bufSize
protected boolean discard
START_DATA
it will be thrown away.
public static int invokecount
Constructor Detail |
---|
public XByteBuffer(int size, boolean discard)
size
- - the initial size of the byte buffer
TODO use a pool of byte[] for performancepublic XByteBuffer(byte[] data, boolean discard)
public XByteBuffer(byte[] data, int size, boolean discard)
Method Detail |
---|
public int getLength()
public void setLength(int size)
public void trim(int length)
public void reset()
public byte[] getBytesDirect()
public byte[] getBytes()
public void clear()
public boolean append(java.nio.ByteBuffer b, int len)
b
- - bytes to be appendedlen
- - the number of bytes to append.
public boolean append(byte i)
public boolean append(boolean i)
public boolean append(long i)
public boolean append(int i)
public boolean append(byte[] b, int off, int len)
public void expand(int newcount)
public int getCapacity()
public int countPackages()
public int countPackages(boolean first)
public boolean doesPackageExist()
public XByteBuffer extractDataPackage(boolean clearFromBuffer)
clearFromBuffer
- - if true, the package will be removed from the byte buffer
public ChannelData extractPackage(boolean clearFromBuffer) throws java.io.IOException
java.io.IOException
public static byte[] createDataPackage(ChannelData cdata)
cdata
- - the message data to be contained within the package
public static byte[] createDataPackage(byte[] data, int doff, int dlength, byte[] buffer, int bufoff)
public static int getDataPackageLength(int datalength)
public static byte[] createDataPackage(byte[] data)
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(boolean bool)
bool
- - the boolean
public static byte[] toBytes(boolean bool, byte[] data, int offset)
public static boolean toBoolean(byte[] b, int offset)
public static byte[] toBytes(int n)
n
- - the integer
public static byte[] toBytes(int n, byte[] b, int offset)
public static byte[] toBytes(long n)
n
- - the long
public static byte[] toBytes(long n, byte[] b, int offset)
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 java.io.Serializable deserialize(byte[] data) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.ClassCastException
java.io.IOException
java.lang.ClassNotFoundException
java.lang.ClassCastException
public static java.io.Serializable deserialize(byte[] data, int offset, int length) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.ClassCastException
java.io.IOException
java.lang.ClassNotFoundException
java.lang.ClassCastException
public static java.io.Serializable deserialize(byte[] data, int offset, int length, java.lang.ClassLoader[] cls) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.ClassCastException
java.io.IOException
java.lang.ClassNotFoundException
java.lang.ClassCastException
public static byte[] serialize(java.io.Serializable msg) throws java.io.IOException
msg
- ClusterMessage
java.io.IOException
public void setDiscard(boolean discard)
public boolean getDiscard()
|
Apache Tomcat 6.0.53 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |