Java Utililty Methods ByteBuffer Append

List of utility methods to do ByteBuffer Append

Description

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

Method

voidappend(ByteBuffer buffer, String s)
append
int len = s.length();
for (int i = 0; i < len; i++)
    buffer.put((byte) s.charAt(i));
buffer.put((byte) 0);
align(buffer);
byte[]append(ByteBuffer source, int index, byte[] dest)
append
if (source == null || source.remaining() == 0)
    return dest;
int byteCount = source.remaining();
int requiredCapacity = index + byteCount;
if (requiredCapacity > dest.length) {
    byte[] newArray = new byte[requiredCapacity];
    System.arraycopy(dest, 0, newArray, 0, dest.length);
    dest = newArray;
...
voidappend(ByteBuffer to, byte[] b, int off, int len)
Append bytes to a buffer.
int pos = flipToFill(to);
try {
    to.put(b, off, len);
} finally {
    flipToFlush(to, pos);
ByteBufferappendBuffers(ByteBuffer buffer, ByteBuffer buffer1, int incomingBufferSize, int BUFFER_STEP_SIZE)
Concatenates two buffers into one.
final int limit = buffer.limit();
final int capacity = buffer.capacity();
final int remaining = buffer.remaining();
final int len = buffer1.remaining();
if (len < (capacity - limit)) {
    buffer.mark();
    buffer.position(limit);
    buffer.limit(capacity);
...
StringBuilderappendHex(StringBuilder sb, ByteBuffer bb)
append Hex
int limit = bb.limit();
for (int i = bb.position(); i < limit; i++) {
    int c = bb.get(i) & 0xff;
    sb.append(Character.forDigit(c >> 4, 16));
    sb.append(Character.forDigit(c & 0xf, 16));
    if (i < limit - 1)
        sb.append(' ');
return sb;
ByteBufferappendLong(long value, ByteBuffer buffer)
Append long to the end of the buffer, possibly reallocating it.
if (buffer.remaining() < 8)
    buffer = grow(buffer, MIN_REMAINING);
buffer.putLong(value);
return buffer;
ByteBufferappendOrRealloc(ByteBuffer dest, ByteBuffer toAppend)
Appends the contents of toAppend to dest if there is capacity, or does the equivalent of C's "realloc" by allocating a larger buffer and copying both dest and toAppend into that new buffer.
if (dest.capacity() - dest.position() < toAppend.limit()) {
    ByteBuffer newDest = ByteBuffer.allocate(dest.capacity() << 1); 
    dest.flip(); 
    newDest.put(dest); 
    dest = newDest;
dest.put(toAppend);
return dest;
...
voidappendSurrogate(ByteBuffer bb, char c)
Append %Uxxxx to the given byte buffer.
bb.put((byte) '%');
bb.put((byte) 'U');
bb.put(HEX_DIGITS[(c >> 12) & 0x0f]);
bb.put(HEX_DIGITS[(c >> 8) & 0x0f]);
bb.put(HEX_DIGITS[(c >> 4) & 0x0f]);
bb.put(HEX_DIGITS[c & 0x0f]);
ByteBufferappendToByteBuffer(ByteBuffer bb, byte[] bytes, int len)
append To Byte Buffer
if (len > bytes.length) {
    int pos = bb.position();
    bb.put(bytes);
    bb.position(pos + len);
} else {
    bb.put(bytes, 0, len);
return bb;
...
voidappendToEnd(final File file, final ByteBuffer contents)
Append the specified byte buffer to the end of the specified file
FileChannel fileChannel = null;
try {
    fileChannel = new FileOutputStream(file, true).getChannel();
    fileChannel.write(contents);
    contents.rewind();
} catch (IOException e) {
    e.printStackTrace();
} finally {
...