本文整理汇总了Java中java.nio.ByteBuffer.putFloat方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.putFloat方法的具体用法?Java ByteBuffer.putFloat怎么用?Java ByteBuffer.putFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.putFloat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unalignedWriteSnippet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
byte[] unalignedWriteSnippet(byte a, short b, int c, long d, double e, float f) {
byte[] ret = new byte[27];
ByteBuffer buffer = makeDirect(27, byteOrder);
buffer.put(a);
buffer.putShort(b);
buffer.putInt(c);
buffer.putLong(d);
buffer.putDouble(e);
buffer.putFloat(f);
buffer.position(0);
buffer.get(ret);
return ret;
}
示例2: saveWord2VecToBinary
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/** Save the word2vec model as binary file */
@SuppressWarnings("unused")
public static void saveWord2VecToBinary(String toPath, Word2Vec w2v){
final Charset cs = StandardCharsets.UTF_8;
try {
final OutputStream os = new FileOutputStream(new File(toPath));
final String header = String.format("%d %d\n", w2v.wordVocabSize(), w2v.getLayerSize());
os.write(header.getBytes(cs));
final ByteBuffer buffer = ByteBuffer.allocate(4 * w2v.getLayerSize());
buffer.order(byteOrder);
for (int i = 0; i < w2v.wordVocabSize(); ++i) {
os.write(String.format("%s ", w2v.getWordVocab().get(i)).getBytes(cs)); // Write one word in byte format, add a space.
buffer.clear();
for (int j = 0; j < w2v.getLayerSize(); ++j) {
buffer.putFloat(w2v.getWordVectors().getFloat(i, j));
}
os.write(buffer.array()); // Write all float values of one vector in byte format.
os.write('\n'); // Add a newline.
}
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例3: toDbb
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public ByteBuffer toDbb(ByteBuffer res, int index) {
res.putFloat(index + 0 * glm.Constants.FloatBYTES, m00);
res.putFloat(index + 1 * glm.Constants.FloatBYTES, m01);
res.putFloat(index + 2 * glm.Constants.FloatBYTES, m02);
res.putFloat(index + 3 * glm.Constants.FloatBYTES, m03);
res.putFloat(index + 4 * glm.Constants.FloatBYTES, m10);
res.putFloat(index + 5 * glm.Constants.FloatBYTES, m11);
res.putFloat(index + 6 * glm.Constants.FloatBYTES, m12);
res.putFloat(index + 7 * glm.Constants.FloatBYTES, m13);
res.putFloat(index + 8 * glm.Constants.FloatBYTES, m20);
res.putFloat(index + 9 * glm.Constants.FloatBYTES, m21);
res.putFloat(index + 10 * glm.Constants.FloatBYTES, m22);
res.putFloat(index + 11 * glm.Constants.FloatBYTES, m23);
res.putFloat(index + 12 * glm.Constants.FloatBYTES, m30);
res.putFloat(index + 13 * glm.Constants.FloatBYTES, m31);
res.putFloat(index + 14 * glm.Constants.FloatBYTES, m32);
res.putFloat(index + 15 * glm.Constants.FloatBYTES, m33);
return res;
}
示例4: processEntity
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
protected void processEntity(Entity entity, float deltaTime) {
TransformComponent transform = transformMapper.get(entity);
MovementComponent movement = movementMapper.get(entity);
ByteBuffer buffer = ByteBuffer.allocate(4 * 8 + 1);
buffer.put(MOVE);
buffer.putFloat(transform.position.x);
buffer.putFloat(transform.position.y);
buffer.putFloat(transform.rotation.x);
buffer.putFloat(transform.rotation.y);
buffer.putFloat(movement.velocity.x);
buffer.putFloat(movement.velocity.y);
buffer.putFloat(movement.acceleration.x);
buffer.putFloat(movement.acceleration.y);
networkService.sendUnreliableMessageToOthers(buffer.array());
}
示例5: sendBullet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void sendBullet(Entity entity) {
// Gdx.app.debug(TAG, "sendBullet: ");
IdComponent bulletId = idMapper.get(entity);
IdComponent playerId = idMapper.get(player.first());
if (!Objects.equals(bulletId.participantId, playerId.participantId)) {
return;
}
TransformComponent transform = transformMapper.get(entity);
MovementComponent movement = movementMapper.get(entity);
ByteBuffer buffer = ByteBuffer.allocate(4 * 4 + 1);
buffer.put(BULLET);
buffer.putFloat(transform.position.x);
buffer.putFloat(transform.position.y);
buffer.putFloat(movement.velocity.x);
buffer.putFloat(movement.velocity.y);
networkService.sendUnreliableMessageToOthers(buffer.array());
}
示例6: getTransposed
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public ByteBuffer getTransposed(int index, ByteBuffer buffer)
{
if (index == 0)
{
buffer.putFloat(0, m00);
buffer.putFloat(4, m10);
buffer.putFloat(8, m01);
buffer.putFloat(12, m11);
}
else
{
buffer.putFloat(index + 0, m00);
buffer.putFloat(index + 4, m10);
buffer.putFloat(index + 8, m01);
buffer.putFloat(index + 12, m11);
}
return buffer;
}
示例7: handleWrite
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
protected NotifyFuture<WriteResult> handleWrite ( final Variant value )
{
final MemoryRequestBlock block = this.block;
if ( block == null )
{
return new InstantErrorFuture<> ( new IllegalStateException ( "Device is not connected" ) );
}
final Double d = value.asDouble ( null );
if ( d != null )
{
final ByteBuffer b = ByteBuffer.allocate ( 4 );
b.putFloat ( d.floatValue () );
block.writeData ( toAddress ( this.index ), b.array () );
return new InstantFuture<WriteResult> ( new WriteResult () );
}
else
{
return new InstantErrorFuture<WriteResult> ( new IllegalArgumentException ( String.format ( "Can only write doubles: %s is not a double", value ) ) );
}
}
示例8: putOne
import java.nio.ByteBuffer; //导入方法依赖的package包/类
void putOne(ByteBuffer b, PrimitiveType t) {
switch (t) {
case BYTE: b.put((byte)0); break;
case CHAR: b.putChar('0'); break;
case SHORT: b.putShort((short)0); break;
case INT: b.putInt(0); break;
case LONG: b.putLong(0); break;
case FLOAT: b.putFloat(0); break;
case DOUBLE: b.putDouble(0); break;
}
}
示例9: alignedWriteSnippet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
byte[] alignedWriteSnippet(byte a, byte b, short c, int d, long e, double f, float g) {
byte[] ret = new byte[28];
ByteBuffer buffer = ByteBuffer.wrap(ret).order(byteOrder);
buffer.put(a);
buffer.put(b);
buffer.putShort(c);
buffer.putInt(d);
buffer.putLong(e);
buffer.putDouble(f);
buffer.putFloat(g);
return ret;
}
示例10: write
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public void write(ByteBuffer buffer) {
for(int i = 0; i < items.length; i ++){
buffer.putInt(items[i]);
}
buffer.putFloat(countdown);
buffer.putFloat(time);
buffer.putShort((short)enemies);
buffer.putShort((short)wave);
buffer.putLong(timestamp);
}
示例11: testUseFloatBufferViewOfByteBufferWithWrongByteOrder
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Test
public void testUseFloatBufferViewOfByteBufferWithWrongByteOrder() {
window = glfwCreateWindow(800, 600, "", 0L, 0L);
glfwMakeContextCurrent(window);
createCapabilities();
ByteBuffer bb = ByteBuffer.allocateDirect(16 * 4);
bb.putFloat(0, 1.0f);
FloatBuffer fb = bb.asFloatBuffer();
assertThrows(IllegalArgumentException.class, () -> glLoadMatrixf(fb), "buffer contains values written using non-native endianness.");
}
示例12: toCompactByteArray
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* 필요 dot data만 byte array로.
* (저장 시에.)
*
* @return byte [ ]
*/
public byte[] toCompactByteArray() {
ByteBuffer buffer = ByteBuffer.allocate(DOT_DATA_COMPACT_BYTE_ALIGN);
buffer.put( (byte) dotType );
buffer.putFloat( x );
buffer.putFloat( y);
buffer.putLong(timestamp);
// buffer.put((byte) fx);
// buffer.put((byte) fy);
buffer.put((byte) pressure);
return buffer.array();
}
示例13: sendObstacle
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void sendObstacle(Entity entity) {
TransformComponent transform = transformMapper.get(entity);
MovementComponent movement = movementMapper.get(entity);
ByteBuffer buffer = ByteBuffer.allocate(4 * 4 + 1);
buffer.put(OBSTACLE);
buffer.putFloat(transform.position.x);
buffer.putFloat(transform.position.y);
buffer.putFloat(movement.velocity.x);
buffer.putFloat(movement.velocity.y);
networkService.sendUnreliableMessageToOthers(buffer.array());
}
示例14: putFloat
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static ByteBuffer putFloat(ByteBuffer buf, float value) {
buf.putFloat(value);
writeByteBuffer(buf);
return buf;
}
示例15: binEncode_FLOAT
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private ByteBuffer binEncode_FLOAT(ByteBuffer buffer, Float value) {
ByteBuffer buf = ByteBuffer.allocate(5);
buf.put((byte) DataType.FLOAT.typeID);
buf.putFloat(value.floatValue());
return this.addData(buffer, buf.array());
}