java.nio.Buffer#flip ( )源码实例Demo

下面列出了java.nio.Buffer#flip ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: trekarta   文件: BufferObject.java
/**
 * @param newSize size required in bytes
 */
public void loadBufferData(Buffer buf, int newSize) {
    boolean clear = false;

    if (buf.position() != 0) {
        log.debug("flip your buffer!");
        buf.flip();
    }

    GLState.bindBuffer(target, id);

    /* reuse memory allocated for vbo when possible and allocated
     * memory is less then four times the new data */
    if (!GLAdapter.NO_BUFFER_SUB_DATA && !clear &&
            (size > newSize) && (size < newSize * 4)) {
        gl.bufferSubData(target, 0, newSize, buf);
    } else {
        mBufferMemoryUsage += newSize - size;
        size = newSize;
        //GL.bufferData(target, size, buf, GL20.DYNAMIC_DRAW);
        gl.bufferData(target, size, buf, GL.STATIC_DRAW);
    }
}
 
源代码2 项目: feign   文件: Util.java
/**
 * Adapted from {@code com.google.common.io.CharStreams.toString()}.
 */
public static String toString(Reader reader) throws IOException {
  if (reader == null) {
    return null;
  }
  try {
    StringBuilder to = new StringBuilder();
    CharBuffer charBuf = CharBuffer.allocate(BUF_SIZE);
    // must cast to super class Buffer otherwise break when running with java 11
    Buffer buf = charBuf;
    while (reader.read(charBuf) != -1) {
      buf.flip();
      to.append(charBuf);
      buf.clear();
    }
    return to.toString();
  } finally {
    ensureClosed(reader);
  }
}
 
源代码3 项目: apm-agent-java   文件: SamplingProfiler.java
private void readActivationEventsToBuffer(FileChannel activationEventsFileChannel, long eof, ByteBuffer byteBuffer) throws IOException {
    Buffer buf = byteBuffer;
    buf.clear();
    long remaining = eof - activationEventsFileChannel.position();
    activationEventsFileChannel.read(byteBuffer);
    buf.flip();
    if (remaining < buf.capacity()) {
        buf.limit((int) remaining);
    }
}
 
源代码4 项目: apm-agent-java   文件: SamplingProfiler.java
long startProcessingActivationEventsFile() throws IOException {
    Buffer activationEventsBuffer = this.activationEventsBuffer;
    if (activationEventsFileChannel.position() > 0) {
        flushActivationEvents();
        activationEventsBuffer.limit(0);
    } else {
        activationEventsBuffer.flip();
    }
    long eof = activationEventsFileChannel.position();
    activationEventsFileChannel.position(0);
    return eof;
}
 
源代码5 项目: jaamsim   文件: RenderUtils.java
static void nioBuffToGL(GL2GL3 gl, Renderer r, int bufferHandle, int itemSize, Buffer buff) {

	buff.flip();
	int size = buff.limit() * itemSize;
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, bufferHandle);
	gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, size, buff, GL2GL3.GL_STATIC_DRAW);
	gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);
	r.usingVRAM(size);

}
 
源代码6 项目: java   文件: TensorTest.java
private static void flipBuffer(Buffer buf) {
  buf.flip();
}
 
源代码7 项目: ShizuruNotes   文件: Utils.java
static void flipBuffer(Buffer buffer) {
  buffer.flip();
}
 
源代码8 项目: incubator-heron   文件: BufferHelper.java
/**
 * Flip the provided buffer.
 * <p>
 * This wrapper around {@link Buffer#flip()} is required because of
 * incompatible ABI changes between Java 8 and 11. In Java 8, {@link ByteBuffer#flip()} returns
 * a {@link Buffer}, whereas in Java 11, this method returns a {@link ByteBuffer}.
 * <p>
 * If this function is used, any object of {@link Buffer} (and subclasses) are first cast to
 * {@link Buffer} objects, then flipped, thus avoiding the binary incompatibility.
 *
 * @param buffer The buffer to flip
 */
static void flip(Buffer buffer) {
  buffer.flip();
}