public class XByteBuffer extends Object
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
XByteBuffer(byte[] data,
boolean discard) |
XByteBuffer(byte[] data,
int size,
boolean discard) |
XByteBuffer(int size,
boolean discard)
Constructs a new XByteBuffer.
|
Modifier and Type | Method and Description |
---|---|
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,
byte[] data,
int offset)
Converts a boolean to a 1-byte array
|
static byte[] |
toBytes(int n,
byte[] b,
int offset)
Converts an integer to four bytes
|
static byte[] |
toBytes(long n,
byte[] b,
int offset)
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
|
void |
trim(int length) |
protected byte[] buf
protected int bufSize
protected boolean discard
START_DATA
it will be thrown away.public XByteBuffer(int size, boolean discard)
size
- - the initial size of the byte bufferpublic XByteBuffer(byte[] data, boolean discard)
public XByteBuffer(byte[] data, int size, boolean discard)
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 bufferpublic ChannelData extractPackage(boolean clearFromBuffer)
public static byte[] createDataPackage(ChannelData cdata)
cdata
- - the message data to be contained within the packagepublic 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 offsetArrayIndexOutOfBoundsException
public static long toLong(byte[] b, int off)
b
- - the byte array containing the four bytesoff
- - the offsetArrayIndexOutOfBoundsException
public static byte[] toBytes(boolean bool, byte[] data, int offset)
bool
- - the integerpublic static boolean toBoolean(byte[] b, int offset)
b
- byte arrayoffset
- within byte arraypublic static byte[] toBytes(int n, byte[] b, int offset)
n
- - the integerpublic static byte[] toBytes(long n, byte[] b, int offset)
n
- - the longpublic 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 srcpublic static Serializable deserialize(byte[] data) throws IOException, ClassNotFoundException, ClassCastException
public static Serializable deserialize(byte[] data, int offset, int length) throws IOException, ClassNotFoundException, ClassCastException
public static Serializable deserialize(byte[] data, int offset, int length, ClassLoader[] cls) throws IOException, ClassNotFoundException, ClassCastException
public static byte[] serialize(Serializable msg) throws IOException
msg
- ClusterMessageIOException
public void setDiscard(boolean discard)
public boolean getDiscard()
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.