public final class ByteBuffer extends Object implements Comparable<ByteBuffer>
| Modifier and Type | Field and Description |
|---|---|
static int |
CHECKSUM_MODE |
static int |
MIN_CAPACITY |
| Constructor and Description |
|---|
ByteBuffer()
Default constructor which allocates internal storage with min capacity (MIN_CAPACITY).
|
ByteBuffer(byte[] buffer)
Constructor which allocates internal storage corresponding to the specified buffer length and copies all bytes
from buffer.
|
ByteBuffer(byte[] buffer,
int length)
Constructor which allocates internal storage corresponding to the specified length and copies length of bytes
from buffer.
|
ByteBuffer(ByteBuffer byteBuffer)
Copy constructor.
|
ByteBuffer(ByteBuffer byteBuffer,
int length)
Copy constructor with specified length of bytes to be copied.
|
ByteBuffer(ByteBuffer buffer,
int offset,
int length)
Copy constructor with specified offset and length of bytes to be copied.
|
ByteBuffer(int capacity)
Constructor which allocates internal storage according to the specified capacity.
|
ByteBuffer(String str)
Constructor which allocates internal storage and copies all bytes encoded from string.
|
| Modifier and Type | Method and Description |
|---|---|
ByteBuffer |
append(byte b)
Appends a byte to byte buffer.
|
ByteBuffer |
append(byte[] buffer)
Appends bytes array to byte buffer.
|
ByteBuffer |
append(byte[] buffer,
int length)
Append bytes array to byte buffer with specified length.
|
ByteBuffer |
append(byte[] buffer,
int offset,
int length)
Appends bytes array to byte buffer from specified offset with specified length.
|
ByteBuffer |
append(ByteBuffer byteBuffer)
Appends bytes taken from specified byte buffer.
|
ByteBuffer |
append(char c)
Appends a character to byte buffer.
|
ByteBuffer |
append(long value)
Appends bytes array converted from long number.
|
ByteBuffer |
append(String str)
Appends bytes array encoded from string to byte buffer.
|
ByteBuffer |
append(ValuePtr value)
Appends bytes taken from value pointer to byte buffer.
|
ByteBuffer |
appendCheckSum(int checkSum)
Appends bytes array converted from int number in checksum format.
|
int |
capacity()
Returns capacity of the byte buffer.
|
ByteBuffer |
clear()
Clears the byte buffer.
|
int |
compareTo(ByteBuffer o) |
ByteBuffer |
copy()
Copies this byte buffer and returns a copy.
|
boolean |
equals(Object obj) |
ByteBuffer |
erase(int length)
Erases bytes from the beginning of byte buffer with specified length.
|
ByteBuffer |
erase(int length,
int startPsn)
Erases bytes from specified position and with length form byte buffer.
|
int |
findIndex(int startPsn,
byte[] subBuffer)
Finds index of bytes sub-sequence in the data of the byte buffer.
|
byte[] |
get()
Returns internal storage(byte array).
|
int |
getCheckSum()
Gets checksum corresponding to bytes kept in byte buffer.
|
byte[] |
getCopy()
Returns copy of bytes kept in byte buffer.
|
ByteBuffer |
incLength(int size)
Increases data size of byte buffer by the specified size.
|
ByteBuffer |
insert(byte[] bytes,
int pos)
Inserts the bytes array at the specified position.
|
ByteBuffer |
insert(byte[] buffer,
int length,
int startPsn)
Inserts the bytes array with length at the specified position.
|
ByteBuffer |
insert(byte[] buffer,
int offset,
int length,
int startPsn)
Inserts the bytes array from specified offset with length at the specified position.
|
ByteBuffer |
insert(ByteBuffer buffer,
int startPsn)
Inserts the content of the buffer at the specified position.
|
ByteBuffer |
insert(byte b,
int pos)
Inserts the byte at the specified position.
|
ByteBuffer |
insert(byte b,
int pos,
int times)
Inserts the byte at the specified position and at specified times.
|
ByteBuffer |
insert(char c,
int pos)
Inserts the char converted to byte at the specified position.
|
ByteBuffer |
insert(long l,
int pos)
Inserts the long number converted to bytes at the specified position.
|
ByteBuffer |
insert(String s,
int pos)
Inserts the string encoded to bytes at the specified position.
|
int |
length()
Returns size of data in the byte buffer.
|
ByteBuffer |
overwrite(byte[] buffer,
int length)
Overwrites data.
|
ByteBuffer |
overwrite(ByteBuffer byteBuffer)
Overwrites data.
|
ByteBuffer |
overwrite(int startPsn,
byte[] buffer,
int length)
Overwrites data.
|
ByteBuffer |
overwrite(int startPsn,
byte[] buffer,
int length,
int offset)
Overwrites data.
|
ByteBuffer |
reserve(int expectedCapacity)
Ensures the specified capacity is reserved.
|
ByteBuffer |
reserveSpace(int space)
Reserves additional space in the storage.
|
ByteBuffer |
resize(int newSize)
Resizes data size in byte buffer.
|
ByteBuffer |
reverse()
Reverses data in the byte buffer.
|
ByteBuffer |
reverse(int startIdx)
Reverses data in byte buffer from the specified start index.
|
ByteBuffer |
reverse(int startIdx,
int endIdx)
Reverses the specified range of data in byte buffer.
|
int |
size()
Returns size of data in the byte buffer.
|
ByteBuffer |
subBuffer(int offset)
Creates a new byte buffer from the specified offset.
|
ByteBuffer |
subBuffer(int offset,
int length)
Creates a new byte buffer from the specified offset and with the specified length.
|
String |
toString() |
ByteBuffer |
write(OutputStream outputStream)
Writes the data from the byte buffer into specified output stream.
|
public static final int MIN_CAPACITY
public static final int CHECKSUM_MODE
public ByteBuffer()
public ByteBuffer(int capacity)
capacity - size of internal byte arraypublic ByteBuffer(byte[] buffer)
buffer - bytes arraypublic ByteBuffer(byte[] buffer,
int length)
buffer - bytes arraylength - length of bytes to be copiedpublic ByteBuffer(String str)
str - string from which byte array is encoded using String.getBytes()public ByteBuffer(ByteBuffer byteBuffer)
byteBuffer - byte buffer to be copiedpublic ByteBuffer(ByteBuffer byteBuffer, int length)
byteBuffer - byte buffer to be copiedlength - length of bytes to be copiedpublic ByteBuffer(ByteBuffer buffer, int offset, int length)
buffer - byte buffer to be copiedoffset - offset from which bytes should be copiedlength - length of bytes to be copiedpublic ByteBuffer copy()
public ByteBuffer subBuffer(int offset)
offset - offsetpublic ByteBuffer subBuffer(int offset, int length)
offset - offsetlength - length of new byte bufferpublic ByteBuffer overwrite(ByteBuffer byteBuffer)
The buffer is extended if it is not big enough.
byteBuffer - byte bufferpublic ByteBuffer overwrite(byte[] buffer, int length)
The buffer is extended if it is not big enough.
buffer - buffer to take data fromlength - buffer lengthpublic ByteBuffer overwrite(int startPsn, byte[] buffer, int length)
The buffer is extended if it is not big enough.
startPsn - start position to overwrite, begins from 0buffer - buffer to take data fromlength - buffer lengthpublic ByteBuffer overwrite(int startPsn, byte[] buffer, int length, int offset)
The buffer is extended if it is not big enough.
startPsn - start position to overwrite, begins from 0buffer - buffer to take data fromlength - buffer lengthoffset - offset in the buffer to start from, begins from 0public ByteBuffer append(ByteBuffer byteBuffer)
byteBuffer - byte bufferpublic ByteBuffer append(char c)
c - character be appendedpublic ByteBuffer append(byte b)
b - byte to be appendedpublic ByteBuffer append(byte[] buffer)
buffer - bytes arraypublic ByteBuffer append(String str)
str - string to be appendedpublic ByteBuffer append(ValuePtr value)
value - value pointerpublic ByteBuffer append(byte[] buffer, int length)
buffer - bytes arraylength - lengthpublic ByteBuffer append(byte[] buffer, int offset, int length)
buffer - bytes arrayoffset - offsetlength - lengthpublic ByteBuffer append(long value)
value - numberpublic ByteBuffer appendCheckSum(int checkSum)
checkSum - checksumpublic ByteBuffer insert(ByteBuffer buffer, int startPsn)
buffer - source data buffer to insert fromstartPsn - position to insert at in the target (this) bufferpublic ByteBuffer insert(char c, int pos)
c - char to convert and insertpos - position to insert at in target (this) bufferpublic ByteBuffer insert(byte b, int pos)
b - byte to insertpos - position to insert at in target (this) bufferpublic ByteBuffer insert(byte b, int pos, int times)
b - byte to insertpos - position to insert at in the target (this) buffertimes - number of times the same byte to insert at in the target (this) bufferpublic ByteBuffer insert(long l, int pos)
l - long number to convert and insertpos - position to insert at in target (this) bufferpublic ByteBuffer insert(String s, int pos)
s - string to encode and insertpos - position to insert at in target (this) bufferpublic ByteBuffer insert(byte[] bytes, int pos)
bytes - bytes array to insertpos - position to insert at in target (this) bufferpublic ByteBuffer insert(byte[] buffer, int length, int startPsn)
buffer - bytes array to insertlength - length to usestartPsn - position to insert at in target (this) bufferpublic ByteBuffer insert(byte[] buffer, int offset, int length, int startPsn)
buffer - bytes array to insertoffset - offset in bytes array to start from, begins from 0length - length to usestartPsn - position to insert at in target (this) bufferpublic int capacity()
public ByteBuffer clear()
public ByteBuffer erase(int length)
length - length of bytes to be removedpublic ByteBuffer erase(int length, int startPsn)
length - length of bytes to be removedstartPsn - starting position from where bytes will be removedpublic byte[] get()
public byte[] getCopy()
public int getCheckSum()
public ByteBuffer reserveSpace(int space)
space - number of bytes added to storagepublic ByteBuffer reserve(int expectedCapacity)
expectedCapacity - capacity to be reservedpublic int size()
public int length()
public ByteBuffer resize(int newSize)
The buffer is extended if it is not big enough.
newSize - new size of the datapublic ByteBuffer incLength(int size)
The buffer is extended if it is not big enough.
size - number of bytes the data of byte buffer to be increasedpublic ByteBuffer reverse()
public ByteBuffer reverse(int startIdx)
startIdx - start index in the byte buffer from where data should be reversedpublic ByteBuffer reverse(int startIdx, int endIdx)
startIdx - start index of the range to be reversedendIdx - end index of the range to be reversedpublic int findIndex(int startPsn,
byte[] subBuffer)
startPsn - start position the finding will beginsubBuffer - bytes sub-sequence to be foundpublic ByteBuffer write(OutputStream outputStream) throws IOException
outputStream - output stream the data to be writtenIOException - if an I/O error occurs. In particular, an IOException is thrown if the output
stream is closed.public int compareTo(ByteBuffer o)
compareTo in interface Comparable<ByteBuffer>Copyright © 2014–2025 Onix Solutions. All rights reserved.