public class ArrayReadWriteBuf extends Object
ReadBuf using an array of bytes
as a backing storage. Using array of bytes are
usually faster than ByteBuffer.
This class is not thread-safe, meaning that
it must operate on a single thread. Operating from
multiple thread leads into a undefined behavior| Constructor and Description |
|---|
ArrayReadWriteBuf() |
ArrayReadWriteBuf(byte[] buffer) |
ArrayReadWriteBuf(byte[] buffer,
int startPos) |
ArrayReadWriteBuf(int initialCapacity) |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
data()
Expose ReadBuf as an array of bytes.
|
byte |
get(int index)
Read a byte from data.
|
boolean |
getBoolean(int index)
Read boolean from data.
|
double |
getDouble(int index)
Read a 64-bit float from data.
|
float |
getFloat(int index)
Read a 32-bit float from data.
|
int |
getInt(int index)
Read a 32-bit int from data.
|
long |
getLong(int index)
Read a 64-bit long from data.
|
short |
getShort(int index)
Read a short from data.
|
String |
getString(int start,
int size)
Read an UTF-8 string from data.
|
int |
limit()
Defines the size of the message in the buffer.
|
void |
put(byte value)
Write a byte into the buffer at
writePosition(). |
void |
put(byte[] value,
int start,
int length)
Put an array of bytes into the buffer at
writePosition(). |
void |
putBoolean(boolean value)
Put a boolean into the buffer at
writePosition() . |
void |
putDouble(double value)
Write a 64-bit float into the buffer at
writePosition(). |
void |
putFloat(float value)
Write a 32-bit float into the buffer at
writePosition(). |
void |
putInt(int value)
Write a 32-bit into in the buffer at
writePosition(). |
void |
putLong(long value)
Write a 64-bit into in the buffer at
writePosition(). |
void |
putShort(short value)
Write a 16-bit into in the buffer at
writePosition(). |
boolean |
requestCapacity(int capacity)
Request capacity of the buffer.
|
void |
set(int index,
byte value)
Read a byte from data.
|
void |
set(int index,
byte[] toCopy,
int start,
int length)
Write an array of bytes into the buffer.
|
void |
setBoolean(int index,
boolean value)
Write boolean into a given position on the buffer.
|
void |
setDouble(int index,
double value)
Read a 64-bit float from data.
|
void |
setFloat(int index,
float value)
Read a 32-bit float from data.
|
void |
setInt(int index,
int value)
Read a 32-bit int from data.
|
void |
setLong(int index,
long value)
Read a 64-bit long from data.
|
void |
setShort(int index,
short value)
Read a short from data.
|
int |
writePosition() |
public ArrayReadWriteBuf()
public ArrayReadWriteBuf(int initialCapacity)
public ArrayReadWriteBuf(byte[] buffer)
public ArrayReadWriteBuf(byte[] buffer,
int startPos)
public boolean getBoolean(int index)
index - position of the element in ReadBufpublic byte get(int index)
index - position of the element in ReadBufpublic short getShort(int index)
index - position of the element in ReadBufpublic int getInt(int index)
index - position of the element in ReadBufpublic long getLong(int index)
index - position of the element in ReadBufpublic float getFloat(int index)
index - position of the element in ReadBufpublic double getDouble(int index)
index - position of the element in ReadBufpublic String getString(int start, int size)
start - initial element of the stringsize - size of the string in bytes.Stringpublic byte[] data()
public void putBoolean(boolean value)
writePosition() . Booleans as stored as single
byte. Write position will be incremented.public void put(byte[] value,
int start,
int length)
writePosition(). Write position will be
incremented.value - the data to be copiedstart - initial position on value to be copiedlength - amount of bytes to be copiedpublic void put(byte value)
writePosition(). Write position will be
incremented.public void putShort(short value)
writePosition(). Write position will be
incremented.public void putInt(int value)
writePosition(). Write position will be
incremented.public void putLong(long value)
writePosition(). Write position will be
incremented.public void putFloat(float value)
writePosition(). Write position will be
incremented.public void putDouble(double value)
writePosition(). Write position will be
incremented.public void setBoolean(int index,
boolean value)
index - position of the element in bufferpublic void set(int index,
byte value)
index - position of the element in the bufferpublic void set(int index,
byte[] toCopy,
int start,
int length)
index - initial position of the buffer to be writtentoCopy - the data to be copiedstart - initial position on value to be copiedlength - amount of bytes to be copiedpublic void setShort(int index,
short value)
index - position of the element in ReadBufpublic void setInt(int index,
int value)
index - position of the element in ReadBufpublic void setLong(int index,
long value)
index - position of the element in ReadBufpublic void setFloat(int index,
float value)
index - position of the element in ReadBufpublic void setDouble(int index,
double value)
index - position of the element in ReadBufpublic int limit()
limit() -1.public int writePosition()
public boolean requestCapacity(int capacity)
Copyright © 2020. All rights reserved.