Example usage for com.google.common.io ByteArrayDataOutput writeLong

List of usage examples for com.google.common.io ByteArrayDataOutput writeLong

Introduction

In this page you can find the example usage for com.google.common.io ByteArrayDataOutput writeLong.

Prototype

@Override
    void writeLong(long v);

Source Link

Usage

From source file:org.apache.hadoop.hbase.client.Mutation.java

/**
 * Marks that the clusters with the given clusterIds have consumed the mutation
 * @param clusterIds of the clusters that have consumed the mutation
 *//*from www . j a  v a2s  .c om*/
public void setClusterIds(List<UUID> clusterIds) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeInt(clusterIds.size());
    for (UUID clusterId : clusterIds) {
        out.writeLong(clusterId.getMostSignificantBits());
        out.writeLong(clusterId.getLeastSignificantBits());
    }
    setAttribute(CONSUMED_CLUSTER_IDS, out.toByteArray());
}

From source file:co.cask.cdap.data2.transaction.stream.AbstractStreamFileConsumer.java

/**
 * Try to claim a stream event offset./*ww w .  j  a  v a2  s.c  o m*/
 *
 * @return The row key for writing to the state table if successfully claimed or {@code null} if not claimed.
 */
private byte[] claimEntry(StreamFileOffset offset, byte[] claimedStateContent) throws IOException {
    ByteArrayDataOutput out = ByteStreams.newDataOutput(50);
    out.writeLong(consumerConfig.getGroupId());
    StreamUtils.encodeOffset(out, offset);
    byte[] row = out.toByteArray();

    SortedMap<byte[], byte[]> rowStates = getInitRowStates(row);

    // See if the entry should be ignored. If it is in the rowStates with null value, then it should be ignored.
    byte[] rowState = rowStates.get(row);
    if (rowStates.containsKey(row) && rowState == null) {
        return null;
    }

    // Only need to claim entry if FIFO and group size > 1
    if (consumerConfig.getDequeueStrategy() == DequeueStrategy.FIFO && consumerConfig.getGroupSize() > 1) {
        return claimFifoEntry(row, claimedStateContent, rowState) ? row : null;
    }

    // For Hash, RR and FIFO with group size == 1, no need to claim and check,
    // as it's already handled by the readFilter
    return row;
}

From source file:de.nx42.maps4cim.header.CustomHeader.java

@Override
public byte[] generateHeader() throws IOException {

    // first part
    ByteArrayDataOutput outP1 = ByteStreams.newDataOutput(4096);

    // static intro
    outP1.write(intro);/*from  w w  w  .  j  a  va 2 s.co m*/
    outP1.write(formatHeaderString(staticString01));
    // gap of 4 bytes
    outP1.write(new byte[4]);

    // dates and timestamps
    outP1.writeLong(DateUtils.dateToTicks(unusedDate1));
    outP1.writeLong(DateUtils.dateToTicks(unusedDate2));
    outP1.writeLong(DateUtils.dateToTicks(lastSaved));
    outP1.writeLong(DateUtils.dateToTicks(mapCreated));
    outP1.writeLong(workTime1);
    outP1.writeLong(workTime2);

    // static data
    outP1.write(staticBinary01);
    outP1.write(formatHeaderString(staticString02));

    // map name
    outP1.write(formatHeaderString(mapName));
    if (buildingSet == BuildingSet.EUROPEAN) {
        outP1.write(formatHeaderString(staticString02eur01));
    }

    // map overview image
    outP1.write(pngLength);
    outP1.write(png);

    // static data
    outP1.write(staticBinary02);
    if (buildingSet == BuildingSet.EUROPEAN) {
        outP1.write(formatHeaderString(staticString02eur02));
        outP1.write(staticBinary02eur);
    }
    outP1.write(formatHeaderString(staticString03));
    outP1.write(new byte[34]);
    outP1.write(staticBinary03);
    outP1.write(formatHeaderString(staticString04));
    outP1.write(formatHeaderString(staticString05));

    // second part
    ByteArrayDataOutput outP2 = ByteStreams.newDataOutput(256);

    // static data
    outP2.write(intro);
    outP2.write(formatHeaderString(staticString06));
    outP2.write(staticBinary04);
    for (String s : staticStrings07) {
        outP2.write(formatHeaderString(s));
    }
    outP2.write(staticBinary05);

    // combine the parts
    ByteArrayDataOutput out = ByteStreams.newDataOutput(4352);

    byte[] p1 = outP1.toByteArray();
    out.write(p1);
    // fill with 0s until next next free index % 4096 = 0
    out.write(new byte[((p1.length / 4096) + 1) * 4096 - p1.length]);

    byte[] p2 = outP2.toByteArray();
    out.write(p2);
    // fill with 0s until 256 bytes are filled after the beginning of p2
    out.write(new byte[256 - p2.length]);

    // return combined result
    return out.toByteArray();
}

From source file:net.portalblock.rbbridge.MessageChannelListener.java

@EventHandler
public void onPluginMessage(final PluginMessageEvent event) {
    if (event.getTag().equals("RedisBungee") && event.getSender() instanceof Server) {
        final byte[] data = Arrays.copyOf(event.getData(), event.getData().length);
        plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
            @Override/*w w  w .j  a v  a  2  s  .  c  o  m*/
            public void run() {
                ByteArrayDataInput in = ByteStreams.newDataInput(data);

                String subchannel = in.readUTF();
                ByteArrayDataOutput out = ByteStreams.newDataOutput();
                String type;

                switch (subchannel) {
                case "PlayerList":
                    out.writeUTF("PlayerList");
                    Set<UUID> original = Collections.emptySet();
                    type = in.readUTF();
                    if (type.equals("ALL")) {
                        out.writeUTF("ALL");
                        original = RedisBungee.getApi().getPlayersOnline();
                    } else {
                        try {
                            original = RedisBungee.getApi().getPlayersOnServer(type);
                        } catch (IllegalArgumentException ignored) {
                        }
                    }
                    Set<String> players = new HashSet<String>();
                    for (UUID uuid : original)
                        players.add(RedisBungee.getApi().getNameFromUuid(uuid, false));
                    out.writeUTF(Joiner.on(',').join(players));
                    break;
                case "PlayerCount":
                    out.writeUTF("PlayerCount");
                    type = in.readUTF();
                    if (type.equals("ALL")) {
                        out.writeUTF("ALL");
                        out.writeInt(RedisBungee.getApi().getPlayerCount());
                    } else {
                        out.writeUTF(type);
                        try {
                            out.writeInt(RedisBungee.getApi().getPlayersOnServer(type).size());
                        } catch (IllegalArgumentException e) {
                            out.writeInt(0);
                        }
                    }
                    break;
                case "LastOnline":
                    String user = in.readUTF();
                    out.writeUTF("LastOnline");
                    out.writeUTF(user);
                    out.writeLong(RedisBungee.getApi()
                            .getLastOnline(RedisBungee.getApi().getUuidFromName(user, true)));
                    break;
                default:
                    break;
                }

                ((Server) event.getSender()).sendData("RedisBungee", out.toByteArray());
            }
        });
    }
}