Java ByteBuffer Resize resize(ByteBuffer buffer)

Here you can find the source of resize(ByteBuffer buffer)

Description

Allocate a larger buffer that contains the data of an existing buffer.

License

Open Source License

Parameter

Parameter Description
buffer a parameter

Declaration

public static ByteBuffer resize(ByteBuffer buffer) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    /**/*  ww w.  j  a  v a2 s. c  o m*/
     * Allocate a larger buffer that contains the data of an existing buffer.
     * @param buffer
     * @return
     */
    public static ByteBuffer resize(ByteBuffer buffer) {
        int capacity = buffer.capacity();
        if (capacity > 2048)
            capacity += 1024;
        else
            capacity *= 2;
        ByteBuffer newBuffer = ByteBuffer.allocate(capacity);
        buffer.flip();
        newBuffer.put(buffer);
        return newBuffer;
    }
}

Related

  1. check(BufferedImage image, int resizeWidth, int resizeHeight)
  2. increaseBufferCapatity(ByteBuffer byteBuffer)
  3. increaseByteBuffer(ByteBuffer byteBuffer, int increase)
  4. performResize(BufferedImage source, int newWidth, int newHeight)
  5. resize(ByteBuffer oldBuffer, int newSize)
  6. resizeBuffer(final ByteBuffer in)
  7. resizeByteBuffer(ByteBuffer buf, long size)