Java Code Examples for java.nio.ByteBuffer.getFloat()
The following are Jave code examples for showing how to use
getFloat() of the
java.nio.ByteBuffer
class.
You can vote up the examples you like. Your votes will be used in our system to get
more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10 File: ByteBufferViews.java View Source Code | 6 votes |
@Test(dataProvider = "floatViewProvider") public void testFloatGet(String desc, IntFunction<ByteBuffer> fbb, Function<ByteBuffer, FloatBuffer> fbi) { ByteBuffer bb = allocate(fbb); FloatBuffer vb = fbi.apply(bb); int o = bb.position(); for (int i = 0; i < vb.limit(); i++) { float fromBytes = getFloatFromBytes(bb, o + i * 4); float fromMethodView = bb.getFloat(o + i * 4); assertValues(i, fromBytes, fromMethodView, bb); float fromBufferView = vb.get(i); assertValues(i, fromMethodView, fromBufferView, bb, vb); } for (int i = 0; i < vb.limit(); i++) { float v = getFloatFromBytes(bb, o + i * 4); float a = bb.getFloat(); assertValues(i, v, a, bb); float b = vb.get(); assertValues(i, a, b, bb, vb); } }
Example 2
Project: penguins-in-space File: NetworkSystem.java View Source Code | 6 votes |
private void updateEntity(String participantId, ByteBuffer wrap) { Entity entity = null; for (Entity syncedEntity : syncedEntities) { if (idMapper.get(syncedEntity).participantId.equals(participantId)) { entity = syncedEntity; break; } } if (entity == null) { Gdx.app.debug(TAG, "updateEntity: NULL"); return; } TransformComponent transformComponent = transformMapper.get(entity); MovementComponent movement = movementMapper.get(entity); if (transformComponent == null || movement == null) return; transformComponent.position.x = wrap.getFloat(); transformComponent.position.y = wrap.getFloat(); transformComponent.rotation.x = wrap.getFloat(); transformComponent.rotation.y = wrap.getFloat(); movement.velocity.x = wrap.getFloat(); movement.velocity.y = wrap.getFloat(); movement.acceleration.x = wrap.getFloat(); movement.acceleration.y = wrap.getFloat(); }
Example 3
Project: openjdk-jdk10 File: DirectByteBufferTest.java View Source Code | 5 votes |
Ret unalignedReadSnippet(byte[] arg) { ByteBuffer buffer = makeDirect(arg, byteOrder); Ret ret = new Ret(); ret.byteValue = buffer.get(); ret.shortValue = buffer.getShort(); ret.intValue = buffer.getInt(); ret.longValue = buffer.getLong(); ret.doubleValue = buffer.getDouble(); ret.floatValue = buffer.getFloat(); return ret; }
Example 4
Project: multiple-dimension-spread File: OptimizeFloatColumnBinaryMaker.java View Source Code | 5 votes |
@Override public PrimitiveObject[] getDicPrimitiveArray( final byte[] buffer , final int start , final int length ) throws IOException{ int size = length / Float.BYTES; PrimitiveObject[] result = new PrimitiveObject[size]; ByteBuffer wrapBuffer = ByteBuffer.wrap( buffer , start , length ); wrapBuffer.getFloat(); for( int i = 1 ; i < size ; i++ ){ result[i] = new FloatObj( wrapBuffer.getFloat() ); } return result; }
Example 5
Project: simulacron File: CqlMapper.java View Source Code | 5 votes |
@Override Float decodeInternal(ByteBuffer input) { if (input == null || input.remaining() == 0) return 0.0f; if (input.remaining() != 4) throw new InvalidTypeException( "Invalid 32-bits float value, expecting 4 bytes but got " + input.remaining()); return input.getFloat(input.position()); }
Example 6
Project: abhot File: ValueSerializer.java View Source Code | 5 votes |
public static double getDoubleFromByteBuffer(ByteBuffer byteBuffer) { byte flag = byteBuffer.get(); double ret = 0; if (flag == FLOAT_VALUE) ret = byteBuffer.getFloat(); else ret = byteBuffer.getDouble(); return (ret); }
Example 7
Project: Mindustry File: Packets.java View Source Code | 5 votes |
@Override public void read(ByteBuffer buffer) { weaponid = buffer.get(); x = buffer.getFloat(); y = buffer.getFloat(); rotation = buffer.getFloat(); playerid = buffer.getInt(); }
Example 8
Project: Mindustry File: Packets.java View Source Code | 5 votes |
@Override public void read(ByteBuffer buffer) { type = buffer.getShort(); owner = buffer.getInt(); x = buffer.getFloat(); y = buffer.getFloat(); angle = buffer.getFloat(); damage = buffer.getShort(); }
Example 9
Project: openjdk-jdk10 File: DirectByteBufferTest.java View Source Code | 5 votes |
Ret alignedReadSnippet(byte[] arg) { ByteBuffer buffer = makeDirect(arg, byteOrder); Ret ret = new Ret(); ret.byteValue = buffer.get(); ret.byteValue += buffer.get(); ret.shortValue = buffer.getShort(); ret.intValue = buffer.getInt(); ret.longValue = buffer.getLong(); ret.doubleValue = buffer.getDouble(); ret.floatValue = buffer.getFloat(); return ret; }
Example 10
Project: GRIB2Tools File: DataRepresentationTemplate50.java View Source Code | 5 votes |
public DataRepresentationTemplate50(ByteBuffer byteBuffer) { referenceValueR = byteBuffer.getFloat(); binaryScaleFactorE = GribSection.correctNegativeShort(byteBuffer.getShort()); decimalScaleFactorD = GribSection.correctNegativeShort(byteBuffer.getShort()); numberBits = byteBuffer.get(); typeOfField = byteBuffer.get(); }
Example 11
Project: openjdk-jdk10 File: ByteBufferTest.java View Source Code | 5 votes |
Ret unalignedReadSnippet(byte[] arg) { ByteBuffer buffer = ByteBuffer.wrap(arg).order(byteOrder); Ret ret = new Ret(); ret.byteValue = buffer.get(); ret.shortValue = buffer.getShort(); ret.intValue = buffer.getInt(); ret.longValue = buffer.getLong(); ret.doubleValue = buffer.getDouble(); ret.floatValue = buffer.getFloat(); return ret; }
Example 12
Project: mycat-src-1.6.1-RELEASE File: ByteBufferUtil.java View Source Code | 4 votes |
public static float toFloat(ByteBuffer bytes) { return bytes.getFloat(bytes.position()); }
Example 13
Project: multiple-dimension-spread File: ConstantColumnBinaryMaker.java View Source Code | 4 votes |
@Override public void loadInMemoryStorage( final ColumnBinary columnBinary , final IMemoryAllocator allocator ) throws IOException{ ByteBuffer wrapBuffer = ByteBuffer.wrap( columnBinary.binary , columnBinary.binaryStart , columnBinary.binaryLength ); switch( columnBinary.columnType ){ case BOOLEAN: boolean booleanObj = wrapBuffer.get() == 1; for( int i = 0 ; i < columnBinary.rowCount ; i++ ){ allocator.setBoolean( i , booleanObj ); } break; case BYTE: byte byteObj = wrapBuffer.get(); for( int i = 0 ; i < columnBinary.rowCount ; i++ ){ allocator.setByte( i , byteObj ); } break; case SHORT: short shortObj = wrapBuffer.getShort(); for( int i = 0 ; i < columnBinary.rowCount ; i++ ){ allocator.setShort( i , shortObj ); } break; case INTEGER: int intObj = wrapBuffer.getInt(); for( int i = 0 ; i < columnBinary.rowCount ; i++ ){ allocator.setInteger( i , intObj ); } break; case LONG: long longObj = wrapBuffer.getLong(); for( int i = 0 ; i < columnBinary.rowCount ; i++ ){ allocator.setLong( i , longObj ); } break; case FLOAT: float floatObj = wrapBuffer.getFloat(); for( int i = 0 ; i < columnBinary.rowCount ; i++ ){ allocator.setFloat( i , floatObj ); } break; case DOUBLE: double doubleObj = wrapBuffer.getDouble(); for( int i = 0 ; i < columnBinary.rowCount ; i++ ){ allocator.setDouble( i , doubleObj ); } break; case STRING: int stringLength = wrapBuffer.getInt(); byte[] stringBytes = new byte[stringLength]; wrapBuffer.get( stringBytes ); String utf8 = new String( stringBytes , "UTF-8" ); for( int i = 0 ; i < columnBinary.rowCount ; i++ ){ allocator.setString( i , utf8 ); } break; case BYTES: int byteLength = wrapBuffer.getInt(); byte[] byteBytes = new byte[byteLength]; wrapBuffer.get( byteBytes ); for( int i = 0 ; i < columnBinary.rowCount ; i++ ){ allocator.setBytes( i , byteBytes ); } break; default: throw new IOException( "Unknown primitive type." ); } allocator.setValueCount( columnBinary.rowCount ); }
Example 14
Project: sstable-adaptor File: ByteBufferUtil.java View Source Code | 4 votes |
public static float toFloat(ByteBuffer bytes) { return bytes.getFloat(bytes.position()); }
Example 15
Project: CodeBroker File: DefaultSFSDataSerializer.java View Source Code | 4 votes |
private DataWrapper binDecode_FLOAT(ByteBuffer buffer) { float floatValue = buffer.getFloat(); return new DataWrapper(DataType.FLOAT, Float.valueOf(floatValue)); }
Example 16
Project: EasyDiameter File: Float32AVP.java View Source Code | 4 votes |
@Override public void decodeData(ByteBuffer buffer, int length) { data = buffer.getFloat(); addDataLength(length); }
Example 17
Project: Cybernet-VPN File: LogItem.java View Source Code | 4 votes |
public LogItem(byte[] in, int length) throws UnsupportedEncodingException { ByteBuffer bb = ByteBuffer.wrap(in, 0, length); bb.get(); // ignore version logtime = bb.getLong(); mVerbosityLevel = bb.getInt(); mLevel = VpnStatus.LogLevel.getEnumByValue(bb.getInt()); mRessourceId = bb.getInt(); int len = bb.getInt(); if (len == 0) { mMessage = null; } else { if (len > bb.remaining()) throw new IndexOutOfBoundsException("String length " + len + " is bigger than remaining bytes " + bb.remaining()); byte[] utf8bytes = new byte[len]; bb.get(utf8bytes); mMessage = new String(utf8bytes, "UTF-8"); } int numArgs = bb.getInt(); if (numArgs > 30) { throw new IndexOutOfBoundsException("Too many arguments for Logitem to unmarschal"); } if (numArgs == 0) { mArgs = null; } else { mArgs = new Object[numArgs]; for (int i = 0; i < numArgs; i++) { char type = bb.getChar(); switch (type) { case 's': mArgs[i] = unmarschalString(bb); break; case 'i': mArgs[i] = bb.getInt(); break; case 'd': mArgs[i] = bb.getDouble(); break; case 'f': mArgs[i] = bb.getFloat(); break; case 'l': mArgs[i] = bb.getLong(); break; case '0': mArgs[i] = null; break; default: throw new UnsupportedEncodingException("Unknown format type: " + type); } } } if (bb.hasRemaining()) throw new UnsupportedEncodingException(bb.remaining() + " bytes left after unmarshaling everything"); }
Example 18
Project: BIMplatform File: ReadWriteVirtualObject.java View Source Code | 4 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) protected Object readFeature(ByteBuffer buffer) { int typeValue = buffer.getInt(); ReadWriteType type = ReadWriteType.getType(typeValue); Object value = null; switch (type) { case String: int length = buffer.getInt(); if (length != -1) { value = BinUtils.readString(buffer, length); } break; case Integer: value = buffer.getInt(); break; case Double: value = buffer.getDouble(); break; case Float: value = buffer.getFloat(); break; case Long: value = buffer.getLong(); break; case Boolean: value = (buffer.get() == 1); break; case List: List list = new ArrayList<>(); int size = buffer.getInt(); for (int i = 0; i < size; i++) { Object valueInList = readFeature(buffer); list.add(valueInList); } value = list; break; case ByteArray: int byteLength = buffer.getInt(); if (byteLength != 0) { byte[] valueByte = new byte[byteLength]; buffer.get(valueByte); value = valueByte; } break; case ReadWriteVirtualObject: ReadWriteVirtualObject readWriteVirtualObject = createReadWriteVirtualObject(); readWriteVirtualObject.read(buffer); value = readWriteVirtualObject; break; default: break; } return value; }
Example 19
Project: BIMplatform File: BinUtils.java View Source Code | 4 votes |
public static float byteArrayToFloat(byte[] data) { ByteBuffer byteBuffer = ByteBuffer.wrap(data); return byteBuffer.getFloat(); }
Example 20
Project: BIMplatform File: BinUtils.java View Source Code | 4 votes |
public static float byteArrayToFloat(byte[] value, int index) { ByteBuffer byteBuffer = ByteBuffer.wrap(value); return byteBuffer.getFloat(index); }