Example usage for java.nio IntBuffer allocate

List of usage examples for java.nio IntBuffer allocate

Introduction

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

Prototype

public static IntBuffer allocate(int capacity) 

Source Link

Document

Creates an int buffer based on a newly allocated int array.

Usage

From source file:com.rinke.solutions.pinball.io.UsbConnector.java

@Override
protected byte[] receive(ConnectionHandle h, int len) {
    byte[] data = new byte[len];
    IntBuffer transfered = IntBuffer.allocate(1);
    ByteBuffer buffer = ByteBuffer.allocateDirect(data.length);
    buffer.put(data);//from   w ww  .  ja v a2s  .co m
    // Use device handle here
    UsbHandle usb = (UsbHandle) h;
    int res = LibUsb.bulkTransfer(usb.getDeviceHandle(), (byte) 0x81, buffer, transfered, 4000);
    if (res != LibUsb.SUCCESS)
        throw new LibUsbException("Control transfer failed", res);
    int read = transfered.get();
    if (read != data.length) {
        log.error("unexpected length returned on bulk: {}", read);
    }
    return data;
}

From source file:com.rinke.solutions.pinball.io.UsbConnector.java

@Override
protected void send(byte[] data, ConnectionHandle handle) {
    IntBuffer transfered = IntBuffer.allocate(1);
    ByteBuffer buffer = ByteBuffer.allocateDirect(data.length);
    buffer.put(data);//from  ww w  . ja va2 s  .com
    UsbHandle usb = (UsbHandle) handle;
    // Use device handle here
    int res = LibUsb.bulkTransfer(usb.getDeviceHandle(), (byte) 0x01, buffer, transfered, 4000);
    if (res != LibUsb.SUCCESS)
        throw new LibUsbException("Control transfer failed", res);
    if (transfered.get() != data.length) {
        log.error("unexpected length returned on bulk: {}", transfered.get());
    }
}

From source file:net.dv8tion.jda.audio.AudioConnection.java

public AudioConnection(AudioWebSocket webSocket, VoiceChannel channel) {
    this.channel = channel;
    this.webSocket = webSocket;
    this.webSocket.audioConnection = this;

    IntBuffer error = IntBuffer.allocate(4);
    opusEncoder = Opus.INSTANCE.opus_encoder_create(OPUS_SAMPLE_RATE, OPUS_CHANNEL_COUNT,
            Opus.OPUS_APPLICATION_AUDIO, error);
}

From source file:fr.amap.viewer3d.loading.shader.Shader.java

private void extractActiveUniforms() {

    IntBuffer buf = IntBuffer.allocate(1);
    gl.glGetProgramiv(programId, GL3.GL_ACTIVE_UNIFORMS, buf);

    IntBuffer size = IntBuffer.allocate(40);
    IntBuffer length = IntBuffer.allocate(40);
    ByteBuffer nm = ByteBuffer.allocate(256);
    IntBuffer type = IntBuffer.allocate(1);

    for (int i = 0; i < buf.get(0); i++) {
        gl.glGetActiveUniform(programId, i, 40, length, size, type, nm);
        String uniformName = new String(ArrayUtils.subarray(nm.array(), 0, length.get(0)));

        uniformMap.put(uniformName, gl.glGetUniformLocation(programId, uniformName));
    }/*from  ww w  .  j a v a2 s. c o m*/
}

From source file:fr.amap.viewer3d.loading.shader.Shader.java

private void extractActiveAttributes() {

    IntBuffer buf = IntBuffer.allocate(1);
    gl.glGetProgramiv(programId, GL3.GL_ACTIVE_ATTRIBUTES, buf);

    IntBuffer size = IntBuffer.allocate(40);
    IntBuffer length = IntBuffer.allocate(40);
    ByteBuffer nm = ByteBuffer.allocate(256);
    IntBuffer type = IntBuffer.allocate(1);

    for (int i = 0; i < buf.get(0); i++) {
        gl.glGetActiveAttrib(programId, i, 40, length, size, type, nm);
        String attributeName = new String(ArrayUtils.subarray(nm.array(), 0, length.get(0)));

        attributeMap.put(attributeName, gl.glGetAttribLocation(programId, attributeName));
    }// w w  w . j a  v  a 2s.  co m
}

From source file:org.goko.viewer.jogl.utils.render.gcode.DefaultGCodeProviderRenderer.java

/** (inheritDoc)
 * @see org.goko.viewer.jogl.utils.render.internal.AbstractVboJoglRenderer#buildGeometry()
 *//*from w w  w . j a va  2  s .  c  om*/
@Override
protected void buildGeometry() throws GkException {
    List<GCodeCommand> commands = gcodeProvider.getGCodeCommands();
    ArrayList<Point3d> lstVertices = new ArrayList<Point3d>();
    ArrayList<Color4f> lstColors = new ArrayList<Color4f>();
    mapVerticesPositionByIdCommand = new HashMap<Integer, Integer[]>();
    boolean firstCommand = true;
    for (GCodeCommand command : commands) {
        List<Point3d> lstCmdVertices = generator.generateVertices(command);
        if (CollectionUtils.isNotEmpty(lstCmdVertices)) {
            if (firstCommand) {
                firstCommand = false;
            } else {
                lstCmdVertices.remove(0);
            }
            // First index is the position of the first vertices that belong to the command
            // Second index is the number of vertices that belongs to this command
            if (CollectionUtils.isNotEmpty(lstCmdVertices)) {
                mapVerticesPositionByIdCommand.put(command.getId(),
                        new Integer[] { lstVertices.size(), lstCmdVertices.size() });
                lstVertices.addAll(lstCmdVertices);
            }
            // Let's generate the colors
            Color4f color = colorizer.getColor(command);
            for (Point3d point3d : lstCmdVertices) {
                lstColors.add(color);
            }
        }
    }
    setVerticesCount(CollectionUtils.size(lstVertices));
    stateBuffer = IntBuffer.allocate(getVerticesCount());
    stateBuffer.rewind();
    //generateCommandStateBuffer();
    setColorsBuffer(JoglUtils.buildFloatBuffer4f(lstColors));
    setVerticesBuffer(JoglUtils.buildFloatBuffer3d(lstVertices));
}

From source file:com.atilika.kuromoji.trie.DoubleArrayTrie.java

/**
 * Construct double array trie which is equivalent to input trie
 *
 * @param trie  normal trie, which contains all dictionary words
 *//* w w  w  .j  a v a 2 s.  c  om*/
public void build(Trie trie) {
    ProgressLog.begin("building " + (compact ? "compact" : "sparse") + " trie");
    baseBuffer = IntBuffer.allocate(BASE_CHECK_INITIAL_SIZE);
    baseBuffer.put(0, 1);
    checkBuffer = IntBuffer.allocate(BASE_CHECK_INITIAL_SIZE);
    tailBuffer = CharBuffer.allocate(TAIL_INITIAL_SIZE);
    add(-1, 0, trie.getRoot());
    reportUtilizationRate();
    ProgressLog.end();
}

From source file:org.tsho.dmc2.core.chart.AbsorbingAreaRenderer.java

public void copyDisplay() {
    IntBuffer buffer = IntBuffer.allocate(grid.length);
    buffer.put(grid);
    buffer.flip();
    buffer.get(gridBackup);
}

From source file:org.tsho.dmc2.core.chart.AbsorbingAreaRenderer.java

public void plotCopiedDisplay() {
    IntBuffer buffer = IntBuffer.allocate(grid.length);
    buffer.put(gridBackup);
    buffer.flip();
    buffer.get(grid);
}

From source file:org.goko.tools.viewer.jogl.shaders.ShaderLoader.java

private static void checkLinkProgramm(GL3 gl, int program) {
    IntBuffer b = IntBuffer.allocate(10);
    gl.glGetProgramiv(program, GL3.GL_LINK_STATUS, b);
    ByteBuffer logBuffer = ByteBuffer.allocate(10000);
    gl.glGetProgramInfoLog(program, 10000, null, logBuffer);
    try {//  w  ww.  j  av a2s  .  c  o  m
        String logBufferStr = new String(logBuffer.array(), "UTF-8");
        if (StringUtils.isNotBlank(StringUtils.defaultString(logBufferStr).trim())) {
            LOG.error("CheckProgramm :" + logBufferStr);
        }
    } catch (UnsupportedEncodingException e) {
        LOG.error(e);
    }
}