Java ByteBuffer Resize increaseBufferCapatity(ByteBuffer byteBuffer)

Here you can find the source of increaseBufferCapatity(ByteBuffer byteBuffer)

Description

increase Buffer Capatity

License

Open Source License

Parameter

Parameter Description
byteBuffer a parameter

Declaration

public static final ByteBuffer increaseBufferCapatity(ByteBuffer byteBuffer) 

Method Source Code


//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();
            }
        }
    }
}

Related

  1. check(BufferedImage image, int resizeWidth, int resizeHeight)
  2. increaseByteBuffer(ByteBuffer byteBuffer, int increase)
  3. performResize(BufferedImage source, int newWidth, int newHeight)
  4. resize(ByteBuffer buffer)
  5. resize(ByteBuffer oldBuffer, int newSize)