Example usage for java.nio IntBuffer limit

List of usage examples for java.nio IntBuffer limit

Introduction

In this page you can find the example usage for java.nio IntBuffer limit.

Prototype

public final Buffer limit(int newLimit) 

Source Link

Document

Sets the limit of this buffer.

Usage

From source file:com.alvermont.terraj.fracplanet.geom.TriangleBufferArray.java

/**
 * Resize this buffer to accomodate a larger number of elements
 *//*from  w  w  w . j av a 2 s.c  om*/
protected void resizeBuffer() {
    // we can't resize it so we have to allocate a new one and copy the data across
    final int slots = this.buffer.capacity() / INTS_PER_ENTRY;
    final int newCapacity = this.buffer.capacity()
            + (((slots * CAPACITY_PCT_INCREASE) / PERCENT_100) * INTS_PER_ENTRY);

    final IntBuffer newBuffer = ByteBuffer.allocateDirect(newCapacity * SIZEOF_INT)
            .order(ByteOrder.nativeOrder()).asIntBuffer();

    newBuffer.limit(this.buffer.limit());

    if (log.isDebugEnabled()) {
        log.debug("Resizing triangle buffer capacity to: " + newCapacity + " " + newBuffer.capacity());
    }

    this.buffer.rewind();
    newBuffer.put(this.buffer);

    this.buffer = newBuffer;
}