public class XByteBuffer
extends java.lang.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. |
protected static StringManager |
sm |
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(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)
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 static final StringManager sm
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(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 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 offsetjava.lang.ArrayIndexOutOfBoundsException
public static long toLong(byte[] b, int off)
b
- - the byte array containing the four bytesoff
- - the offsetjava.lang.ArrayIndexOutOfBoundsException
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 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
- ClusterMessagejava.io.IOException
public void setDiscard(boolean discard)
public boolean getDiscard()
Copyright © 2000-2018 Apache Software Foundation. All Rights Reserved.