本文整理汇总了Java中com.google.gwt.typedarrays.shared.Uint8Array类的典型用法代码示例。如果您正苦于以下问题:Java Uint8Array类的具体用法?Java Uint8Array怎么用?Java Uint8Array使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Uint8Array类属于com.google.gwt.typedarrays.shared包,在下文中一共展示了Uint8Array类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putMethod
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
@Override
public Promise<HTTPResponse> putMethod(String url, byte[] contents) {
return new Promise<>(resolver -> {
JsHttpRequest request = JsHttpRequest.create();
request.open("PUT", url);
request.setRequestHeader("Content-Type", "application/octet-stream");
request.setOnLoadHandler(request1 -> {
if (request1.getReadyState() == 4) {
if (request1.getStatus() >= 200 && request1.getStatus() < 300) {
resolver.result(new HTTPResponse(request1.getStatus(), null));
} else {
resolver.error(new HTTPError(request1.getStatus()));
}
}
});
Uint8Array push = TypedArrays.createUint8Array(contents.length);
for (int i = 0; i < contents.length; i++) {
push.set(i, contents[i]);
}
request.send(push.buffer());
});
}
示例2: send
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
@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 = TypedArrays.createArrayBuffer(len);
Uint8Array view = TypedArrays.createUint8Array(buf);
for (int i = 0; i < len; i++) {
view.set(i, data.get(i));
}
ws.send(buf);
}
示例3: setTile
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
public void setTile(TileInfo tileInfo, GMap bufferGMap) {
if (bufferImageData == null || bufferImageData.getWidth() != bufferGMap.getDataWidth()
|| bufferImageData.getHeight() != bufferGMap.getDataHeight()) {
bufferImageData = bufferCanvas.getContext2d()
.createImageData(bufferGMap.getDataWidth(), bufferGMap.getDataHeight());
}
Uint8Array imageArray = bufferImageData.getData().cast();
imageArray.set(bufferGMap.getImageData());
bufferCanvas.getContext2d().putImageData(bufferImageData, -bufferGMap.getBorder(), 0);
CanvasElement tile = tiles.get(tileInfo);
if (tile == null) {
tile = createImage(bufferGMap.getDataWidth() - bufferGMap.getBorder(), bufferGMap.getDataHeight());
tiles.put(new TileInfo(tileInfo), tile);
}
Context2d c = tile.getContext2d();
c.setFillStyle("white");
c.fillRect(0, 0, tileSize, tileSize);
c.drawImage(bufferCanvas, 0, 0);
for (Consumer<Integer> listener : tileListeners)
listener.accept(tileInfo.page);
}
示例4: nextChar
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
private static int nextChar(
Uint8Array byteArray,
int pos)
{
if(pos < byteArray.length())
{
while(++pos < byteArray.length())
{
if((byteArray.get(pos) & 0xc0) != 0x80)
{
return pos;
}
}
}
return pos;
}
示例5: firstEndSpace
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
private int firstEndSpace(
final Uint8Array byteArray,
int start,
final int length)
{
for(int pos = start + length; --pos >= start;)
{
if(
((byteArray.get(pos) & 0xc0) != 0x80)
&& !isspace(getChar(byteArray, pos)))
{
return nextChar(byteArray, pos);
}
}
return start;
}
示例6: prevChar
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
private static int prevChar(
Uint8Array byteArray,
int pos)
{
if(pos >= 0)
{
while(--pos >= 0)
{
if((byteArray.get(pos) & 0xc0) != 0x80)
{
return pos;
}
}
}
return pos;
}
示例7: glReadPixels
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
@Override
public void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) {
// verify request
if ((format != WebGLRenderingContext.RGBA) || (type != WebGLRenderingContext.UNSIGNED_BYTE)) {
throw new GdxRuntimeException("Only format RGBA and type UNSIGNED_BYTE are currently supported for glReadPixels(...).");
}
if (!(pixels instanceof ByteBuffer)) {
throw new GdxRuntimeException("Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...).");
}
// create new ArrayBufferView (4 bytes per pixel)
int size = 4 * width * height;
Uint8Array buffer = Uint8ArrayNative.create(size);
// read bytes to ArrayBufferView
gl.readPixels(x, y, width, height, format, type, buffer);
// copy ArrayBufferView to our pixels array
ByteBuffer pixelsByte = (ByteBuffer)pixels;
for (int i = 0; i < size; i++) {
pixelsByte.put((byte)(buffer.get(i) & 0x000000ff));
}
}
示例8: glTexImage2D
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
@Override
public void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type,
Buffer pixels) {
if (pixels.limit() > 1) {
HasArrayBufferView arrayHolder = (HasArrayBufferView) pixels;
ArrayBufferView webGLArray = arrayHolder.getTypedArray();
int remainingBytes = pixels.remaining() * 4;
int byteOffset = webGLArray.byteOffset() + pixels.position() * 4;
Uint8Array buffer = Uint8ArrayNative.create(webGLArray.buffer(), byteOffset, remainingBytes);
gl.texImage2D(target, level, internalformat, width, height, border, format, type, buffer);
} else {
Pixmap pixmap = Pixmap.pixmaps.get(((IntBuffer)pixels).get(0));
gl.texImage2D(target, level, internalformat, format, type, pixmap.getCanvasElement());
}
}
示例9: glTexSubImage2D
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
@Override
public void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format, int type,
Buffer pixels) {
if (pixels.limit() > 1) {
HasArrayBufferView arrayHolder = (HasArrayBufferView) pixels;
ArrayBufferView webGLArray = arrayHolder.getTypedArray();
int remainingBytes = pixels.remaining() * 4;
int byteOffset = webGLArray.byteOffset() + pixels.position() * 4;
Uint8Array buffer = Uint8ArrayNative.create(webGLArray.buffer(), byteOffset, remainingBytes);
gl.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, buffer);
} else {
Pixmap pixmap = Pixmap.pixmaps.get(((IntBuffer) pixels).get(0));
gl.texSubImage2D(target, level, xoffset, yoffset, width, height, pixmap.getCanvasElement());
}
}
示例10: glReadPixels
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
@Override
public void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) {
// verify request
if ((format != WebGLRenderingContext.RGBA) || (type != WebGLRenderingContext.UNSIGNED_BYTE)) {
throw new GdxRuntimeException("Only format RGBA and type UNSIGNED_BYTE are currently supported for glReadPixels(...).");
}
if (!(pixels instanceof ByteBuffer)) {
throw new GdxRuntimeException("Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...).");
}
// create new ArrayBufferView (4 bytes per pixel)
int size = 4 * width * height;
Uint8Array buffer = Uint8ArrayNative.create(size);
// read bytes to ArrayBufferView
gl.readPixels(x, y, width, height, format, type, buffer);
// copy ArrayBufferView to our pixels array
ByteBuffer pixelsByte = (ByteBuffer)pixels;
for (int i = 0; i < size; i++) {
pixelsByte.put((byte)(buffer.get(i) & 0x000000ff));
}
}
示例11: glTexImage2D
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
@Override
public void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type,
Buffer pixels) {
if (pixels.limit() > 1) {
HasArrayBufferView arrayHolder = (HasArrayBufferView) pixels;
ArrayBufferView webGLArray = arrayHolder.getTypedArray();
int remainingBytes = pixels.remaining() * 4;
int byteOffset = webGLArray.byteOffset() + pixels.position() * 4;
Uint8Array buffer = Uint8ArrayNative.create(webGLArray.buffer(), byteOffset, remainingBytes);
gl.texImage2D(target, level, internalformat, width, height, border, format, type, buffer);
} else {
// Put this back later
Pixmap pixmap = Pixmap.pixmaps.get(((IntBuffer)pixels).get(0));
gl.texImage2D(target, level, internalformat, format, type, pixmap.getCanvasElement());
}
}
示例12: glTexSubImage2D
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
@Override
public void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format, int type,
Buffer pixels) {
if (pixels.limit() > 1) {
HasArrayBufferView arrayHolder = (HasArrayBufferView) pixels;
ArrayBufferView webGLArray = arrayHolder.getTypedArray();
int remainingBytes = pixels.remaining() * 4;
int byteOffset = webGLArray.byteOffset() + pixels.position() * 4;
Uint8Array buffer = Uint8ArrayNative.create(webGLArray.buffer(), byteOffset, remainingBytes);
gl.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, buffer);
} else {
// Put this back later
Pixmap pixmap = Pixmap.pixmaps.get(((IntBuffer) pixels).get(0));
gl.texSubImage2D(target, level, xoffset, yoffset, width, height, pixmap.getCanvasElement());
}
}
示例13: doSend
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
@Override
public void doSend(byte[] data) {
// Log.d(TAG, "doSend");
if (isClosed) {
return;
}
Uint8Array push = TypedArrays.createUint8Array(data.length);
for (int i = 0; i < data.length; i++) {
push.set(i, data[i]);
}
send(push);
}
示例14: convertBytes
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
public static byte[] convertBytes(ArrayBuffer buffer) {
Uint8Array array = TypedArrays.createUint8Array(buffer);
byte[] res = new byte[array.length()];
for (int i = 0; i < res.length; i++) {
res[i] = (byte) (array.get(i));
}
return res;
}
示例15: read
import com.google.gwt.typedarrays.shared.Uint8Array; //导入依赖的package包/类
@Override
public Promise<FilePart> read(int fileOffset, int len) {
return new Promise<>(resolver -> {
JsFileReader fileReader = JsFileReader.create();
fileReader.setOnLoaded(message -> {
Uint8Array array = TypedArrays.createUint8Array(message);
byte[] data = new byte[len];
for (int i = 0; i < len; i++) {
data[i] = (byte) (array.get(i));
}
resolver.result(new FilePart(fileOffset, len, data));
});
fileReader.readAsArrayBuffer(jsFile.slice(fileOffset, fileOffset + len));
});
}