List of usage examples for com.google.common.io ByteArrayDataOutput toByteArray
byte[] toByteArray();
From source file:cpw.mods.fml.common.network.ModListResponsePacket.java
@Override public byte[] generatePacket(Object... data) { Map<String, String> modVersions = (Map<String, String>) data[0]; List<String> missingMods = (List<String>) data[1]; ByteArrayDataOutput dat = ByteStreams.newDataOutput(); dat.writeInt(modVersions.size());// w w w. j a v a 2s . c om for (Entry<String, String> version : modVersions.entrySet()) { dat.writeUTF(version.getKey()); dat.writeUTF(version.getValue()); } dat.writeInt(missingMods.size()); for (String missing : missingMods) { dat.writeUTF(missing); } return dat.toByteArray(); }
From source file:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java
/** * Executer a global broadcast with a permission who recieve it over the network. * this can be used to broadcast global things with a plugin * * @param whoExecuteIt the player who send the plugin message * @param permission the needed permission to recieve the message * @param message the message which get send *///from w ww . j a va 2 s . c o m public void executeBroadcast(Player whoExecuteIt, String permission, String message) { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF("broadcast"); stream.writeUTF("Permission:" + permission); stream.writeUTF(message); whoExecuteIt.sendPluginMessage(this.thePlugin, "BungeeCord", stream.toByteArray()); }
From source file:tk.playerforcehd.networklib.bungee.connection.NetworkManager.java
/** * Send a plugin message to all servers in the network * * @param subchannel the subchannel or "command" * @param messages the messages of the plugin message * @throws Exception should not get thrown *//*ww w .j a v a 2 s .c o m*/ public void broadcastPluginMessage(String subchannel, String... messages) throws Exception { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF(subchannel); for (String write : messages) { stream.writeUTF(write); } Collection<ServerInfo> servers = this.thePlugin.getProxy().getServers().values(); for (ServerInfo currentServer : servers) { currentServer.sendData(this.channel, stream.toByteArray()); } }
From source file:org.apache.hadoop.hive.llap.daemon.impl.LlapProtocolServerImpl.java
@Override public GetTokenResponseProto getDelegationToken(RpcController controller, GetTokenRequestProto request) throws ServiceException { if (secretManager == null) { throw new ServiceException("Operation not supported on unsecure cluster"); }/*from w w w . jav a 2s . co m*/ UserGroupInformation callingUser = null; Token<LlapTokenIdentifier> token = null; try { callingUser = UserGroupInformation.getCurrentUser(); // Determine if the user would need to sign fragments. boolean isSigningRequired = determineIfSigningIsRequired(callingUser); token = secretManager.createLlapToken(request.hasAppId() ? request.getAppId() : null, null, isSigningRequired); } catch (IOException e) { throw new ServiceException(e); } if (isRestrictedToClusterUser && !clusterUser.equals(callingUser.getShortUserName())) { throw new ServiceException("Management protocol ACL is too permissive. The access has been" + " automatically restricted to " + clusterUser + "; " + callingUser.getShortUserName() + " is denied acccess. Please set " + ConfVars.LLAP_VALIDATE_ACLS.varname + " to false," + " or adjust " + ConfVars.LLAP_MANAGEMENT_ACL.varname + " and " + ConfVars.LLAP_MANAGEMENT_ACL_DENY.varname + " to a more restrictive ACL."); } ByteArrayDataOutput out = ByteStreams.newDataOutput(); try { token.write(out); } catch (IOException e) { throw new ServiceException(e); } ByteString bs = ByteString.copyFrom(out.toByteArray()); GetTokenResponseProto response = GetTokenResponseProto.newBuilder().setToken(bs).build(); return response; }
From source file:io.github.apfelcreme.GuildsBungee.GuildsBungee.java
/** * sends a player to its home/* w ww .j a va 2s.co m*/ * * @param uuid the player uuid * @param guild the guild * @param homeServer the ip of the server the home is on * @param source the server the message is coming from */ private void sendPlayerToGuildHome(UUID uuid, String guild, String homeServer, Server source) throws IOException { ServerInfo target = source.getInfo(); if (!source.getInfo().getAddress().toString().split("/")[1].equals(homeServer)) { ProxiedPlayer player = getProxy().getPlayer(uuid); if (player != null) { if (new InetSocketAddress(homeServer.split(":")[0], Integer.parseInt(homeServer.split(":")[1])) .getAddress().isReachable(2000)) { target = getTargetServer(homeServer); if (target != null) { player.connect(target); } else { getLogger().severe("Targetserver nicht gefunden!"); } } else { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("homeServerUnreachable"); out.writeUTF(uuid.toString()); source.sendData("guilds:error", out.toByteArray()); return; } } } ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("home"); out.writeUTF(uuid.toString()); out.writeUTF(guild); if (target != null) { target.sendData("guilds:player", out.toByteArray()); } }
From source file:pw.simplyintricate.bitcoin.models.datastructures.NetworkAddress.java
public byte[] toByteArray() { ByteArrayDataOutput writer = ByteStreams.newDataOutput(); //writer.writeInt(EndianUtils.swapInteger(time)); writer.writeLong(EndianUtils.swapLong(services.longValue())); // write the two ipv4 to ipv6 pads for (int i = 0; i < 10; i++) { writer.writeByte(0);/*from w ww . ja v a 2 s. c o m*/ } writer.writeByte(0xFF); writer.writeByte(0xFF); writer.write(ipAddress); writer.writeShort(port); return writer.toByteArray(); }
From source file:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java
/** * Execute a command on the proxy//from www .j av a 2 s . c o m * * @param command the command which get runned */ public void executeCommand_Proxy(String command) { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF("executeCommand"); stream.writeUTF("bungee"); stream.writeUTF(command); Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(this.thePlugin, "BungeeCord", stream.toByteArray()); }
From source file:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java
/** * Let's a player execute a command on his current server * * @param command the command which get executes * @param player the player who executes it */// w ww .j a v a 2 s . co m public void executeCommand_Player(String command, Player player) { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF("executeCommand"); stream.writeUTF(player.getName()); stream.writeUTF(command); Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(this.thePlugin, "BungeeCord", stream.toByteArray()); }
From source file:garmintools.adapters.garmin.LandingFacilityDetailGarminAdapter.java
@Override public GarminOutput write(List<LandingFacilityDetail> landingFacilityDetails) { ImmutableMap.Builder<Integer, Integer> indexToOffset = ImmutableMap.builder(); ByteArrayDataOutput output = new LittleEndianByteArrayDataOutput(ByteStreams.newDataOutput()); for (int index = 0; index < landingFacilityDetails.size(); ++index) { int offset = output.toByteArray().length; indexToOffset.put(index, offset); // System.err.printf("Encoding detail offset %06d %06x (%06x)\n", offset, offset, 0x14ea0f + offset); encode(landingFacilityDetails.get(index), output); }/*from w w w.j a v a2s .c o m*/ return new GarminOutputAndIndexToOffset(output.toByteArray(), indexToOffset.build()); }
From source file:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java
/** * Execute a command in the console of a speciefied server * * @param command the command which get executed * @param serverName the name of the server the the command get executed *//*from w ww . j a v a 2 s . c om*/ public void executeCommand_Server(String command, String serverName) { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF("executeCommand"); stream.writeUTF("server_" + serverName); stream.writeUTF(command); Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(this.thePlugin, "BungeeCord", stream.toByteArray()); }