Here you can find the source of increaseBufferCapatity(ByteBuffer byteBuffer)
Parameter | Description |
---|---|
byteBuffer | a parameter |
public static final ByteBuffer increaseBufferCapatity(ByteBuffer byteBuffer)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { static final int DEFAULT_INCREASE_BUFF_SIZE = 16 * 1024; /**// w w w .java 2 s . c o m * * @param byteBuffer * @return * */ public static final ByteBuffer increaseBufferCapatity(ByteBuffer byteBuffer) { if (byteBuffer == null) { throw new IllegalArgumentException("buffer is null"); } int capacity = byteBuffer.capacity() + DEFAULT_INCREASE_BUFF_SIZE; if (capacity < 0) { throw new IllegalArgumentException("capacity can't be negative"); } ByteBuffer result = byteBuffer.isDirect() ? ByteBuffer.allocateDirect(capacity) : ByteBuffer.allocate(capacity); result.order(byteBuffer.order()); byteBuffer.flip(); result.put(byteBuffer); return result; } public static final void flip(ByteBuffer[] buffers) { if (buffers == null) { return; } for (ByteBuffer buffer : buffers) { if (buffer != null) { buffer.flip(); } } } }