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

longreadBE(ByteBuffer bb, int elementWidth)
read BE
final int p = bb.position();
long value = 0;
for (int j = 0; j < elementWidth; j++) {
    value = (value << 8) | (bb.get(p + j) & 0xff);
bb.position(p + elementWidth);
return value;
booleanreadBoolean(ByteBuffer buff)
Reads one byte as a boolean.
return buff.get() == 1;
boolean[]readBooleanArray(ByteBuffer in)
read Boolean Array
int len = readVInt(in);
if (len < 0)
    return null;
boolean[] array = new boolean[len];
byte b_true = (byte) 1;
for (int i = 0; i < array.length; i++) {
    byte temp = in.get();
    if (temp == b_true)
...
ByteBufferreadBuf(ByteBuffer buffer)
read Buf
ByteBuffer result = buffer.duplicate();
buffer.position(buffer.limit());
return result;
intreadBuffer(ByteChannel channel, ByteBuffer buffer)
reading buffer
int numberRead = channel.read(buffer);
int position = 0;
int totalRead = numberRead;
while (numberRead >= 0 && position <= buffer.capacity()) {
    numberRead = channel.read(buffer);
    if (numberRead > 0) {
        totalRead += numberRead;
    position++;
return totalRead;
voidreadBufferFully(FileChannel fc, ByteBuffer buf, int startPos)
read Buffer Fully
int pos = startPos;
while (buf.hasRemaining()) {
    int read = fc.read(buf, pos);
    if (read == -1) {
        throw new EOFException();
    pos += read;
buf.flip();
byte[]readByteBuffer(ByteBuffer buf)
read Byte Buffer
int pos = buf.position();
byte[] r = new byte[buf.limit() - buf.position()];
buf.get(r);
buf.position(pos);
return r;
ByteBufferreadByteBufferFromFile(String filepath)
read Byte Buffer From File
File file = new File(filepath);
FileChannel inChannel;
inChannel = new FileInputStream(file).getChannel();
ByteBuffer buf = ByteBuffer.allocate((int) file.length());
inChannel.read(buf);
inChannel.close();
buf.rewind();
return buf;
...
StringreadChars(ByteBuffer bb, int length)
read Chars
byte[] b = new byte[length];
bb.get(b);
int strLength = 0;
for (int i = 0; i < b.length; i++) {
    if (b[i] == 0) {
        break;
    strLength++;
...
StringreadCharsUTF8(ByteBuffer bb, int length)
read Chars UTF
byte[] b = new byte[length];
bb.get(b);
int strLength = 0;
for (int i = 0; i < b.length; i++) {
    if (b[i] == 0) {
        break;
    strLength++;
...