Package com.epam.common.utils
Class ByteBuffer
java.lang.Object
com.epam.common.utils.ByteBuffer
The byte buffer helper class.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates theByteBuffer
with allocated byte buffer.ByteBuffer
(int length) Creates theByteBuffer
with allocated byte buffer.ByteBuffer
(int length, boolean useNIOBuffer) ByteBuffer
(int length, int growIncrement) ByteBuffer
(int size, int growIncrement, boolean useNIOBuffer) -
Method Summary
Modifier and TypeMethodDescriptionadd
(byte b) Adds byte to buffer.add
(byte[] array) Appends the array argument to internal buffer.add
(byte[] array, int start, int len) Appends the array argument to internal buffer.add
(char b) Adds char to buffer.add
(ByteBuffer buffer) add
(ByteBuffer buffer) addLikeString
(long value) void
checkAndExtend
(int length) static ByteBuffer
demand
(int size) flip()
byte
get()
get
(byte[] dst) get
(byte[] dst, int offset, int length) byte
get
(int index) byte[]
getBulk()
byte[]
Gets internal byte buffer.byte[]
getByteArray
(int position, int length) Gets internal byte buffer.char
getChar()
char
getChar
(int index) double
double
getDouble
(int index) int
getInt()
int
getInt
(int index) int
Gets buffer length.long
getLong()
long
getLong
(int index) int
Gets buffer offset.byte[]
getSubArray
(int start, int length) void
increaseBuffer
(int increase) Increases the buffer.boolean
isAvailable
(int length) Checks if buffer has a numOfBytes.boolean
isEmpty()
int
limit()
limit
(int limit) int
position()
position
(int position) put
(byte b) put
(byte[] src) put
(byte[] src, int offset, int length) put
(int index, byte b) putChar
(char value) putChar
(int index, char value) putDouble
(double value) putDouble
(int index, double value) putInAll
(int start, int end, byte value) putInt
(int value) putInt
(int index, int value) putLong
(int index, long value) putLong
(long value) void
release()
static void
release
(ByteBuffer buffer) int
void
Resets the buffer.void
setOffset
(int offset) Sets offset of buffer.static ByteBuffer
wrapBuffer
(byte[] buffer)
-
Field Details
-
NO_GROWTH_INCREMENT
public static final int NO_GROWTH_INCREMENT- See Also:
-
-
Constructor Details
-
ByteBuffer
public ByteBuffer()Creates theByteBuffer
with allocated byte buffer. The default buffer length if 1024 bytes. -
ByteBuffer
public ByteBuffer(int length) Creates theByteBuffer
with allocated byte buffer.- Parameters:
length
- allocated buffer length
-
ByteBuffer
public ByteBuffer(int length, boolean useNIOBuffer) -
ByteBuffer
public ByteBuffer(int length, int growIncrement) -
ByteBuffer
public ByteBuffer(int size, int growIncrement, boolean useNIOBuffer) - Parameters:
size
- buffer size in bytesgrowIncrement
- grow size in bytesuseNIOBuffer
-
-
-
Method Details
-
getBuffer
-
addLikeString
-
checkAndExtend
public void checkAndExtend(int length) -
add
-
put
-
add
Appends the array argument to internal buffer.- Returns:
- a reference to this object.
-
add
Adds byte to buffer.- Parameters:
b
- a byte
-
add
Adds char to buffer.- Parameters:
b
- a char
-
add
Appends the array argument to internal buffer.- Returns:
- a reference to this object.
-
add
-
add
-
isAvailable
public boolean isAvailable(int length) Checks if buffer has a numOfBytes.- Parameters:
length
- the requested space- Returns:
- boolean true if has
-
setOffset
public void setOffset(int offset) Sets offset of buffer.- Parameters:
offset
- the new offset
-
increaseBuffer
public void increaseBuffer(int increase) Increases the buffer.- Parameters:
increase
- the number of bytes
-
getByteArray
public byte[] getByteArray()Gets internal byte buffer. -
getByteArray
public byte[] getByteArray(int position, int length) Gets internal byte buffer. -
release
public void release() -
limit
public int limit() -
limit
-
position
public int position() -
position
-
put
-
put
-
get
public byte get() -
get
public byte get(int index) -
put
-
put
-
get
-
get
-
putChar
-
putChar
-
getChar
public char getChar() -
getChar
public char getChar(int index) -
putInt
-
putInt
-
getInt
public int getInt() -
getInt
public int getInt(int index) -
putLong
-
putLong
-
getLong
public long getLong() -
getLong
public long getLong(int index) -
putDouble
-
putDouble
-
getDouble
public double getDouble() -
getDouble
public double getDouble(int index) -
putInAll
-
remaining
public int remaining() -
flip
-
demand
-
release
-
getNioBuffer
-
resetBuffer
public void resetBuffer()Resets the buffer. -
getOffset
public int getOffset()Gets buffer offset. -
getLength
public int getLength()Gets buffer length.- Returns:
- int length
-
getBulk
public byte[] getBulk() -
isEmpty
public boolean isEmpty() -
wrapBuffer
-
getSubArray
public byte[] getSubArray(int start, int length)
-