Java ByteBuffer Append appendLong(long value, ByteBuffer buffer)

Here you can find the source of appendLong(long value, ByteBuffer buffer)

Description

Append long to the end of the buffer, possibly reallocating it.

License

Apache License

Parameter

Parameter Description
value a parameter
buffer a parameter

Declaration

public static ByteBuffer appendLong(long value, ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;

public class Main {
    private static final int MIN_REMAINING = 32;

    /**//ww  w .j a  v a 2s.c om
     * Append long to the end of the buffer, possibly reallocating it.
     *
     * @param value
     * @param buffer
     * @return
     */
    public static ByteBuffer appendLong(long value, ByteBuffer buffer) {
        if (buffer.remaining() < 8)
            buffer = grow(buffer, MIN_REMAINING);
        buffer.putLong(value);
        return buffer;
    }

    private static ByteBuffer grow(ByteBuffer buffer, int minCapacityIncrease) {
        ByteBuffer tmp = ByteBuffer
                .allocate(Math.max(buffer.capacity() << 1, buffer.capacity() + minCapacityIncrease));
        buffer.flip();
        tmp.put(buffer);
        return tmp;
    }
}

Related

  1. append(ByteBuffer buffer, String s)
  2. append(ByteBuffer source, int index, byte[] dest)
  3. append(ByteBuffer to, byte[] b, int off, int len)
  4. appendBuffers(ByteBuffer buffer, ByteBuffer buffer1, int incomingBufferSize, int BUFFER_STEP_SIZE)
  5. appendHex(StringBuilder sb, ByteBuffer bb)
  6. appendOrRealloc(ByteBuffer dest, ByteBuffer toAppend)
  7. appendSurrogate(ByteBuffer bb, char c)
  8. appendToByteBuffer(ByteBuffer bb, byte[] bytes, int len)
  9. appendToEnd(final File file, final ByteBuffer contents)