Example usage for com.google.gwt.typedarrays.client ArrayBuffer create

List of usage examples for com.google.gwt.typedarrays.client ArrayBuffer create

Introduction

In this page you can find the example usage for com.google.gwt.typedarrays.client ArrayBuffer create.

Prototype

public static final native ArrayBuffer create(int length) ;

Source Link

Document

Creates a new ArrayBuffer of the given length in bytes.

Usage

From source file:playn.html.HtmlWebSocket.java

License:Apache License

@Override
public void send(ByteBuffer data) {
    int len = data.limit();
    // TODO(haustein) Sending the view directly does not work for some reason.
    // May be a chrome issue...?
    //  Object trick = data;
    // ArrayBufferView ta = ((HasArrayBufferView) trick).getTypedArray();
    // Int8Array view = Int8Array.create(ta.getBuffer(), ta.getByteOffset(), len)
    // ws.send(view);
    ArrayBuffer buf = ArrayBuffer.create(len);
    Uint8Array view = Uint8Array.create(buf);
    for (int i = 0; i < len; i++) {
        view.set(i, data.get(i));/*w  ww. j  a va2s  . com*/
    }
    ws.send(buf);
}