List of usage examples for com.google.common.io ByteArrayDataOutput writeFloat
@Override void writeFloat(float v);
From source file:shadowmage.ancient_warfare.common.vehicles.missiles.MissileBase.java
@Override public void writeSpawnData(ByteArrayDataOutput data) { data.writeInt(missileType);/*from w w w.j a v a 2 s . c om*/ data.writeFloat(rotationYaw); data.writeFloat(rotationPitch); data.writeBoolean(inGround); data.writeInt(blockX); data.writeInt(blockY); data.writeInt(blockZ); data.writeInt(blockID); data.writeInt(blockMeta); data.writeInt(rocketBurnTime); data.writeBoolean(this.launcher != null); if (this.launcher != null) { data.writeInt(this.launcher.entityId); } }
From source file:shadowmage.ancient_warfare.common.gates.EntityGate.java
@Override public void writeSpawnData(ByteArrayDataOutput data) { data.writeInt(pos1.x);/* ww w . j a v a 2 s .c o m*/ data.writeInt(pos1.y); data.writeInt(pos1.z); data.writeInt(pos2.x); data.writeInt(pos2.y); data.writeInt(pos2.z); data.writeInt(this.gateType.getGlobalID()); data.writeInt(this.teamNum); data.writeFloat(this.edgePosition); data.writeFloat(this.edgeMax); data.writeByte(this.gateStatus); data.writeByte(this.gateOrientation); data.writeInt(health); }
From source file:org.wso2.carbon.analytics.data.commons.utils.AnalyticsCommonUtils.java
public static byte[] encodeElement(String name, Object value) throws AnalyticsException { ByteArrayDataOutput buffer = ByteStreams.newDataOutput(); byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8); buffer.writeInt(nameBytes.length);//from ww w . ja v a 2 s .c o m buffer.write(nameBytes); if (value instanceof String) { buffer.write(DATA_TYPE_STRING); String strVal = (String) value; byte[] strBytes = strVal.getBytes(StandardCharsets.UTF_8); buffer.writeInt(strBytes.length); buffer.write(strBytes); } else if (value instanceof Long) { buffer.write(DATA_TYPE_LONG); buffer.writeLong((Long) value); } else if (value instanceof Double) { buffer.write(DATA_TYPE_DOUBLE); buffer.writeDouble((Double) value); } else if (value instanceof Boolean) { buffer.write(DATA_TYPE_BOOLEAN); boolean boolVal = (Boolean) value; if (boolVal) { buffer.write(BOOLEAN_TRUE); } else { buffer.write(BOOLEAN_FALSE); } } else if (value instanceof Integer) { buffer.write(DATA_TYPE_INTEGER); buffer.writeInt((Integer) value); } else if (value instanceof Float) { buffer.write(DATA_TYPE_FLOAT); buffer.writeFloat((Float) value); } else if (value instanceof byte[]) { buffer.write(DATA_TYPE_BINARY); byte[] binData = (byte[]) value; buffer.writeInt(binData.length); buffer.write(binData); } else if (value == null) { buffer.write(DATA_TYPE_NULL); } else { buffer.write(DATA_TYPE_OBJECT); byte[] binData = serializeObject(value); buffer.writeInt(binData.length); buffer.write(binData); } return buffer.toByteArray(); }
From source file:smpships.entity.EntityShipBlock.java
@Override protected void writeControlBlockSpawnData(ByteArrayDataOutput data) { // runs on server data.writeUTF(name);/*from w w w.j a v a 2s.co m*/ data.writeUTF(captain); // write mates data.writeInt(mates.size()); for (String mate : mates) data.writeUTF(mate); data.writeFloat(draft); data.writeInt(children.size()); for (int i = 0; i < children.size(); i++) { // write child data data.writeInt(children.get(i).xOff); data.writeInt(children.get(i).yOff); data.writeInt(children.get(i).zOff); data.writeInt(children.get(i).blockID); data.writeInt(children.get(i).metadata); } }
From source file:org.wso2.carbon.analytics.datasource.core.util.GenericUtils.java
public static byte[] encodeElement(String name, Object value) throws AnalyticsException { ByteArrayDataOutput buffer = ByteStreams.newDataOutput(); byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8); buffer.writeInt(nameBytes.length);/*from www.ja v a 2s . c o m*/ buffer.write(nameBytes); if (value instanceof String) { buffer.write(DATA_TYPE_STRING); String strVal = (String) value; byte[] strBytes = strVal.getBytes(StandardCharsets.UTF_8); buffer.writeInt(strBytes.length); buffer.write(strBytes); } else if (value instanceof Long) { buffer.write(DATA_TYPE_LONG); buffer.writeLong((Long) value); } else if (value instanceof Double) { buffer.write(DATA_TYPE_DOUBLE); buffer.writeDouble((Double) value); } else if (value instanceof Boolean) { buffer.write(DATA_TYPE_BOOLEAN); boolean boolVal = (Boolean) value; if (boolVal) { buffer.write(BOOLEAN_TRUE); } else { buffer.write(BOOLEAN_FALSE); } } else if (value instanceof Integer) { buffer.write(DATA_TYPE_INTEGER); buffer.writeInt((Integer) value); } else if (value instanceof Float) { buffer.write(DATA_TYPE_FLOAT); buffer.writeFloat((Float) value); } else if (value instanceof byte[]) { buffer.write(DATA_TYPE_BINARY); byte[] binData = (byte[]) value; buffer.writeInt(binData.length); buffer.write(binData); } else if (value == null) { buffer.write(DATA_TYPE_NULL); } else { buffer.write(DATA_TYPE_OBJECT); byte[] binData = GenericUtils.serializeObject(value); buffer.writeInt(binData.length); buffer.write(binData); } return buffer.toByteArray(); }
From source file:shadowmage.ancient_warfare.common.vehicles.VehicleBase.java
@Override public void writeSpawnData(ByteArrayDataOutput data) { data.writeFloat(this.getHealth()); data.writeInt(this.vehicleType.getGlobalVehicleType()); data.writeInt(this.vehicleMaterialLevel); ByteTools.writeNBTTagCompound(upgradeHelper.getNBTTag(), data); ByteTools.writeNBTTagCompound(ammoHelper.getNBTTag(), data); ByteTools.writeNBTTagCompound(moveHelper.getNBTTag(), data); ByteTools.writeNBTTagCompound(firingHelper.getNBTTag(), data); ByteTools.writeNBTTagCompound(firingVarsHelper.getNBTTag(), data); data.writeFloat(localLaunchPower);/* w ww . j a v a 2s . c om*/ data.writeFloat(localTurretPitch); data.writeFloat(localTurretRotation); data.writeFloat(localTurretDestPitch); data.writeFloat(localTurretDestRot); data.writeInt(teamNum); data.writeFloat(localTurretRotationHome); data.writeBoolean(this.isSettingUp); if (this.isSettingUp) { data.writeInt(this.setupTicks); } }
From source file:org.apache.druid.indexer.InputRowSerde.java
public static final SerializeResult toBytes(final Map<String, IndexSerdeTypeHelper> typeHelperMap, final InputRow row, AggregatorFactory[] aggs) { try {/*from w w w .jav a 2 s . com*/ List<String> parseExceptionMessages = new ArrayList<>(); ByteArrayDataOutput out = ByteStreams.newDataOutput(); //write timestamp out.writeLong(row.getTimestampFromEpoch()); //writing all dimensions List<String> dimList = row.getDimensions(); WritableUtils.writeVInt(out, dimList.size()); for (String dim : dimList) { IndexSerdeTypeHelper typeHelper = typeHelperMap.get(dim); if (typeHelper == null) { typeHelper = STRING_HELPER; } writeString(dim, out); try { typeHelper.serialize(out, row.getRaw(dim)); } catch (ParseException pe) { parseExceptionMessages.add(pe.getMessage()); } } //writing all metrics Supplier<InputRow> supplier = () -> row; WritableUtils.writeVInt(out, aggs.length); for (AggregatorFactory aggFactory : aggs) { String k = aggFactory.getName(); writeString(k, out); try (Aggregator agg = aggFactory.factorize(IncrementalIndex .makeColumnSelectorFactory(VirtualColumns.EMPTY, aggFactory, supplier, true))) { try { agg.aggregate(); } catch (ParseException e) { // "aggregate" can throw ParseExceptions if a selector expects something but gets something else. log.debug(e, "Encountered parse error, skipping aggregator[%s].", k); parseExceptionMessages.add(e.getMessage()); } String t = aggFactory.getTypeName(); if (agg.isNull()) { out.writeByte(NullHandling.IS_NULL_BYTE); } else { out.writeByte(NullHandling.IS_NOT_NULL_BYTE); if ("float".equals(t)) { out.writeFloat(agg.getFloat()); } else if ("long".equals(t)) { WritableUtils.writeVLong(out, agg.getLong()); } else if ("double".equals(t)) { out.writeDouble(agg.getDouble()); } else { //its a complex metric Object val = agg.get(); ComplexMetricSerde serde = getComplexMetricSerde(t); writeBytes(serde.toBytes(val), out); } } } } return new SerializeResult(out.toByteArray(), parseExceptionMessages); } catch (IOException ex) { throw new RuntimeException(ex); } }