java.nio.ByteBuffer.asIntBuffer()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中java.nio.ByteBuffer.asIntBuffer()方法的一些代码示例,展示了ByteBuffer.asIntBuffer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.asIntBuffer()方法的具体详情如下:
包路径:java.nio.ByteBuffer
类名称:ByteBuffer
方法名:asIntBuffer

ByteBuffer.asIntBuffer介绍

[英]Returns a int buffer which is based on the remaining content of this byte buffer.

The new buffer's position is zero, its limit and capacity is the number of remaining bytes divided by four, and its mark is not set. The new buffer's read-only property and byte order are the same as this buffer's. The new buffer is direct if this byte buffer is direct.

The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the other. The two buffer's position, limit and mark are independent.
[中]返回基于此字节缓冲区剩余内容的int缓冲区。
新缓冲区的位置为零,其限制和容量为剩余字节数除以四,且未设置其标记。新缓冲区的只读属性和字节顺序与此缓冲区的相同。如果此字节缓冲区是直接的,则新缓冲区是直接的。
新缓冲区与此缓冲区共享其内容,这意味着任何一个缓冲区的内容更改都将对另一个缓冲区可见。两个缓冲器的位置、极限和标记是独立的。

代码示例

代码示例来源:origin: libgdx/libgdx

public static IntBuffer newIntBuffer (int numInts) {
  ByteBuffer buffer = ByteBuffer.allocateDirect(numInts * 4);
  buffer.order(ByteOrder.nativeOrder());
  return buffer.asIntBuffer();
}

代码示例来源:origin: libgdx/libgdx

public String glGetProgramInfoLog (int program) {
  ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
  buffer.order(ByteOrder.nativeOrder());
  ByteBuffer tmp = ByteBuffer.allocateDirect(4);
  tmp.order(ByteOrder.nativeOrder());
  IntBuffer intBuffer = tmp.asIntBuffer();
  GL20.glGetProgramInfoLog(program, intBuffer, buffer);
  int numBytes = intBuffer.get(0);
  byte[] bytes = new byte[numBytes];
  buffer.get(bytes);
  return new String(bytes);
}

代码示例来源:origin: HdrHistogram/HdrHistogram

@Override
  synchronized void fillCountsArrayFromBuffer(final ByteBuffer buffer, final int length) {
    buffer.asIntBuffer().get(counts, 0, length);
  }
}

代码示例来源:origin: deeplearning4j/nd4j

/**
 * Convert an array to a byte buffer
 * @param arr the array
 * @return a direct byte buffer with the array contents
 */
public static IntBuffer toBuffer(int... arr) {
  ByteBuffer directBuffer = ByteBuffer.allocateDirect(arr.length * 4).order(ByteOrder.nativeOrder());
  IntBuffer buffer = directBuffer.asIntBuffer();
  for (int i = 0; i < arr.length; i++)
    buffer.put(i, arr[i]);
  return buffer;
}

代码示例来源:origin: deeplearning4j/nd4j

fromView.order(ByteOrder.nativeOrder());
toView.order(ByteOrder.nativeOrder());
switch (bufferType) {
  case INT:
    IntBuffer fromInt = fromView.asIntBuffer();
    IntBuffer toInt = toView.asIntBuffer();
    for (int i = 0; i < n; i++) {
      int put = fromInt.get(fromOffset + i * fromStride);
      toInt.put(toOffset + i * toStride, put);

代码示例来源:origin: apache/incubator-druid

public byte[] toBytes()
{
 if (words == null) {
  return new byte[]{};
 }
 ByteBuffer buf = ByteBuffer.allocate(words.capacity() * Integer.BYTES);
 buf.asIntBuffer().put(words.asReadOnlyBuffer());
 return buf.array();
}

代码示例来源:origin: apache/incubator-pinot

PinotDataBuffer buffer = _memoryManager.allocate(bbSize, _allocationContext);
_pinotDataBuffers.add(buffer);
IntBuffer iBuf = buffer.toDirectByteBuffer(0L, bbSize).asIntBuffer();
for (int i = 0; i < iBuf.capacity(); i++) {
 iBuf.put(i, NULL_VALUE_INDEX);
  boolean done = false;
  for (int i = offsetInBuf; i < offsetInBuf + NUM_COLUMNS; i++) {
   if (iBuf.get(i) == NULL_VALUE_INDEX) {
    iBuf.put(i, entry.getValue());
    done = true;
    break;

代码示例来源:origin: libgdx/libgdx

public String glGetShaderInfoLog (int shader) {
  ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
  buffer.order(ByteOrder.nativeOrder());
  ByteBuffer tmp = ByteBuffer.allocateDirect(4);
  tmp.order(ByteOrder.nativeOrder());
  IntBuffer intBuffer = tmp.asIntBuffer();
  GL20.glGetShaderInfoLog(shader, intBuffer, buffer);
  int numBytes = intBuffer.get(0);
  byte[] bytes = new byte[numBytes];
  buffer.get(bytes);
  return new String(bytes);
}

代码示例来源:origin: Rajawali/Rajawali

public void setIndices(int[] indices, boolean override) {
  final BufferInfo indexInfo = mBuffers.get(INDEX_BUFFER_KEY);
  if (indexInfo.buffer == null || override == true) {
    indexInfo.buffer = ByteBuffer.allocateDirect(indices.length * INT_SIZE_BYTES)
        .order(ByteOrder.nativeOrder()).asIntBuffer();
    ((IntBuffer) indexInfo.buffer).put(indices).position(0);
    mNumIndices = indices.length;
  } else {
    ((IntBuffer) indexInfo.buffer).put(indices);
  }
}

代码示例来源:origin: libgdx/libgdx

public static IntBuffer newIntBuffer (int numInts) {
  ByteBuffer buffer = ByteBuffer.allocateDirect(numInts * 4);
  buffer.order(ByteOrder.nativeOrder());
  return buffer.asIntBuffer();
}

代码示例来源:origin: libgdx/libgdx

defaultFramebufferHandleInitialized = true;
if (Gdx.app.getType() == ApplicationType.iOS) {
  IntBuffer intbuf = ByteBuffer.allocateDirect(16 * Integer.SIZE / 8).order(ByteOrder.nativeOrder()).asIntBuffer();
  gl.glGetIntegerv(GL20.GL_FRAMEBUFFER_BINDING, intbuf);
  defaultFramebufferHandle = intbuf.get(0);
} else {
  defaultFramebufferHandle = 0;
IntBuffer buffer = BufferUtils.newIntBuffer(colorTextureCounter);
for (int i = 0; i < colorTextureCounter; i++) {
  buffer.put(GL30.GL_COLOR_ATTACHMENT0 + i);

代码示例来源:origin: stackoverflow.com

ByteBuffer bb = ByteBuffer.wrap(new byte[] {0, 0, 0, 1, 0, 0, 0, 4});
IntBuffer ib = bb.asIntBuffer();
int i0 = ib.get(0);
int i1 = ib.get(1);

System.out.println(i0);
System.out.println(i1);

代码示例来源:origin: stackoverflow.com

import java.nio.*;
import java.net.*;

class Test
{   
  public static void main(String [] args)
    throws Exception // Just for simplicity!
  {
    int[] data = { 100, 200, 300, 400 };

    ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 4);        
    IntBuffer intBuffer = byteBuffer.asIntBuffer();
    intBuffer.put(data);

    byte[] array = byteBuffer.array();

    for (int i=0; i < array.length; i++)
    {
      System.out.println(i + ": " + array[i]);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public static byte[] intsToBytes(int[] ints) {
  ByteBuffer bb = ByteBuffer.allocate(ints.length * 4);
  IntBuffer ib = bb.asIntBuffer();
  for (int i : ints) ib.put(i);
  return bb.array();
}

public static int[] bytesToInts(byte[] bytes) {
  int[] ints = new int[bytes.length / 4];
  ByteBuffer.wrap(bytes).asIntBuffer().get(ints);
  return ints;
}

代码示例来源:origin: libgdx/libgdx

public String glGetShaderInfoLog (int shader) {
  ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
  buffer.order(ByteOrder.nativeOrder());
  ByteBuffer tmp = ByteBuffer.allocateDirect(4);
  tmp.order(ByteOrder.nativeOrder());
  IntBuffer intBuffer = tmp.asIntBuffer();
  GL20.glGetShaderInfoLog(shader, intBuffer, buffer);
  int numBytes = intBuffer.get(0);
  byte[] bytes = new byte[numBytes];
  buffer.get(bytes);
  return new String(bytes);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static final ByteBuffer getImageDataFromImage(BufferedImage bufferedImage) {
  WritableRaster wr;
  DataBuffer db;
  BufferedImage bi = new BufferedImage(128, 64, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = bi.createGraphics();
  g.drawImage(bufferedImage, null, null);
  bufferedImage = bi;
  wr = bi.getRaster();
  db = wr.getDataBuffer();
  DataBufferInt dbi = (DataBufferInt) db;
  int[] data = dbi.getData();
  ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length * 4);
  byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
  byteBuffer.asIntBuffer().put(data);
  byteBuffer.flip();
  return byteBuffer;
}

代码示例来源:origin: runelite/runelite

static IntBuffer allocateDirect(int size)
  {
    return ByteBuffer.allocateDirect(size * Integer.BYTES)
      .order(ByteOrder.nativeOrder())
      .asIntBuffer();
  }
}

代码示例来源:origin: libgdx/libgdx

defaultFramebufferHandleInitialized = true;
if (Gdx.app.getType() == ApplicationType.iOS) {
  IntBuffer intbuf = ByteBuffer.allocateDirect(16 * Integer.SIZE / 8).order(ByteOrder.nativeOrder()).asIntBuffer();
  gl.glGetIntegerv(GL20.GL_FRAMEBUFFER_BINDING, intbuf);
  defaultFramebufferHandle = intbuf.get(0);
} else {
  defaultFramebufferHandle = 0;
IntBuffer buffer = BufferUtils.newIntBuffer(colorTextureCounter);
for (int i = 0; i < colorTextureCounter; i++) {
  buffer.put(GL30.GL_COLOR_ATTACHMENT0 + i);

代码示例来源:origin: stackoverflow.com

static {
  System.loadLibrary("webp");
}

private Bitmap webpToBitmap(byte[] encoded) {

  int[] width = new int[] { 0 };
  int[] height = new int[] { 0 };
  byte[] decoded = libwebp.WebPDecodeARGB(encoded, encoded.length, width, height);

  int[] pixels = new int[decoded.length / 4];
  ByteBuffer.wrap(decoded).asIntBuffer().get(pixels);

  return Bitmap.createBitmap(pixels, width[0], height[0], Bitmap.Config.ARGB_8888);

}

代码示例来源:origin: apache/hive

public static Decimal getDecimal(int number, int scale) {
 ByteBuffer bb = ByteBuffer.allocate(4);
 bb.asIntBuffer().put(number);
 return new Decimal((short) scale, bb);
}

相关文章

微信公众号

最新文章

更多