List of usage examples for com.google.common.io ByteArrayDataOutput writeDouble
@Override void writeDouble(double v);
From source file:nxminetilities.network.MultilightPacket.java
@Override public void write(ByteArrayDataOutput out) { out.writeInt(x);//from w ww . j a v a 2s . c o m out.writeInt(y); out.writeInt(z); out.writeDouble(lightColourRed); out.writeDouble(lightColourGreen); out.writeDouble(lightColourBlue); out.writeBoolean(lightEnabled); }
From source file:buildcraft.core.EntityLaser.java
@Override public void writeSpawnData(ByteArrayDataOutput data) { data.writeDouble(head.x); data.writeDouble(head.y);/* ww w .j av a 2 s.co m*/ data.writeDouble(head.z); data.writeDouble(tail.x); data.writeDouble(tail.y); data.writeDouble(tail.z); }
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 . j ava2 s . com 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:buildcraft.factory.EntityMechanicalArm.java
@Override public void writeSpawnData(ByteArrayDataOutput data) { data.writeDouble(armSizeX); data.writeDouble(armSizeZ); }
From source file:io.github.apfelcreme.LitePortals.Bungee.BukkitMessenger.java
/** * teleports a player to a location. If that location is on a different Bukkit instance, he is being sent to that server * * @param uuid the player uuid * @param targetLocation the target location the player is being teleported to. *///from w w w .j a va2 s.c o m public void teleportPlayer(UUID uuid, Location targetLocation) { ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); if (player != null) { try { ServerInfo serverInfo = LitePortals.getInstance().getTargetServer(targetLocation.getServer()); if (serverInfo != null) { if (!player.getServer().getInfo().equals(serverInfo) && serverInfo.getAddress().getAddress().isReachable(2000)) { player.connect(serverInfo); LitePortals.getInstance().getLogger() .info(player.getName() + " used a LitePortal to " + serverInfo.getName()); } ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("WARP"); out.writeUTF(uuid.toString()); out.writeUTF(targetLocation.getWorld()); out.writeDouble(targetLocation.getX()); out.writeDouble(targetLocation.getY()); out.writeDouble(targetLocation.getZ()); out.writeDouble(targetLocation.getYaw()); serverInfo.sendData("LitePortals", out.toByteArray()); } } catch (IOException e) { e.printStackTrace(); } } }
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);// w w w .j a va2 s. co 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:org.apache.druid.indexer.InputRowSerde.java
public static final SerializeResult toBytes(final Map<String, IndexSerdeTypeHelper> typeHelperMap, final InputRow row, AggregatorFactory[] aggs) { try {/*from w ww . jav a 2s . co m*/ 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); } }