List of usage examples for com.google.common.io ByteArrayDataOutput toByteArray
byte[] toByteArray();
From source file:de.paleocrafter.pmfw.network.packet.PaleoPacket.java
public final Packet makePacket() throws IllegalArgumentException { if (PaleoPacketHandler.CHANNEL_NAME != null) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeByte(getPacketId());//from w ww. j ava 2s . c om write(out); return PacketDispatcher.getPacket(PaleoPacketHandler.CHANNEL_NAME, out.toByteArray()); } throw new IllegalArgumentException("You have to define a channel for the PowerGrid packets first!"); }
From source file:com.netflix.suro.message.MessageSerDe.java
@Override public byte[] serialize(Message payload) { try {/* ww w . ja v a2 s .c o m*/ ByteArrayDataOutput out = new ByteArrayDataOutputStream(outputStream.get()); out.writeByte(Message.classMap.inverse().get(payload.getClass())); payload.write(out); return out.toByteArray(); } catch (IOException e) { log.error("Exception on serialize: " + e.getMessage(), e); return new byte[] {}; } }
From source file:cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket.java
@Override public byte[] generatePacket(Object... data) { ByteArrayDataOutput dat = ByteStreams.newDataOutput(); dat.writeInt((Integer) data[0]); dat.writeInt((Integer) data[1]); dat.writeInt((Integer) data[2]); dat.writeInt((Integer) data[3]); return dat.toByteArray(); }
From source file:eu.matejkormuth.pexel.PexelCore.actions.TeleportAction.java
@Override public void execute(final Player player) { if (this.server.isLocalServer()) { // Just teleport player to target location. player.teleport(this.location); } else {/*w ww . ja v a 2s. c o m*/ // TODO: Add teleport to location. Perform server-wide teleport // Teleport to other server when using Bungee. ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Connect"); out.writeUTF(this.server.getBungeeName()); player.sendPluginMessage(Pexel.getCore(), "BungeeCord", out.toByteArray()); } }
From source file:io.github.apfelcreme.LitePortals.Bungee.BukkitMessenger.java
/** * sends a message to the bukkit to check the position of a player. * Bukkit then returns a message with a location of a portal if the player is standing in one * * @param player the player/*from w w w. j av a2 s . c o m*/ */ public void sendPositionRequest(ProxiedPlayer player) { ServerInfo target = player.getServer().getInfo(); if (target != null) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("POSITIONREQUEST"); out.writeUTF(player.getUniqueId().toString()); target.sendData("LitePortals", out.toByteArray()); } }
From source file:com.minestein.novacore.command.Hub.java
/** * @param sender The thing that sent the command. * @param command The command sent./*from ww w. j a v a 2 s. c om*/ * @param s The command's label. * @param strings The arguments to the command. * @return ignore */ @Override public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) { if (!(sender instanceof Player)) { sender.sendMessage(Core.getPrefix() + "4Only players can exit to hub!"); return true; } else { final Player p = (Player) sender; if (alreadySending.contains(p.getName())) { p.sendMessage(Core.getPrefix() + "4You are already going to the hub!"); return true; } alreadySending.add(p.getName()); String[] messages = new String[] { "Through the portal!", "They aren't gonna make it!", "RUUUNNNNNN!", "It's a trap!", "Don't do it!" }; p.sendMessage(Core.getPrefix() + "bSending you to the hub! bo" + messages[Core.random.nextInt(messages.length)]); Bukkit.getScheduler().runTaskLater(Core.plugin, new Runnable() { @Override public void run() { alreadySending.remove(p.getName()); ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Connect"); out.writeUTF("lobby"); p.sendPluginMessage(Core.plugin, "BungeeCord", out.toByteArray()); } }, 30); } return true; }
From source file:org.xdi.oxauth.service.fido.u2f.RawAuthenticationService.java
private byte[] packBytesToSign(byte[] appIdHash, byte userPresence, long counter, byte[] challengeHash) { ByteArrayDataOutput encoded = ByteStreams.newDataOutput(); encoded.write(appIdHash);/*from w w w.jav a2s . co m*/ encoded.write(userPresence); encoded.writeInt((int) counter); encoded.write(challengeHash); return encoded.toByteArray(); }
From source file:org.elasticsoftware.elasticactors.cassandra.serialization.CompressingSerializer.java
@Override public byte[] serialize(I object) throws IOException { byte[] serializedObject = delegate.serialize(object); if (serializedObject.length > compressionThreshold) { byte[] compressedBytes = lz4Compressor.compress(serializedObject); ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(compressedBytes.length + 8); dataOutput.write(MAGIC_HEADER);//from w ww . j a v a 2 s.co m dataOutput.writeInt(serializedObject.length); dataOutput.write(compressedBytes); return dataOutput.toByteArray(); } else { return serializedObject; } }
From source file:co.cask.cdap.data2.transaction.stream.StreamConsumerStateStore.java
/** * Encodes list of {@link StreamFileOffset} into bytes. *///from ww w .j av a 2s . c om private byte[] encodeOffsets(Iterable<StreamFileOffset> offsets) throws IOException { // Assumption: Each offset encoded into ~40 bytes and there are 8 offsets (number of live files) ByteArrayDataOutput output = ByteStreams.newDataOutput(320); encodeOffsets(offsets, output); return output.toByteArray(); }
From source file:garmintools.adapters.garmin.MetadataGarminAdapter.java
@Override public GarminOutput write(Proto.Metadata data) { ByteArrayDataOutput output = new LittleEndianByteArrayDataOutput(ByteStreams.newDataOutput()); writePreamble(output);// ww w . j a v a 2 s.c o m writeMetadata(data, output); return new GarminOutput(output.toByteArray()); }