當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBuffer.getFloat方法代碼示例

本文整理匯總了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);
    }

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:ByteBufferViews.java

示例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();
}
 
開發者ID:ezet,項目名稱:penguins-in-space,代碼行數:25,代碼來源:NetworkSystem.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:DirectByteBufferTest.java

示例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;
}
 
開發者ID:yahoojapan,項目名稱:multiple-dimension-spread,代碼行數:12,代碼來源:OptimizeFloatColumnBinaryMaker.java

示例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());
}
 
開發者ID:datastax,項目名稱:simulacron,代碼行數:10,代碼來源:CqlMapper.java

示例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);
}
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:13,代碼來源:ValueSerializer.java

示例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();
}
 
開發者ID:Anuken,項目名稱:Mindustry,代碼行數:9,代碼來源:Packets.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:DirectByteBufferTest.java

示例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();
	}
 
開發者ID:philippphb,項目名稱:GRIB2Tools,代碼行數:9,代碼來源:DataRepresentationTemplate50.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:ByteBufferTest.java

示例11: toFloat

import java.nio.ByteBuffer; //導入方法依賴的package包/類
public static float toFloat(ByteBuffer bytes)
{
    return bytes.getFloat(bytes.position());
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:5,代碼來源:ByteBufferUtil.java

示例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 );
}
 
開發者ID:yahoojapan,項目名稱:multiple-dimension-spread,代碼行數:69,代碼來源:ConstantColumnBinaryMaker.java

示例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));
}
 
開發者ID:zerosoft,項目名稱:CodeBroker,代碼行數:5,代碼來源:DefaultSFSDataSerializer.java

示例14: decodeData

import java.nio.ByteBuffer; //導入方法依賴的package包/類
@Override
public void decodeData(ByteBuffer buffer, int length) {
	data = buffer.getFloat();
	addDataLength(length);
}
 
開發者ID:mustafabayar,項目名稱:EasyDiameter,代碼行數:6,代碼來源:Float32AVP.java

示例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");
}
 
開發者ID:akashdeepsingh9988,項目名稱:Cybernet-VPN,代碼行數:53,代碼來源:LogItem.java


注:本文中的java.nio.ByteBuffer.getFloat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。