|
Apache Tomcat 7.0.28 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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. |
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(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 Serializable |
deserialize(byte[] data)
|
static Serializable |
deserialize(byte[] data,
int offset,
int length)
|
static Serializable |
deserialize(byte[] data,
int offset,
int length,
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(Serializable msg)
Serializes a message into cluster data |
void |
setDiscard(boolean discard)
|
void |
setLength(int size)
|
static boolean |
toBoolean(byte[] b,
int offset)
Converts a byte array entry to boolean |
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 |
---|
protected byte[] buf
protected int bufSize
protected boolean discard
START_DATA
it will be thrown away.
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(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 IOException
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
ArrayIndexOutOfBoundsException
public static long toLong(byte[] b, int off)
b
- - the byte array containing the four bytesoff
- - the offset
ArrayIndexOutOfBoundsException
@Deprecated public static byte[] toBytes(boolean bool)
bool
- - the integer
public static byte[] toBytes(boolean bool, byte[] data, int offset)
public static boolean toBoolean(byte[] b, int offset)
b
- byte arrayoffset
- within byte array
@Deprecated public static byte[] toBytes(int n)
n
- - the integer
public static byte[] toBytes(int n, byte[] b, int offset)
@Deprecated 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 Serializable deserialize(byte[] data) throws IOException, ClassNotFoundException, ClassCastException
IOException
ClassNotFoundException
ClassCastException
public static Serializable deserialize(byte[] data, int offset, int length) throws IOException, ClassNotFoundException, ClassCastException
IOException
ClassNotFoundException
ClassCastException
public static Serializable deserialize(byte[] data, int offset, int length, ClassLoader[] cls) throws IOException, ClassNotFoundException, ClassCastException
IOException
ClassNotFoundException
ClassCastException
public static byte[] serialize(Serializable msg) throws IOException
msg
- ClusterMessage
IOException
public void setDiscard(boolean discard)
public boolean getDiscard()
|
Apache Tomcat 7.0.28 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |