All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.t.util.common.ByteBufferUtil Maven / Gradle / Ivy

There is a newer version: 1.0.16.RELEASE
Show newest version
package cn.t.util.common;

import java.nio.ByteBuffer;

public class ByteBufferUtil {

    public static ByteBuffer newCapacity(ByteBuffer byteBuffer, int add) {
        ByteBuffer newBuffer = ByteBuffer.allocateDirect(byteBuffer.capacity() + add);
        return copyBuffer(byteBuffer, newBuffer);
    }

    public static ByteBuffer newCapacity(ByteBuffer byteBuffer) {
        ByteBuffer newBuffer = ByteBuffer.allocateDirect(byteBuffer.capacity() * 2);
        return copyBuffer(byteBuffer, newBuffer);
    }

    private static ByteBuffer copyBuffer(ByteBuffer oldByteBuffer, ByteBuffer newByteBuffer) {
        oldByteBuffer.flip();
        return newByteBuffer.put(oldByteBuffer);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy