List of usage examples for com.google.common.io ByteArrayDataOutput toByteArray
byte[] toByteArray();
From source file:de.bl4ckskull666.afkbukkit.AFKBukkit.java
public void sendPluginMessage(Player p) { if ((_lastFire.containsKey(p.getUniqueId()) && ((System.currentTimeMillis() - _lastFire.get(p.getUniqueId())) / 1000) < 30) && !_isAFK.contains(p.getUniqueId())) return;/*from w w w.j av a 2 s . c om*/ _lastFire.put(p.getUniqueId(), System.currentTimeMillis()); ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("AFKB"); out.writeUTF("Player"); out.writeUTF(p.getUniqueId().toString()); ByteArrayDataInput in = ByteStreams.newDataInput(out.toByteArray()); debugMe("Send PluginMessage with " + in.readLine()); p.sendPluginMessage(this, "BungeeCord", out.toByteArray()); }
From source file:garmintools.adapters.garmin.LandingFacilityDetailGarminAdapter.java
private void encode(LandingFacilityDetail detail, ByteArrayDataOutput output) { BitSet sectionsPresent = new BitSet(16); List<ByteArrayDataOutput> sections = new ArrayList<>(); if (!detail.runways.isEmpty()) { sectionsPresent.set(0);/*from ww w . j av a 2 s. co m*/ ByteArrayDataOutput sectionOutput = new LittleEndianByteArrayDataOutput(ByteStreams.newDataOutput()); sections.add(sectionOutput); encodeRunwayInfo(detail.runways, sectionOutput); } if (!detail.communicationFrequencies.isEmpty()) { sectionsPresent.set(1); ByteArrayDataOutput sectionOutput = new LittleEndianByteArrayDataOutput(ByteStreams.newDataOutput()); sections.add(sectionOutput); encodeCommunicationInfo(detail.communicationFrequencies, sectionOutput); } // Temporary; pass through unknown sections. for (UnknownLandingFacilityDetailSection unknownSection : detail.protoLandingFacilityDetail .getUnknownSectionList()) { sectionsPresent.set(unknownSection.getSectionNumber()); ByteArrayDataOutput sectionOutput = ByteStreams.newDataOutput(); sectionOutput.write(unknownSection.getData().toByteArray()); sections.add(sectionOutput); } output.writeShort(sectionsPresent.length() == 0 ? 0 : (short) sectionsPresent.toLongArray()[0]); // write lengths. for (ByteArrayDataOutput section : sections) { int sectionLength = section.toByteArray().length; output.writeShort(sectionLength); } // write contents. for (ByteArrayDataOutput section : sections) { output.write(section.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 message the message which get send *//*from w w w.ja va2s . c o m*/ public void executeBroadcast(Player whoExecuteIt, String message) { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF("broadcast"); stream.writeUTF(message); whoExecuteIt.sendPluginMessage(this.thePlugin, "BungeeCord", stream.toByteArray()); }
From source file:com.gmail.tracebachi.DeltaEssentials.Listeners.PlayerDataIOListener.java
public void onPlayerSaveSuccess(String name, String destServer) { PlayerPostSaveEvent savedEvent = new PlayerPostSaveEvent(name); Bukkit.getPluginManager().callEvent(savedEvent); Player player = Bukkit.getPlayerExact(name); if (player == null) { return;/*from w w w. ja va 2 s . co m*/ } if (destServer == null) { return; } ByteArrayDataOutput output = ByteStreams.newDataOutput(); output.writeUTF("Connect"); output.writeUTF(destServer); player.sendPluginMessage(plugin, "BungeeCord", output.toByteArray()); plugin.getPlayerLockManager().add(name, System.currentTimeMillis() + 15000); // TODO Make configurable time }
From source file:com.indeed.lsmtree.recordcache.MemcachedCache.java
MemcachedCache(final MemcachedClient memcache, final InetSocketAddress address, final String prefix, final Stringifier<K> keyStringifier, final Serializer<V> valueSerializer) throws IOException { this.memcache = memcache; this.prefix = prefix; this.keyStringifier = keyStringifier; this.host = address; valueTranscoder = new Transcoder<V>() { @Override/*w w w . java2 s .com*/ public boolean asyncDecode(CachedData cachedData) { return false; } @Override public CachedData encode(V v) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); try { valueSerializer.write(v, out); return identityTranscoder.encode(out.toByteArray()); } catch (IOException e) { throw new RuntimeException(e); } } @Override public V decode(CachedData cachedData) { byte[] bytes = identityTranscoder.decode(cachedData); ByteArrayDataInput in = ByteStreams.newDataInput(bytes); try { return valueSerializer.read(in); } catch (IOException e) { throw new RuntimeException(e); } } @Override public int getMaxSize() { return Integer.MAX_VALUE; } }; final Thread addFutureChecker = new Thread(new FutureQueueChecker(run, addFutureQueue, "memcached add failed, key already exists in cache", Level.INFO), "addFutureChecker"); addFutureChecker.setDaemon(true); addFutureChecker.start(); final Thread setFutureChecker = new Thread(new FutureQueueChecker(run, setFutureQueue, "memcached set failed, this should never happen", Level.ERROR), "setFutureChecker"); setFutureChecker.setDaemon(true); setFutureChecker.start(); }
From source file:info.mallmc.framework.commands.admincommands.SetCurrencyCommand.java
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender instanceof Player) { Player p = (Player) sender;/*w ww.ja v a2 s. c om*/ if (MallPlayer.getPlayer(p.getName()).getPermissions().getPower() != PermissionSet.ALL.getPower()) { Messaging.sendMessage(p, "global.command.notallowed"); return false; } } if (args.length == 0 || args.length < 2) { Messaging.sendMessage(sender, "global.command.incorrectusage", "/setcurrency <player> <rank>"); return false; } if (MallPlayer.getPlayer(args[0]) != null) { MallPlayer mp = MallPlayer.getPlayer(args[0]); ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("currencyset"); out.writeUTF(args[0]); out.writeInt(Integer.parseInt(args[1])); // If you don't care about the player // Player player = Iterables.getFirst(Bukkit.getOnlinePlayers(), null); // Else, specify them Bukkit.getPlayer(args[0]).sendPluginMessage(Framework.getInstance(), "BungeeCord", out.toByteArray()); return true; } return false; }
From source file:cpw.mods.fml.common.network.ModIdentifiersPacket.java
@Override public byte[] generatePacket(Object... data) { ByteArrayDataOutput dat = ByteStreams.newDataOutput(); Collection<NetworkModHandler> networkMods = FMLNetworkHandler.instance().getNetworkIdMap().values(); dat.writeInt(networkMods.size());// www . j a v a 2 s. co m for (NetworkModHandler handler : networkMods) { dat.writeUTF(handler.getContainer().getModId()); dat.writeInt(handler.getNetworkId()); } // TODO send the other id maps as well return dat.toByteArray(); }
From source file:codecrafter47.bungeetablistplus.managers.RedisPlayerManager.java
public <T> void request(UUID uuid, DataKey<T> key) { try {// w w w . jav a 2s . com ByteArrayDataOutput data = ByteStreams.newDataOutput(); DataStreamUtils.writeUUID(data, uuid); DataStreamUtils.writeDataKey(data, key); RedisBungee.getApi().sendChannelMessage(CHANNEL_DATA_REQUEST, Base64.getEncoder().encodeToString(data.toByteArray())); } catch (RuntimeException ex) { BungeeTabListPlus.getInstance().getLogger().log(Level.WARNING, "RedisBungee Error", ex); } catch (Throwable th) { BungeeTabListPlus.getInstance().getLogger().log(Level.SEVERE, "Failed to request data", th); } }
From source file:com.netease.flume.taildirSource.TailFile.java
private String readLine() throws IOException { ByteArrayDataOutput out = ByteStreams.newDataOutput(300); int i = 0;/* w ww . j ava 2 s . c o m*/ int c; while ((c = raf.read()) != -1) { i++; out.write((byte) c); if (c == LINE_SEP.charAt(0)) { break; } } if (i == 0) { return null; } return new String(out.toByteArray(), Charsets.UTF_8); }
From source file:io.github.apfelcreme.GuildsBungee.GuildsBungee.java
/** * notifies servers about a login or a logout * * @param uuid the player/* w w w . ja va 2s . c o m*/ * @param isOnline the status */ public void sendPlayerStatusChange(UUID uuid, boolean isOnline) { for (ServerInfo serverInfo : ProxyServer.getInstance().getServers().values()) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF(isOnline ? "joined" : "disconnected"); out.writeUTF(uuid.toString()); serverInfo.sendData("guilds:player", out.toByteArray()); } }