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 theByteBufferwith allocated byte buffer.ByteBuffer(int length) Creates theByteBufferwith 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) voidcheckAndExtend(int length) static ByteBufferdemand(int size) flip()byteget()get(byte[] dst) get(byte[] dst, int offset, int length) byteget(int index) byte[]getBulk()byte[]Gets internal byte buffer.byte[]getByteArray(int position, int length) Gets internal byte buffer.chargetChar()chargetChar(int index) doubledoublegetDouble(int index) intgetInt()intgetInt(int index) intGets buffer length.longgetLong()longgetLong(int index) intGets buffer offset.byte[]getSubArray(int start, int length) voidincreaseBuffer(int increase) Increases the buffer.booleanisAvailable(int length) Checks if buffer has a numOfBytes.booleanisEmpty()intlimit()limit(int limit) intposition()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) voidrelease()static voidrelease(ByteBuffer buffer) intvoidResets the buffer.voidsetOffset(int offset) Sets offset of buffer.static ByteBufferwrapBuffer(byte[] buffer)
-
Field Details
-
NO_GROWTH_INCREMENT
public static final int NO_GROWTH_INCREMENT- See Also:
-
-
Constructor Details
-
ByteBuffer
public ByteBuffer()Creates theByteBufferwith allocated byte buffer. The default buffer length if 1024 bytes. -
ByteBuffer
public ByteBuffer(int length) Creates theByteBufferwith 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)
-