当前位置: 首页>>代码示例>>Java>>正文


Java ByteStreams.newDataOutput方法代码示例

本文整理汇总了Java中com.google.common.io.ByteStreams.newDataOutput方法的典型用法代码示例。如果您正苦于以下问题:Java ByteStreams.newDataOutput方法的具体用法?Java ByteStreams.newDataOutput怎么用?Java ByteStreams.newDataOutput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.ByteStreams的用法示例。


在下文中一共展示了ByteStreams.newDataOutput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleInventoryClick

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@EventHandler
public void handleInventoryClick(InventoryClickEvent e)
{
    if (!(e.getWhoClicked() instanceof Player)) return;

    if (inventories().contains(e.getInventory()) && e.getCurrentItem() != null && e.getSlot() == e.getRawSlot())
    {
        e.setCancelled(true);
        if (mobConfig.getItemLayout().getItemId() == e.getCurrentItem().getTypeId())
        {
            MobImpl mob = find(e.getInventory());
            if (mob.getServerPosition().containsKey(e.getSlot()))
            {
                if (CloudAPI.getInstance().getServerId().equalsIgnoreCase(mob.getServerPosition().get(e.getSlot()))) return;
                ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput();
                byteArrayDataOutput.writeUTF("Connect");
                byteArrayDataOutput.writeUTF(mob.getServerPosition().get(e.getSlot()));
                ((Player) e.getWhoClicked()).sendPluginMessage(CloudServer.getInstance().getPlugin(), "BungeeCord", byteArrayDataOutput.toByteArray());
            }
        }
    }
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:23,代码来源:MobSelector.java

示例2: update

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public void update() {
    Player player = Bukkit.getPlayer(playerData.getPlayerID());

    try {
        //Update SQL
        gameServiceManager.setPlayerSettings(playerData.getPlayerBean(), this);

        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        //Comamnd type
        out.writeUTF("settingsChanges");
        //The player to refresh settings on bungee
        out.writeUTF(player.getUniqueId().toString());
        //Send data on network channel
        player.sendPluginMessage(APIPlugin.getInstance(), "Network", out.toByteArray());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:SamaGames,项目名称:SamaGamesCore,代码行数:20,代码来源:ImpPlayerSettings.java

示例3: encodeString

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
/**
 * Encodes a string in either UTF-8 or UTF-16 and returns the bytes of the encoded string.
 * Strings are prefixed by 2 values. The first is the number of characters in the string.
 * The second is the encoding length (number of bytes in the string).
 *
 * <p>Here's an example UTF-8-encoded string of ab©:
 * <pre>03 04 61 62 C2 A9 00</pre>
 *
 * @param str The string to be encoded.
 * @param type The encoding type that the {@link ResourceString} should be encoded in.
 * @return The encoded string.
 */
public static byte[] encodeString(String str, Type type) {
  byte[] bytes = str.getBytes(type.charset());
  // The extra 5 bytes is for metadata (character count + byte count) and the NULL terminator.
  ByteArrayDataOutput output = ByteStreams.newDataOutput(bytes.length + 5);
  encodeLength(output, str.length(), type);
  if (type == Type.UTF8) {  // Only UTF-8 strings have the encoding length.
    encodeLength(output, bytes.length, type);
  }
  output.write(bytes);
  // NULL-terminate the string
  if (type == Type.UTF8) {
    output.write(0);
  } else {
    output.writeShort(0);
  }
  return output.toByteArray();
}
 
开发者ID:xyxyLiu,项目名称:AndResM,代码行数:30,代码来源:ResourceString.java

示例4: readLine

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
private String readLine() throws IOException {

        ByteArrayDataOutput out = ByteStreams.newDataOutput(300);
        int i = 0;
        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);
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:18,代码来源:TailFile.java

示例5: sendSignUpdateRequest

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
public static void sendSignUpdateRequest(Game game) {
	ByteArrayDataOutput out = ByteStreams.newDataOutput();
	String name = SkyWarsReloaded.getCfg().getBungeeServer();
	try {
		out.writeUTF("Forward");
		out.writeUTF("ALL");
		out.writeUTF("SkyWarsReloaded");

		ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
		DataOutputStream msgout = new DataOutputStream(msgbytes);
		msgout.writeUTF(name + ":" + game.getState().toString() + ":" + Integer.toString(game.getPlayers().size()) + ":" + Integer.toString(game.getNumberOfSpawns()) + ":" + game.getMapName());

		out.writeShort(msgbytes.toByteArray().length);
		out.write(msgbytes.toByteArray());

		Bukkit.getServer().sendPluginMessage(SkyWarsReloaded.get(), "BungeeCord", out.toByteArray());
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:smessie,项目名称:SkyWarsReloaded,代码行数:21,代码来源:BungeeUtil.java

示例6: sendToaRandomServerInGroup

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
public void sendToaRandomServerInGroup(Plugin plugin, Player player)
{
    plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "CloudNet");
    ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput();
    byteArrayDataOutput.writeUTF("Connect");
    byteArrayDataOutput.writeUTF("Lobby"); //Connect to the group Lobby
    player.sendPluginMessage(plugin, "CloudNet", byteArrayDataOutput.toByteArray());
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:9,代码来源:BungeeCordChannelExample.java

示例7: saveToCache

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public void saveToCache(OutputStream out) throws Exception {
    ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();

    DoubleArrayTrie.write(trie, dataOutput, this::writeItem);

    out.write(dataOutput.toByteArray());
}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:9,代码来源:CommonDictionary.java

示例8: create

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
public static CreateLocalHistoryPayload create(final LocalHistoryIdentifier historyId) {
    final ByteArrayDataOutput out = ByteStreams.newDataOutput();
    try {
        historyId.writeTo(out);
    } catch (IOException e) {
        // This should never happen
        LOG.error("Failed to serialize {}", historyId, e);
        throw new RuntimeException("Failed to serialize " + historyId, e);
    }
    return new CreateLocalHistoryPayload(historyId, out.toByteArray());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:12,代码来源:CreateLocalHistoryPayload.java

示例9: create

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
public static PurgeTransactionPayload create(final TransactionIdentifier transactionId) {
    final ByteArrayDataOutput out = ByteStreams.newDataOutput();
    try {
        transactionId.writeTo(out);
    } catch (IOException e) {
        // This should never happen
        LOG.error("Failed to serialize {}", transactionId, e);
        throw new RuntimeException("Failed to serialize " + transactionId, e);
    }
    return new PurgeTransactionPayload(transactionId, out.toByteArray());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:12,代码来源:PurgeTransactionPayload.java

示例10: toByteArray

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public byte[] toByteArray(boolean shrink) throws IOException {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    for (Chunk chunk : chunks) {
        output.write(chunk.toByteArray(shrink));
    }
    return output.toByteArray();
}
 
开发者ID:CalebFenton,项目名称:apkfile,代码行数:9,代码来源:ResourceFile.java

示例11: create

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
public static CloseLocalHistoryPayload create(final LocalHistoryIdentifier historyId) {
    final ByteArrayDataOutput out = ByteStreams.newDataOutput();
    try {
        historyId.writeTo(out);
    } catch (IOException e) {
        // This should never happen
        LOG.error("Failed to serialize {}", historyId, e);
        throw new RuntimeException("Failed to serialize " + historyId, e);
    }
    return new CloseLocalHistoryPayload(historyId, out.toByteArray());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:12,代码来源:CloseLocalHistoryPayload.java

示例12: saveToCache

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public void saveToCache(OutputStream out) throws Exception {
    ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();

    DoubleArrayTrie.write(dat, dataOutput, NatureAttribute::write);

    out.write(dataOutput.toByteArray());
}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:9,代码来源:CustomDictionary.java

示例13: onClick

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public void onClick(Player player, ItemStack stack, String action, ClickType clickType)
{
    if (action.startsWith("Hub_"))
    {
        if (action.split("_")[1].equals(SamaGamesAPI.get().getServerName().split("_")[1]))
        {
            player.sendMessage(ChatColor.RED + "Vous ne pouvez pas aller sur votre hub actuel !");
            return;
        }
        else if (this.hub.getHubRefresher().getHubByID(Integer.parseInt(action.split("_")[1])).getConnectedPlayers() >= 120)
        {
            player.sendMessage(ChatColor.RED + "Le hub sélectionné est plein !");
            return;
        }

        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Connect");
        out.writeUTF(action);
        player.sendPluginMessage(this.hub, "BungeeCord", out.toByteArray());

        // TODO: Use API
        // SamaGamesAPI.get().getPlayerManager().connectToServer(player.getUniqueId(), action);
    }
    else if (action.equals("page_back"))
    {
        this.hub.getGuiManager().openGui(player, new GuiSwitchHub(this.hub, (this.page - 1)));
    }
    else if (action.equals("page_next"))
    {
        this.hub.getGuiManager().openGui(player, new GuiSwitchHub(this.hub, (this.page + 1)));
    }
    else if (action.equals("back"))
    {
        this.hub.getGuiManager().openGui(player, new GuiMain(this.hub));
    }
}
 
开发者ID:SamaGames,项目名称:Hub,代码行数:38,代码来源:GuiSwitchHub.java

示例14: sendToServer

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
public void sendToServer(String server) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF("Connect");
    out.writeUTF(server);
    getPlayer().sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
    sendMessage(PAData.BUNGEE.getPrefix() + "&cConectando a &6" + server);
}
 
开发者ID:cadox8,项目名称:PA,代码行数:8,代码来源:PAUser.java

示例15: ping

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
void ping() {
    final Player player = this.getFirstPlayer();
    if (player == null)
        return;
    for (final String s : this.controller.getServers()) {
        final ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("ServerIP");
        out.writeUTF(s);
        player.sendPluginMessage(this.plugin, "BungeeCord", out.toByteArray());
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:12,代码来源:BungeeCordProvider.java


注:本文中的com.google.common.io.ByteStreams.newDataOutput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。