32package com.jogamp.common.nio;
34import java.nio.Buffer;
35import java.nio.ByteBuffer;
37import com.jogamp.common.os.Platform;
43@SuppressWarnings(
"rawtypes")
56 POINTER_SIZE =
Platform.
is32Bit() ? Buffers.SIZEOF_INT : Buffers.SIZEOF_LONG ;
68 protected AbstractBuffer(
final Buffer buffer,
final int elementSize,
final int capacity) {
70 this.elementSize = elementSize;
71 this.capacity = capacity;
72 this.limit = capacity;
87 @SuppressWarnings(
"unchecked")
89 public final B
limit(
final int newLim) {
90 if (0 > newLim || newLim >= capacity) {
91 throw new IllegalArgumentException(
"New limit "+newLim+
" out of bounds [0 .. capacity " +capacity()+
"].");
107 @SuppressWarnings(
"unchecked")
110 if (0 > newPos || newPos > limit) {
111 throw new IllegalArgumentException(
"New position "+newPos+
" out of bounds [0 .. limit " +limit()+
"].");
119 return limit - position;
124 return limit > position;
127 @SuppressWarnings(
"unchecked")
135 @SuppressWarnings(
"unchecked")
143 @SuppressWarnings(
"unchecked")
156 return buffer.isDirect();
161 return Buffers.getDirectBufferAddressImpl(buffer);
168 final long addr = getDirectBufferAddress();
169 switch(POINTER_SIZE) {
171 directDest.putInt(0, (
int) ( addr & 0x00000000FFFFFFFFL ) );
174 directDest.putLong(0, addr);
177 directDest.position(directDest.position()+POINTER_SIZE);
182 final long addr = getDirectBufferAddress();
183 switch(POINTER_SIZE) {
185 directDest.putInt(destBytePos, (
int) ( addr & 0x00000000FFFFFFFFL ) );
188 directDest.putLong(destBytePos, addr);
195 return buffer.hasArray();
201 return buffer.arrayOffset();
208 public Object
array() throws UnsupportedOperationException {
209 return buffer.array();
213 return "[direct["+isDirect()+
", addr 0x"+Long.toHexString(getDirectBufferAddress())+
"], hasArray "+hasArray()+
", capacity "+capacity+
", position "+position+
", elementSize "+elementSize+
", buffer[capacity "+buffer.capacity()+
", lim "+buffer.limit()+
", pos "+buffer.position()+
"]]";
217 return "AbstractBuffer"+toSubString();
AbstractBuffer(final Buffer buffer, final int elementSize, final int capacity)
capacity and elementSize should be match the equation w/ target buffer type
final B limit(final int newLim)
void storeDirectAddress(final ByteBuffer directDest, final int destBytePos)
final B position(final int newPos)
final boolean hasRemaining()
void storeDirectAddress(final ByteBuffer directDest)
static final int POINTER_SIZE
Platform dependent pointer size in bytes, i.e.
long getDirectBufferAddress()
Utility methods allowing easy java.nio.Buffer manipulations.
Hardware independent container for various kinds of buffers.