本文整理匯總了Java中com.google.common.io.ByteArrayDataOutput類的典型用法代碼示例。如果您正苦於以下問題:Java ByteArrayDataOutput類的具體用法?Java ByteArrayDataOutput怎麽用?Java ByteArrayDataOutput使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ByteArrayDataOutput類屬於com.google.common.io包,在下文中一共展示了ByteArrayDataOutput類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleInteract
import com.google.common.io.ByteArrayDataOutput; //導入依賴的package包/類
@EventHandler
public void handleInteract(PlayerInteractEvent e)
{
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && (e.getClickedBlock().getType().equals(Material.SIGN_POST) || e.getClickedBlock().getType().equals(Material.WALL_SIGN)))
{
if (containsPosition(e.getClickedBlock().getLocation()))
{
Sign sign = getSignByPosition(e.getClickedBlock().getLocation());
if (sign.getServerInfo() != null)
{
String s = sign.getServerInfo().getServiceId().getServerId();
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.writeUTF("Connect");
output.writeUTF(s);
e.getPlayer().sendPluginMessage(CloudServer.getInstance().getPlugin(), "BungeeCord", output.toByteArray());
}
}
}
}
示例2: handleInventoryClick
import com.google.common.io.ByteArrayDataOutput; //導入依賴的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());
}
}
}
}
示例3: encodeString
import com.google.common.io.ByteArrayDataOutput; //導入依賴的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: encodeLength
import com.google.common.io.ByteArrayDataOutput; //導入依賴的package包/類
private static void encodeLength(ByteArrayDataOutput output, int length, Type type) {
if (length < 0) {
output.write(0);
return;
}
if (type == Type.UTF8) {
if (length > 0x7F) {
output.write(((length & 0x7F00) >> 8) | 0x80);
}
output.write(length & 0xFF);
} else { // UTF-16
// TODO(acornwall): Replace output with a little-endian output.
if (length > 0x7FFF) {
int highBytes = ((length & 0x7FFF0000) >> 16) | 0x8000;
output.write(highBytes & 0xFF);
output.write((highBytes & 0xFF00) >> 8);
}
int lowBytes = length & 0xFFFF;
output.write(lowBytes & 0xFF);
output.write((lowBytes & 0xFF00) >> 8);
}
}
示例5: encodeString
import com.google.common.io.ByteArrayDataOutput; //導入依賴的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();
}
示例6: encodeLength
import com.google.common.io.ByteArrayDataOutput; //導入依賴的package包/類
private static void encodeLength(ByteArrayDataOutput output, int length, Type type) {
if (length < 0) {
output.write(0);
return;
}
if (type == Type.UTF8) {
if (length > 0x7F) {
output.write(((length & 0x7F00) >> 8) | 0x80);
}
output.write(length & 0xFF);
} else { // UTF-16
// TODO(acornwall): Replace output with a little-endian output.
if (length > 0x7FFF) {
int highBytes = ((length & 0x7FFF0000) >> 16) | 0x8000;
output.write(highBytes & 0xFF);
output.write((highBytes & 0xFF00) >> 8);
}
int lowBytes = length & 0xFFFF;
output.write(lowBytes & 0xFF);
output.write((lowBytes & 0xFF00) >> 8);
}
}
示例7: sendSignUpdateRequest
import com.google.common.io.ByteArrayDataOutput; //導入依賴的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();
}
}
示例8: readLine
import com.google.common.io.ByteArrayDataOutput; //導入依賴的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);
}
示例9: update
import com.google.common.io.ByteArrayDataOutput; //導入依賴的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();
}
}
示例10: sendVaultBalance
import com.google.common.io.ByteArrayDataOutput; //導入依賴的package包/類
public void sendVaultBalance(String playerName, double playerBalance)
{
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(ServerSync.vault.vaultSubchannel); //Vault Subchannel
out.writeUTF(ServerSync.vault.economySubchannel); //Vault Economy Subchannel
out.writeUTF("Balance"); //Operation
out.writeUTF(ServerSync.bungeeServerName); //Server Name
out.writeUTF(ServerSync.pluginVersion); //Client Version
out.writeUTF(playerName); //Player name
if (ServerSync.encryption.isEnabled())
{
out.writeUTF(ServerSync.encryption.encrypt(String.valueOf(playerBalance)));
}
else
{
out.writeUTF(Double.toString(playerBalance)+""); //Player balance
}
ServerSync.bungeeOutgoing.sendMessage(out, ServerSync.bungeePluginChannel);
if (ServerSync.verbose)
{
Log.info(ServerSync.consolePrefix + "Vault - Balance update sent for " + ChatColor.YELLOW + playerName + " for $" + playerBalance);
}
}
示例11: sendPlayerGroups
import com.google.common.io.ByteArrayDataOutput; //導入依賴的package包/類
protected void sendPlayerGroups(OfflinePlayer player, String world, String groups)
{
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(ServerSync.vault.vaultSubchannel);
out.writeUTF(ServerSync.vault.permissionSubchannel); //Vault Permission sub channel
out.writeUTF("PlayerGroups"); //Operation
out.writeUTF(ServerSync.bungeeServerName); //Server Name
out.writeUTF(ServerSync.pluginVersion); //Client Version
out.writeUTF(player.getUniqueId().toString()); //Player UUID
out.writeUTF(world); //World
out.writeUTF(groups); //Groups
ServerSync.bungeeOutgoing.sendMessage(out, ServerSync.bungeePluginChannel);
if (ServerSync.verbose)
{
Log.info(ServerSync.consolePrefix + "Vault - Permission group update sent for " + ChatColor.YELLOW + player.getName());
}
}
示例12: getData
import com.google.common.io.ByteArrayDataOutput; //導入依賴的package包/類
public byte[] getData() {
if (this.cache == null || this.dirty) {
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.write(toByteArray(blocks, pocketBlock -> (byte) pocketBlock.getId()));
output.write(data.getRaw());
output.write(lighting.getRaw());
output.write(skylight.getRaw());
output.write(height.getRaw());
for (int i = 0; i < this.biomes.length; ++i) {
byte r = this.biomeColors[i * 3];
byte g = this.biomeColors[i * 3 + 1];
byte b = this.biomeColors[i * 3 + 2];
int color = r << 16 | g << 8 | b;
output.writeInt(24 << this.biomes[i] | color & 0xffffff);
}
output.writeInt(0);
this.dirty = false;
this.cache = output.toByteArray();
}
return this.cache;
}
示例13: sendMessage
import com.google.common.io.ByteArrayDataOutput; //導入依賴的package包/類
@Override
protected void sendMessage(String message) {
new BukkitRunnable() {
@Override
public void run() {
Collection<? extends Player> players = BungeeMessagingService.this.plugin.getServer().getOnlinePlayers();
Player p = Iterables.getFirst(players, null);
if (p == null) {
return;
}
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(message);
byte[] data = out.toByteArray();
p.sendPluginMessage(BungeeMessagingService.this.plugin, CHANNEL, data);
cancel();
}
}.runTaskTimer(this.plugin, 1L, 100L);
}
示例14: writeClass
import com.google.common.io.ByteArrayDataOutput; //導入依賴的package包/類
/** Writes a {@link ClassFile} to bytecode. */
public static byte[] writeClass(ClassFile classfile) {
ConstantPool pool = new ConstantPool();
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.writeShort(classfile.access());
output.writeShort(pool.classInfo(classfile.name()));
output.writeShort(classfile.superName() != null ? pool.classInfo(classfile.superName()) : 0);
output.writeShort(classfile.interfaces().size());
for (String i : classfile.interfaces()) {
output.writeShort(pool.classInfo(i));
}
output.writeShort(classfile.fields().size());
for (ClassFile.FieldInfo f : classfile.fields()) {
writeField(pool, output, f);
}
output.writeShort(classfile.methods().size());
for (ClassFile.MethodInfo m : classfile.methods()) {
writeMethod(pool, output, m);
}
writeAttributes(pool, output, LowerAttributes.classAttributes(classfile));
return finishClass(pool, output);
}
示例15: manyManyConstants
import com.google.common.io.ByteArrayDataOutput; //導入依賴的package包/類
@Test
public void manyManyConstants() {
ConstantPool pool = new ConstantPool();
Map<Integer, String> entries = new LinkedHashMap<>();
int i = 0;
while (pool.nextEntry < 0xffff) {
String value = "c" + i++;
entries.put(pool.classInfo(value), value);
}
ByteArrayDataOutput bytes = ByteStreams.newDataOutput();
ClassWriter.writeConstantPool(pool, bytes);
ConstantPoolReader reader =
ConstantPoolReader.readConstantPool(new ByteReader(bytes.toByteArray(), 0));
for (Map.Entry<Integer, String> entry : entries.entrySet()) {
assertThat(reader.classInfo(entry.getKey())).isEqualTo(entry.getValue());
}
}