Java Utililty Methods ByteBuffer Get

List of utility methods to do ByteBuffer Get

Description

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

Method

ByteBuffergetWithShortLength(ByteBuffer bb)
get With Short Length
int length = getShortLength(bb);
return getBytes(bb, length);
byte[]getZeroTerminatedStringBytes(ByteBuffer dataBuffer)
get Zero Terminated String Bytes
ByteArrayOutputStream bos = new ByteArrayOutputStream(dataBuffer.remaining());
while (dataBuffer.remaining() > 0) {
    byte thisByte = dataBuffer.get();
    if (thisByte == 0) {
        break;
    bos.write(thisByte);
return bos.toByteArray();
longgetZipEocdCentralDirectorySizeBytes(ByteBuffer zipEndOfCentralDirectory)
Returns the size (in bytes) of the ZIP Central Directory.
assertByteOrderLittleEndian(zipEndOfCentralDirectory);
return getUnsignedInt32(zipEndOfCentralDirectory,
        zipEndOfCentralDirectory.position() + ZIP_EOCD_CENTRAL_DIR_SIZE_FIELD_OFFSET);
ByteBufferinsertByteArray(byte[] source, ByteBuffer target)
Insert a static byte array at the current position of the given message.
int current = target.position();
target.rewind();
byte[] first = new byte[current];
byte[] last = new byte[target.capacity() - current];
target.get(first, 0, first.length);
target.get(last, 0, last.length);
byte[] all = new byte[first.length + source.length + last.length];
System.arraycopy(first, 0, all, 0, first.length);
...
inttransfer(ByteBuffer src, FileChannel target, long position, long count)
transfer
int wrote;
if (src.remaining() <= count) {
    wrote = target.write(src, position);
} else {
    int srcLimit = src.limit();
    src.limit(src.position() + (int) count);
    try {
        wrote = target.write(src, position);
...
voidtransferUntilTargetPos(ByteBuffer src, ByteBuffer trg, int trgPos)
Copy as many byte from source to target, until either source has no more data, target cannot take more or the trg.position() is equals to limit value.
int cpySz = Math.min(src.remaining(), Math.min(trgPos - trg.position(), trg.remaining()));
if (cpySz <= 0) {
    return;
int oldLimit = src.limit();
src.limit(src.position() + cpySz);
trg.put(src);
src.limit(oldLimit);
...
ByteBufferutf8ByteBuffer(String messageTemplate, Object... args)
Builds a message replacing placeholders in the input template and encodes the result.
return UTF_8.encode(format(messageTemplate, args));