com.google.common.io.ByteArrayDataOutput Java Examples

The following examples show how to use com.google.common.io.ByteArrayDataOutput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisPlayerManager.java    From BungeeTabListPlus with GNU General Public License v3.0 6 votes vote down vote up
private <T> void updateData(UUID uuid, DataKey<T> key, T value) {
    try {
        ByteArrayDataOutput data = ByteStreams.newDataOutput();
        DataStreamUtils.writeUUID(data, uuid);
        DataStreamUtils.writeDataKey(data, key);
        data.writeBoolean(value == null);
        if (value != null) {
            typeRegistry.getTypeAdapter(key.getType()).write(data, value);
        }
        RedisBungee.getApi().sendChannelMessage(CHANNEL_DATA_UPDATE, 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 send data", th);
    }
}
 
Example #2
Source File: TestMemoryFlamdex.java    From imhotep with Apache License 2.0 6 votes vote down vote up
@Test
public void testDocWithRepeatingTerms() throws IOException {
    MemoryFlamdex fdx = new MemoryFlamdex();
    FlamdexDocument doc = new FlamdexDocument();
    doc.setIntField("if1", new long[]{1, 1, 1, 3, 3});
    fdx.addDocument(doc);
    doc.setIntField("if1", new long[]{1, 2, 2, 2, 4});
    fdx.addDocument(doc);
    fdx.close();

    innerTestBadDoc(fdx);

    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    fdx.write(out);
    MemoryFlamdex fdx2 = new MemoryFlamdex();
    fdx2.readFields(ByteStreams.newDataInput(out.toByteArray()));

    innerTestBadDoc(fdx2);
}
 
Example #3
Source File: MobSelector.java    From CloudNet with Apache License 2.0 6 votes vote down vote up
@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 (ItemStackBuilder.getMaterialIgnoreVersion(mobConfig.getItemLayout().getItemName(),
                                                      mobConfig.getItemLayout().getItemId()) == e.getCurrentItem().getType()) {
            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());
            }
        }
    }
}
 
Example #4
Source File: BinarySerializationUtils.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
static byte[] serializeBinary(TagContext tags) throws TagContextSerializationException {
  // Use a ByteArrayDataOutput to avoid needing to handle IOExceptions.
  final ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput();
  byteArrayDataOutput.write(VERSION_ID);
  int totalChars = 0; // Here chars are equivalent to bytes, since we're using ascii chars.
  for (Iterator<Tag> i = InternalUtils.getTags(tags); i.hasNext(); ) {
    Tag tag = i.next();
    if (TagTtl.NO_PROPAGATION.equals(tag.getTagMetadata().getTagTtl())) {
      continue;
    }
    totalChars += tag.getKey().getName().length();
    totalChars += tag.getValue().asString().length();
    encodeTag(tag, byteArrayDataOutput);
  }
  if (totalChars > TAGCONTEXT_SERIALIZED_SIZE_LIMIT) {
    throw new TagContextSerializationException(
        "Size of TagContext exceeds the maximum serialized size "
            + TAGCONTEXT_SERIALIZED_SIZE_LIMIT);
  }
  return byteArrayDataOutput.toByteArray();
}
 
Example #5
Source File: ResourceString.java    From android-chunk-utils with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #6
Source File: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onJoin(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    final Game game = Main.getApi().getFirstWaitingGame();

    if (game != null) {
        game.joinToGame(event.getPlayer());
    } else if (!player.hasPermission("misat11.bw.admin")) {
        ByteArrayDataOutput out = ByteStreams.newDataOutput();

        out.writeUTF("Connect");
        out.writeUTF(Main.getApi().getHubServerName());

        player.sendPluginMessage(Main.getInstance(), "BungeeCord", out.toByteArray());
    }
}
 
Example #7
Source File: SkyWarsReloaded.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public void sendSWRMessage(Player player, String server, ArrayList<String> messages) {
	ByteArrayDataOutput out = ByteStreams.newDataOutput();
	out.writeUTF("Forward"); 
	out.writeUTF(server);
	out.writeUTF("SWRMessaging");

	ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
	DataOutputStream msgout = new DataOutputStream(msgbytes);
	try {
		for (String msg: messages) {
			msgout.writeUTF(msg);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}

	out.writeShort(msgbytes.toByteArray().length);
	out.write(msgbytes.toByteArray());
	player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
}
 
Example #8
Source File: LobbyCommand.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void execute(CommandSender commandSender, String[] strings) {
    ServerInfo serverInfo = this.getLobby();
    if (serverInfo != null && commandSender instanceof ProxiedPlayer) {
        ProxiedPlayer player = (ProxiedPlayer) commandSender;
        if (!player.getServer().getInfo().getName().equals(serverInfo.getName())) {
            player.connect(getLobby());
        } else {
            ByteArrayDataOutput out = ByteStreams.newDataOutput();
            out.writeUTF("HubBasics");
            out.writeUTF("Lobby");
            player.sendData("BungeeCord", out.toByteArray());
        }
    } else if (serverInfo == null) {
        commandSender.sendMessage(new TextComponent(Messages.get(commandSender, "LOBBY_NOT_DEFINED")));
    } else {
        commandSender.sendMessage(new TextComponent(Messages.get(commandSender, "COMMAND_PLAYER")));
    }
}
 
Example #9
Source File: Reporter.java    From RoaringBitmap with Apache License 2.0 6 votes vote down vote up
public static synchronized void report(String testName, Map<String, Object> context, Throwable error, ImmutableBitmapDataProvider... bitmaps) {
  try {
    Map<String, Object> output = new LinkedHashMap<>();
    output.put("testName", testName);
    output.put("error", getStackTrace(error));
    output.putAll(context);
    String[] base64 = new String[bitmaps.length];
    for (int i = 0; i < bitmaps.length; ++i) {
      ByteArrayDataOutput serialised = ByteStreams.newDataOutput(bitmaps[i].serializedSizeInBytes());
      bitmaps[i].serialize(serialised);
      base64[i] = Base64.getEncoder().encodeToString(serialised.toByteArray());
    }
    output.put("bitmaps", base64);
    Path dir = Paths.get(OUTPUT_DIR);
    if (!Files.exists(dir)) {
      Files.createDirectory(dir);
    }
    Files.write(dir.resolve(testName + "-" + UUID.randomUUID() + ".json"), MAPPER.writeValueAsBytes(output));
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
Example #10
Source File: ProtoBufConverter.java    From eagle with Apache License 2.0 5 votes vote down vote up
public static AggregateProtos.AggregateResult toPBAggregateResult(AggregateResult result) throws IOException {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    result.write(output);
    return AggregateProtos.AggregateResult.newBuilder()
            .setByteArray(ByteString.copyFrom(output.toByteArray()))
            .build();
}
 
Example #11
Source File: RedisCommandParser.java    From redis-mock with MIT License 5 votes vote down vote up
@VisibleForTesting
Slice consumeSlice(long len) throws ParseErrorException {
    ByteArrayDataOutput bo = ByteStreams.newDataOutput();
    for (long i = 0; i < len; i++) {
        try {
            bo.write(consumeByte());
        } catch (EOFException e) {
            throw new ParseErrorException();
        }
    }
    return new Slice(bo.toByteArray());
}
 
Example #12
Source File: RawAuthenticationService.java    From oxAuth with MIT License 5 votes vote down vote up
private byte[] packBytesToSign(byte[] appIdHash, byte userPresence, long counter, byte[] challengeHash) {
	ByteArrayDataOutput encoded = ByteStreams.newDataOutput();
	encoded.write(appIdHash);
	encoded.write(userPresence);
	encoded.writeInt((int) counter);
	encoded.write(challengeHash);

	return encoded.toByteArray();
}
 
Example #13
Source File: RedisBungeeListener.java    From RedisBungee with Eclipse Public License 1.0 5 votes vote down vote up
private void serializeMultiset(Multiset<String> collection, ByteArrayDataOutput output) {
    output.writeInt(collection.elementSet().size());
    for (Multiset.Entry<String> entry : collection.entrySet()) {
        output.writeUTF(entry.getElement());
        output.writeInt(entry.getCount());
    }
}
 
Example #14
Source File: TagContextDeserializationTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserializeDuplicateTags() throws TagContextDeserializationException {
  ByteArrayDataOutput output = ByteStreams.newDataOutput();
  output.write(BinarySerializationUtils.VERSION_ID);
  encodeTagToOutput("Key1", "Value1", output);
  encodeTagToOutput("Key1", "Value1", output);
  TagContext expected =
      tagger.emptyBuilder().put(TagKey.create("Key1"), TagValue.create("Value1")).build();
  assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected);
}
 
Example #15
Source File: TagContextDeserializationTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserializeOneTag() throws TagContextDeserializationException {
  ByteArrayDataOutput output = ByteStreams.newDataOutput();
  output.write(BinarySerializationUtils.VERSION_ID);
  encodeTagToOutput("Key", "Value", output);
  TagContext expected =
      tagger.emptyBuilder().put(TagKey.create("Key"), TagValue.create("Value")).build();
  assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(expected);
}
 
Example #16
Source File: ResourceFile.java    From android-arscblamer with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] toByteArray(int options) throws IOException {
  ByteArrayDataOutput output = ByteStreams.newDataOutput();
  for (Chunk chunk : chunks) {
    output.write(chunk.toByteArray(options));
  }
  return output.toByteArray();
}
 
Example #17
Source File: BungeeCordVariables.java    From ScoreboardStats with MIT License 5 votes vote down vote up
@Override
public void run() {
    Player sender = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
    if (sender != null) {
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("PlayerCount");
        out.writeUTF("ALL");

        sender.sendPluginMessage(plugin, BUNGEE_CHANNEL, out.toByteArray());
    }
}
 
Example #18
Source File: BungeeBridge.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
public void sendAlertForBroadcast(String msg) {
    if(!enabled)
        return;
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF("HawkACAlert");
    out.writeUTF(msg);
    Bukkit.getServer().sendPluginMessage(hawk, "BungeeCord", out.toByteArray());
}
 
Example #19
Source File: PacketBusFluidStorage.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void write(ByteArrayDataOutput out)
{
	out.writeInt(world.provider.dimensionId);
	out.writeInt(x);
	out.writeInt(y);
	out.writeInt(z);
	out.writeInt(priority);
}
 
Example #20
Source File: TagContextDeserializationTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserializeInvalidTagValue() throws TagContextDeserializationException {
  ByteArrayDataOutput output = ByteStreams.newDataOutput();
  output.write(BinarySerializationUtils.VERSION_ID);

  // Encode a valid tag key and an invalid tag value:
  encodeTagToOutput("my key", "val\3", output);
  final byte[] bytes = output.toByteArray();

  thrown.expect(TagContextDeserializationException.class);
  thrown.expectMessage("Invalid tag value for key TagKey{name=my key}: val\3");
  serializer.fromByteArray(bytes);
}
 
Example #21
Source File: RowValueFilter.java    From Eagle with Apache License 2.0 5 votes vote down vote up
/**
 * TODO: Currently still use older serialization method from hbase-0.94, need to migrate into ProtoBuff based
 *
 * @return
 * @throws IOException
 */
@Override
public byte[] toByteArray() throws IOException {
    ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput();
    this.comparator.write(byteArrayDataOutput);
    return byteArrayDataOutput.toByteArray();
}
 
Example #22
Source File: BungeeCordImpl.java    From helper with MIT License 5 votes vote down vote up
@Override
public void appendPayload(ByteArrayDataOutput out) {
    out.writeUTF(this.playerName);
    out.writeUTF(this.channelName);
    out.writeShort(this.data.length);
    out.write(this.data);
}
 
Example #23
Source File: TagContextDeserializationTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void stopParsingAtUnknownTagAtStart() throws TagContextDeserializationException {
  ByteArrayDataOutput output = ByteStreams.newDataOutput();
  output.write(BinarySerializationUtils.VERSION_ID);

  // Write unknown field ID 1.
  output.write(1);
  output.write(new byte[] {1, 2, 3, 4});

  encodeTagToOutput("Key", "Value", output);
  assertThat(serializer.fromByteArray(output.toByteArray())).isEqualTo(tagger.empty());
}
 
Example #24
Source File: PacketOutPosLook.java    From FishingBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void write(ByteArrayDataOutput out, int protocolId) throws IOException {
    out.writeDouble(getX());
    out.writeDouble(getY());
    out.writeDouble(getZ());
    out.writeFloat(getYaw());
    out.writeFloat(getPitch());
    out.writeBoolean(isOnGround());
}
 
Example #25
Source File: BungeeManager.java    From FastLogin with MIT License 5 votes vote down vote up
public void sendPluginMessage(PluginMessageRecipient player, ChannelMessage message) {
    if (player != null) {
        ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
        message.writeTo(dataOutput);

        NamespaceKey channel = new NamespaceKey(plugin.getName(), message.getChannelName());
        player.sendPluginMessage(plugin, channel.getCombinedName(), dataOutput.toByteArray());
    }
}
 
Example #26
Source File: SkyWarsReloaded.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public void sendBungeeMsg(Player player, String subchannel, String message) {
	ByteArrayDataOutput out = ByteStreams.newDataOutput();
	out.writeUTF(subchannel);
	if (!message.equalsIgnoreCase("none")) {
		out.writeUTF(message);
	}
	player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
}
 
Example #27
Source File: AttributeWriter.java    From turbine with Apache License 2.0 5 votes vote down vote up
private void writeTypeAnnotation(TypeAnnotations attribute) {
  output.writeShort(pool.utf8(attribute.kind().signature()));
  ByteArrayDataOutput tmp = ByteStreams.newDataOutput();
  tmp.writeShort(attribute.annotations().size());
  for (TypeAnnotationInfo annotation : attribute.annotations()) {
    new AnnotationWriter(pool, tmp).writeTypeAnnotation(annotation);
  }
  byte[] data = tmp.toByteArray();
  output.writeInt(data.length);
  output.write(data);
}
 
Example #28
Source File: PacketOutUseItem.java    From FishingBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void write(ByteArrayDataOutput out, int protocolId) {
    switch (protocolId) {
        case ProtocolConstants.MINECRAFT_1_8: {
            out.writeLong(-1);      //Position
            out.writeByte(255);     //Face
            out.write(FishingBot.getInstance().getPlayer().getSlotData().toByteArray());  //Slot
            out.writeByte(0);       //Cursor X
            out.writeByte(0);       //Cursor Y
            out.writeByte(0);       //Cursor Z
            new Thread(() -> {
                try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); }
                networkHandler.sendPacket(new PacketOutArmAnimation());
            }).start();
            break;
        }
        case ProtocolConstants.MINECRAFT_1_13_2:
        case ProtocolConstants.MINECRAFT_1_13_1:
        case ProtocolConstants.MINECRAFT_1_13:
        case ProtocolConstants.MINECRAFT_1_12_2:
        case ProtocolConstants.MINECRAFT_1_12_1:
        case ProtocolConstants.MINECRAFT_1_12:
        case ProtocolConstants.MINECRAFT_1_11_1:
        case ProtocolConstants.MINECRAFT_1_11:
        case ProtocolConstants.MINECRAFT_1_10:
        case ProtocolConstants.MINECRAFT_1_9_4:
        case ProtocolConstants.MINECRAFT_1_9_2:
        case ProtocolConstants.MINECRAFT_1_9_1:
        case ProtocolConstants.MINECRAFT_1_9:
        case ProtocolConstants.MINECRAFT_1_14:
        case ProtocolConstants.MINECRAFT_1_14_1:
        case ProtocolConstants.MINECRAFT_1_14_2:
        case ProtocolConstants.MINECRAFT_1_14_3:
        case ProtocolConstants.MINECRAFT_1_14_4:
        default: {
            out.writeByte(0);       //main hand
            break;
        }
    }
}
 
Example #29
Source File: TransactionEditTest.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private void assertSerializedEdit(TransactionEdit originalEdit) throws IOException {
  ByteArrayDataOutput out = ByteStreams.newDataOutput();
  originalEdit.write(out);

  TransactionEdit decodedEdit = new TransactionEdit();
  DataInput in = ByteStreams.newDataInput(out.toByteArray());
  decodedEdit.readFields(in);

  Assert.assertEquals(originalEdit, decodedEdit);
}
 
Example #30
Source File: MetricsDailySummaryReducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
public Value toValue() {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    try {
        write(out);
    } catch (IOException e) {
        // can't happen - it's a byte array stream
    }
    return new Value(out.toByteArray());
}