use of java.nio.ByteBuffer in project titan by thinkaurelius.
the class HBaseStoreManager method getStartKey.
/**
* This method generates the second argument to
* {@link HBaseAdmin#createTable(HTableDescriptor, byte[], byte[], int)}.
* <p/>
* From the {@code createTable} javadoc:
* "The start key specified will become the end key of the first region of
* the table, and the end key specified will become the start key of the
* last region of the table (the first region has a null start key and
* the last region has a null end key)"
* <p/>
* To summarize, the {@code createTable} argument called "startKey" is
* actually the end key of the first region.
*/
private byte[] getStartKey(int regionCount) {
ByteBuffer regionWidth = ByteBuffer.allocate(4);
regionWidth.putInt((int) (((1L << 32) - 1L) / regionCount)).flip();
return StaticArrayBuffer.of(regionWidth).getBytes(0, 4);
}
use of java.nio.ByteBuffer in project playn by threerings.
the class AndroidSurfaceGL method onSurfaceCreated.
@Override
public void onSurfaceCreated() {
createTexture();
if (cachedPixels != null) {
try {
AndroidGLContext actx = (AndroidGLContext) ctx;
ByteBuffer pixelBuffer = ByteBuffer.allocate(texWidth * texHeight * 4);
FileInputStream in = new FileInputStream(cachedPixels);
in.read(pixelBuffer.array());
in.close();
int bufferTex = actx.createTexture(false, false, false);
actx.gl.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, texWidth, texHeight, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer);
// bind our surface framebuffer and render the saved texture data into it
bindFramebuffer();
ctx.quadShader(null).prepareTexture(bufferTex, Tint.NOOP_TINT).addQuad(StockInternalTransform.IDENTITY, 0, texHeight, texWidth, 0, 0, 0, 1, 1);
// rebind the default frame buffer (which will flush the rendering operation)
ctx.bindFramebuffer();
ctx.destroyTexture(bufferTex);
pixelBuffer = null;
cachedPixels.delete();
cachedPixels = null;
} catch (IOException e) {
PlayN.reportError("Error reading cached surface pixels from file.", e);
}
}
}
use of java.nio.ByteBuffer in project playn by threerings.
the class AndroidSurfaceGL method onSurfaceLost.
@Override
public void onSurfaceLost() {
try {
AndroidGLContext actx = (AndroidGLContext) ctx;
bindFramebuffer();
ByteBuffer pixelBuffer = ByteBuffer.allocate(texWidth * texHeight * 4);
actx.gl.glReadPixels(0, 0, texWidth, texHeight, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer);
actx.checkGLError("glReadPixels");
try {
cachedPixels = new File(cacheDir, "surface-" + Integer.toHexString(hashCode()));
FileOutputStream out = new FileOutputStream(cachedPixels);
out.write(pixelBuffer.array());
out.close();
} catch (IOException e) {
PlayN.reportError("IOException writing cached Surface to file.", e);
cachedPixels = null;
}
pixelBuffer = null;
} catch (OutOfMemoryError e) {
PlayN.reportError("OutOfMemoryError reading cached Surface to buffer.", e);
cachedPixels = null;
}
clearTexture();
}
use of java.nio.ByteBuffer in project watson by totemo.
the class Screenshot method save.
// --------------------------------------------------------------------------
/**
* Save a screenshot.
*
* @param file the file to write.
* @param width the screen width.
* @param height the screen height.
*/
public static IChatComponent save(File file, int width, int height) {
try {
file.getParentFile().mkdirs();
ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * 4);
GL11.glReadBuffer(GL11.GL_FRONT);
// GL11.glReadBuffer() unexpectedly sets an error state (invalid enum).
GL11.glGetError();
GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int i = (x + width * y) * 4;
int r = buffer.get(i) & 0xFF;
int g = buffer.get(i + 1) & 0xFF;
int b = buffer.get(i + 2) & 0xFF;
image.setRGB(x, (height - 1) - y, (0xFF << 24) | (r << 16) | (g << 8) | b);
}
}
ImageIO.write(image, "png", file);
ChatComponentText text = new ChatComponentText(file.getName());
text.getChatStyle().setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath()));
text.getChatStyle().setUnderlined(Boolean.valueOf(true));
return new ChatComponentTranslation("screenshot.success", new Object[] { text });
} catch (Exception ex) {
return new ChatComponentTranslation("screenshot.failure", new Object[] { ex.getMessage() });
}
}
use of java.nio.ByteBuffer in project titan by thinkaurelius.
the class WriteByteBuffer method require.
private void require(int size) {
if (buffer.capacity() - buffer.position() < size) {
//Need to resize
//extra capacity as buffer
int newcapacity = buffer.position() + size + buffer.capacity();
Preconditions.checkArgument(newcapacity <= MAX_BUFFER_CAPACITY, "Capacity exceeds max buffer capacity: %s", MAX_BUFFER_CAPACITY);
ByteBuffer newBuffer = ByteBuffer.allocate(newcapacity);
buffer.flip();
newBuffer.put(buffer);
buffer = newBuffer;
}
}
Aggregations