use of java.nio.LongBuffer in project android_frameworks_base by AOSPA.
the class GLLogWrapper method toByteBuffer.
private ByteBuffer toByteBuffer(int byteCount, Buffer input) {
ByteBuffer result = null;
boolean convertWholeBuffer = (byteCount < 0);
if (input instanceof ByteBuffer) {
ByteBuffer input2 = (ByteBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = input2.limit() - position;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
for (int i = 0; i < byteCount; i++) {
result.put(input2.get());
}
input2.position(position);
} else if (input instanceof CharBuffer) {
CharBuffer input2 = (CharBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 2;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
CharBuffer result2 = result.asCharBuffer();
for (int i = 0; i < byteCount / 2; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof ShortBuffer) {
ShortBuffer input2 = (ShortBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 2;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
ShortBuffer result2 = result.asShortBuffer();
for (int i = 0; i < byteCount / 2; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof IntBuffer) {
IntBuffer input2 = (IntBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 4;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
IntBuffer result2 = result.asIntBuffer();
for (int i = 0; i < byteCount / 4; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof FloatBuffer) {
FloatBuffer input2 = (FloatBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 4;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
FloatBuffer result2 = result.asFloatBuffer();
for (int i = 0; i < byteCount / 4; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof DoubleBuffer) {
DoubleBuffer input2 = (DoubleBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 8;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
DoubleBuffer result2 = result.asDoubleBuffer();
for (int i = 0; i < byteCount / 8; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof LongBuffer) {
LongBuffer input2 = (LongBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 8;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
LongBuffer result2 = result.asLongBuffer();
for (int i = 0; i < byteCount / 8; i++) {
result2.put(input2.get());
}
input2.position(position);
} else {
throw new RuntimeException("Unimplemented Buffer subclass.");
}
result.rewind();
// The OpenGL API will interpret the result in hardware byte order,
// so we better do that as well:
result.order(ByteOrder.nativeOrder());
return result;
}
use of java.nio.LongBuffer in project android_frameworks_base by ResurrectionRemix.
the class GLLogWrapper method toByteBuffer.
private ByteBuffer toByteBuffer(int byteCount, Buffer input) {
ByteBuffer result = null;
boolean convertWholeBuffer = (byteCount < 0);
if (input instanceof ByteBuffer) {
ByteBuffer input2 = (ByteBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = input2.limit() - position;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
for (int i = 0; i < byteCount; i++) {
result.put(input2.get());
}
input2.position(position);
} else if (input instanceof CharBuffer) {
CharBuffer input2 = (CharBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 2;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
CharBuffer result2 = result.asCharBuffer();
for (int i = 0; i < byteCount / 2; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof ShortBuffer) {
ShortBuffer input2 = (ShortBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 2;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
ShortBuffer result2 = result.asShortBuffer();
for (int i = 0; i < byteCount / 2; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof IntBuffer) {
IntBuffer input2 = (IntBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 4;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
IntBuffer result2 = result.asIntBuffer();
for (int i = 0; i < byteCount / 4; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof FloatBuffer) {
FloatBuffer input2 = (FloatBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 4;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
FloatBuffer result2 = result.asFloatBuffer();
for (int i = 0; i < byteCount / 4; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof DoubleBuffer) {
DoubleBuffer input2 = (DoubleBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 8;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
DoubleBuffer result2 = result.asDoubleBuffer();
for (int i = 0; i < byteCount / 8; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof LongBuffer) {
LongBuffer input2 = (LongBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 8;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
LongBuffer result2 = result.asLongBuffer();
for (int i = 0; i < byteCount / 8; i++) {
result2.put(input2.get());
}
input2.position(position);
} else {
throw new RuntimeException("Unimplemented Buffer subclass.");
}
result.rewind();
// The OpenGL API will interpret the result in hardware byte order,
// so we better do that as well:
result.order(ByteOrder.nativeOrder());
return result;
}
use of java.nio.LongBuffer in project voltdb by VoltDB.
the class ConcurrentHistogram method fillCountsArrayFromBuffer.
@Override
synchronized void fillCountsArrayFromBuffer(final ByteBuffer buffer, final int length) {
LongBuffer logbuffer = buffer.asLongBuffer();
for (int i = 0; i < length; i++) {
inactiveCounts.lazySet(i, logbuffer.get());
activeCounts.lazySet(i, 0);
}
}
use of java.nio.LongBuffer in project XobotOS by xamarin.
the class GLLogWrapper method toByteBuffer.
private ByteBuffer toByteBuffer(int byteCount, Buffer input) {
ByteBuffer result = null;
boolean convertWholeBuffer = (byteCount < 0);
if (input instanceof ByteBuffer) {
ByteBuffer input2 = (ByteBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = input2.limit() - position;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
for (int i = 0; i < byteCount; i++) {
result.put(input2.get());
}
input2.position(position);
} else if (input instanceof CharBuffer) {
CharBuffer input2 = (CharBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 2;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
CharBuffer result2 = result.asCharBuffer();
for (int i = 0; i < byteCount / 2; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof ShortBuffer) {
ShortBuffer input2 = (ShortBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 2;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
ShortBuffer result2 = result.asShortBuffer();
for (int i = 0; i < byteCount / 2; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof IntBuffer) {
IntBuffer input2 = (IntBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 4;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
IntBuffer result2 = result.asIntBuffer();
for (int i = 0; i < byteCount / 4; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof FloatBuffer) {
FloatBuffer input2 = (FloatBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 4;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
FloatBuffer result2 = result.asFloatBuffer();
for (int i = 0; i < byteCount / 4; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof DoubleBuffer) {
DoubleBuffer input2 = (DoubleBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 8;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
DoubleBuffer result2 = result.asDoubleBuffer();
for (int i = 0; i < byteCount / 8; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof LongBuffer) {
LongBuffer input2 = (LongBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 8;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
LongBuffer result2 = result.asLongBuffer();
for (int i = 0; i < byteCount / 8; i++) {
result2.put(input2.get());
}
input2.position(position);
} else {
throw new RuntimeException("Unimplemented Buffer subclass.");
}
result.rewind();
// The OpenGL API will interpret the result in hardware byte order,
// so we better do that as well:
result.order(ByteOrder.nativeOrder());
return result;
}
use of java.nio.LongBuffer in project geode by apache.
the class ByteSourceJUnitTest method testGetLong.
@Test
public void testGetLong() {
ByteBuffer bb = ByteBuffer.allocate(40);
LongBuffer lb = bb.asLongBuffer();
lb.put(0x1110223344556677L);
lb.put(0x2220334455667788L);
lb.put(0x3330445566778899L);
lb.put(0x4440556677889900L);
lb.put(0x55506677889900AAL);
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
long l = bs.getLong();
assertEquals(0x1110223344556677L, l);
assertEquals(8, bs.position());
l = bs.getLong();
assertEquals(0x2220334455667788L, l);
assertEquals(16, bs.position());
bs.position(4 * 8);
l = bs.getLong();
assertEquals(0x55506677889900AAL, l);
assertEquals(40, bs.position());
try {
bs.getLong();
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
}
Aggregations