本文整理汇总了Java中java.nio.ByteBuffer.getFloat方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.getFloat方法的具体用法?Java ByteBuffer.getFloat怎么用?Java ByteBuffer.getFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.getFloat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFloatGet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@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);
}
}
示例2: updateEntity
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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();
}
示例3: unalignedReadSnippet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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;
}
示例4: getDicPrimitiveArray
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@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;
}
示例5: decodeInternal
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@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());
}
示例6: getDoubleFromByteBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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);
}
示例7: read
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public void read(ByteBuffer buffer) {
weaponid = buffer.get();
x = buffer.getFloat();
y = buffer.getFloat();
rotation = buffer.getFloat();
playerid = buffer.getInt();
}
示例8: alignedReadSnippet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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;
}
示例9: DataRepresentationTemplate50
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public DataRepresentationTemplate50(ByteBuffer byteBuffer) {
referenceValueR = byteBuffer.getFloat();
binaryScaleFactorE = GribSection.correctNegativeShort(byteBuffer.getShort());
decimalScaleFactorD = GribSection.correctNegativeShort(byteBuffer.getShort());
numberBits = byteBuffer.get();
typeOfField = byteBuffer.get();
}
示例10: unalignedReadSnippet
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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;
}
示例11: toFloat
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static float toFloat(ByteBuffer bytes)
{
return bytes.getFloat(bytes.position());
}
示例12: loadInMemoryStorage
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@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 );
}
示例13: binDecode_FLOAT
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private DataWrapper binDecode_FLOAT(ByteBuffer buffer) {
float floatValue = buffer.getFloat();
return new DataWrapper(DataType.FLOAT, Float.valueOf(floatValue));
}
示例14: decodeData
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public void decodeData(ByteBuffer buffer, int length) {
data = buffer.getFloat();
addDataLength(length);
}
示例15: LogItem
import java.nio.ByteBuffer; //导入方法依赖的package包/类
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");
}