Java Utililty Methods ByteBuffer Read

List of utility methods to do ByteBuffer Read

Description

The list of methods to do ByteBuffer Read are organized into topic(s).

Method

voidassertReadyForFreshRead(ByteBuffer b)
Ensure that a buffer is prepared for reading from the beginning.
assert (b.limit() != 0); 
assert (b.position() == 0); 
intc_read(Channel fd, ByteBuffer buffer, int count)
read
try {
    ReadableByteChannel rc = (ReadableByteChannel) fd;
    buffer = buffer.duplicate();
    buffer.limit(buffer.position() + count);
    return rc.read(buffer);
} catch (Exception e) {
    e.printStackTrace();
    return -1;
...
voidcheckNotReadOnly(ByteBuffer buffer)
check Not Read Only
if (buffer.isReadOnly()) {
    throw new ReadOnlyBufferException();
StringcontentOfUnreadBuffer(final ByteBuffer buffer)
content of unread byte buffer, hex representation using ByteBuffer#getInt()
int position = buffer.position();
int limit = buffer.limit();
StringBuffer sb = new StringBuffer();
while (buffer.hasRemaining()) {
    sb.append(Integer.toHexString(buffer.getInt()));
buffer.position(position);
buffer.limit(limit);
...
ByteBufferenlargeThreadLocalByteBuffer()
Double the thread local buffer capacity.
TMP_BUFFER.set(ByteBuffer.allocate(TMP_BUFFER.get().capacity() * 2));
return TMP_BUFFER.get();
voidparseEsInfo(ByteBuffer read)
parse Es Info
intread(@Nonnull final FileChannel src, @Nonnull final ByteBuffer dst, @Nonnegative final long position)
Read until dst buffer is filled or src channel is reached end.
int count = 0;
long offset = position;
while (dst.remaining() > 0) {
    int n = src.read(dst, offset);
    if (n == -1) {
        break;
    offset += n;
...
intread(ByteBuffer b)
read
int result = (b.get() & 0xFF);
return result;
voidread(ByteBuffer bb, FileChannel ch)
read
bb.clear();
ch.read(bb);
bb.flip();
longread(ByteBuffer bb, int elementWidth)
read
final long value = readBE(bb, elementWidth);
if (bb.order() == ByteOrder.BIG_ENDIAN) {
    return value;
return swap(elementWidth, value);