本文整理汇总了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());
}
}
}
}
示例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();
}
}
示例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();
}
示例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);
}
示例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();
}
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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();
}
示例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());
}
示例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());
}
示例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));
}
}
示例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);
}
示例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());
}
}