public void testNewDataOutput_writeUTF() { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("r\u00C9sum\u00C9"); byte[] expected = "r\u00C9sum\u00C9".getBytes(Charsets.UTF_8); byte[] actual = out.toByteArray(); // writeUTF writes the length of the string in 2 bytes assertEquals(0, actual[0]); assertEquals(expected.length, actual[1]); assertEquals(expected, Arrays.copyOfRange(actual, 2, actual.length)); }
public byte[] serializeEvent(DataPointEvent dataPointEvent) { //Todo: Create some adaptive value here, keep stats on if the buffer increases and slowely increase it ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(64); dataOutput.writeUTF(dataPointEvent.getMetricName()); dataOutput.writeInt(dataPointEvent.getTtl()); dataOutput.writeLong(dataPointEvent.getDataPoint().getTimestamp()); dataOutput.writeUTF(dataPointEvent.getDataPoint().getDataStoreDataType()); try { dataPointEvent.getDataPoint().writeValueToBuffer(dataOutput); } catch (IOException e) { logger.error("Error serializing DataPoint", e); } dataOutput.writeInt(dataPointEvent.getTags().size()); for (Map.Entry<String, String> entry : dataPointEvent.getTags().entrySet()) { dataOutput.writeUTF(entry.getKey()); dataOutput.writeUTF(entry.getValue()); } return dataOutput.toByteArray(); }
out.writeUTF( channel ); out.writeShort( data.length ); out.write( data ); out.writeUTF( channel ); out.writeShort( data.length ); out.write( data ); out.writeUTF( "IP" ); out.writeUTF( con.getAddress().getHostString() ); out.writeInt( con.getAddress().getPort() ); out.writeUTF( "PlayerCount" ); if ( target.equals( "ALL" ) ) out.writeUTF( "ALL" ); out.writeInt( bungee.getOnlineCount() ); } else out.writeUTF( server.getName() ); out.writeInt( server.getPlayers().size() ); out.writeUTF( "PlayerList" ); if ( target.equals( "ALL" ) ) out.writeUTF( "ALL" ); out.writeUTF( Util.csv( bungee.getPlayers() ) ); } else
@Override public void appendPayload(ByteArrayDataOutput out) { out.writeUTF(this.serverName); }
private void serializeCollection(Collection<?> collection, ByteArrayDataOutput output) { output.writeInt(collection.size()); for (Object o : collection) { output.writeUTF(o.toString()); } }
private void serializeMultimap(Multimap<String, String> collection, boolean includeNames, ByteArrayDataOutput output) { output.writeInt(collection.keySet().size()); for (Map.Entry<String, Collection<String>> entry : collection.asMap().entrySet()) { output.writeUTF(entry.getKey()); if (includeNames) { serializeCollection(entry.getValue(), output); } else { output.writeInt(entry.getValue().size()); } } }
@Override public void writeTo(ByteArrayDataOutput output) { output.writeBoolean(willEnable); output.writeUTF(playerName); output.writeBoolean(isSourceInvoker); }
public void sendToBukkit(String channel, List<String> messages) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF(channel); messages.forEach((msg) -> { out.writeUTF(msg); }); ProxyServer.getInstance().getServers().keySet().forEach(server -> { ProxyServer.getInstance().getServerInfo(server).sendData("AdvancedBan", out.toByteArray(), true); }); } }
@Override public void writeTo(ByteArrayDataOutput output) { output.writeInt(type.ordinal()); //Data is sent through a random player. We have to tell the Bukkit version of this plugin the target output.writeUTF(playerName); //proxy identifier to check if it's a acceptable proxy output.writeLong(proxyId.getMostSignificantBits()); output.writeLong(proxyId.getLeastSignificantBits()); }
private void serializeMultiset(Multiset<String> collection, ByteArrayDataOutput output) { output.writeInt(collection.elementSet().size()); for (Multiset.Entry<String> entry : collection.entrySet()) { output.writeUTF(entry.getElement()); output.writeInt(entry.getCount()); } }