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

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

Introduction

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

Prototype

byte[] toByteArray();

Source Link

Document

Returns the contents that have been written to this instance, as a byte array.

Usage

From source file:com.jivesoftware.os.miru.bitmaps.roaring5.buffer.MiruBitmapsRoaringBuffer.java

public static void main(String[] args) throws Exception {

    /*for (int i = 0; i < 100; i++) {
            // ww w . jav a2  s.  c  om
    RoaringBitmap bitmap = new RoaringBitmap();
    Random r = new Random(1234);
    for (int j = 0; j < 1_000_000; j++) {
        if (r.nextBoolean()) {
            bitmap.add(j);
        }
    }
            
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    bitmap.serialize(out);
    byte[] bytes = out.toByteArray();
            
    long start = System.currentTimeMillis();
    int count = 0;
    for (int j = 0; j < 1_000; j++) {
        RoaringBitmap bmp = new RoaringBitmap();
        bmp.deserialize(ByteStreams.newDataInput(bytes));
        count++;
    }
    System.out.println("---- regular ----");
    System.out.println((System.currentTimeMillis() - start) + " ms, " + count + " iter");
            
    start = System.currentTimeMillis();
    for (int j = 0; j < 1_000; j++) {
        ImmutableRoaringBitmap buf = new ImmutableRoaringBitmap(ByteBuffer.wrap(bytes));
        count++;
    }
    System.out.println("---- buffers ----");
    System.out.println((System.currentTimeMillis() - start) + " ms, " + count + " iter");
    }*/
    for (int i = 0; i < 1000; i++) {

        RoaringBitmap bitmap1 = new RoaringBitmap();
        RoaringBitmap bitmap2 = new RoaringBitmap();
        Random r = new Random(1234);
        for (int j = 0; j < 1_000_000; j++) {
            if (r.nextBoolean()) {
                bitmap1.add(j);
            }
            if (r.nextBoolean()) {
                bitmap2.add(j);
            }
        }

        ByteArrayDataOutput out1 = ByteStreams.newDataOutput();
        ByteArrayDataOutput out2 = ByteStreams.newDataOutput();
        bitmap1.serialize(out1);
        bitmap2.serialize(out2);
        byte[] bytes1 = out1.toByteArray();
        byte[] bytes2 = out2.toByteArray();

        long start;
        int count;

        start = System.currentTimeMillis();
        count = 0;
        for (int j = 0; j < 1_000; j++) {
            RoaringBitmap bmp1 = new RoaringBitmap();
            bmp1.deserialize(ByteStreams.newDataInput(bytes1));
            RoaringBitmap bmp2 = new RoaringBitmap();
            bmp2.deserialize(ByteStreams.newDataInput(bytes2));

            FastAggregation.or(bmp1, bmp2);
            //FastAggregation.and(bmp1, bmp2);
            count++;
        }
        System.out.println("---- regular ----");
        System.out.println((System.currentTimeMillis() - start) + " ms, " + count + " iter");

        start = System.currentTimeMillis();
        count = 0;
        for (int j = 0; j < 1_000; j++) {
            MutableRoaringBitmap buf1 = new MutableRoaringBitmap();
            buf1.deserialize(ByteStreams.newDataInput(bytes1));
            MutableRoaringBitmap buf2 = new MutableRoaringBitmap();
            buf2.deserialize(ByteStreams.newDataInput(bytes2));

            BufferFastAggregation.or(buf1, buf2);
            //BufferFastAggregation.and(buf1, buf2);
        }
        System.out.println("---- mutable ---- "); // + buf1.getCardinality() + ", " + buf2.getCardinality());
        System.out.println((System.currentTimeMillis() - start) + " ms, " + count + " iter");

        start = System.currentTimeMillis();
        count = 0;
        for (int j = 0; j < 1_000; j++) {
            ImmutableRoaringBitmap ibuf1 = new ImmutableRoaringBitmap(ByteBuffer.wrap(bytes1));
            ImmutableRoaringBitmap ibuf2 = new ImmutableRoaringBitmap(ByteBuffer.wrap(bytes2));

            BufferFastAggregation.or(ibuf1, ibuf2);
            //BufferFastAggregation.and(ibuf1, ibuf2);
        }
        System.out.println("---- immutable ---- "); // + ibuf1.getCardinality() + ", " + ibuf2.getCardinality());
        System.out.println((System.currentTimeMillis() - start) + " ms, " + count + " iter");

    }

    /*for (int i = 0; i < 100; i++) {
            
    long start = System.currentTimeMillis();
    RoaringBitmap b1 = new RoaringBitmap();
    RoaringBitmap b2 = new RoaringBitmap();
    Random r = new Random(1234);
    for (int j = 0; j < 100_000; j++) {
        if (r.nextBoolean()) {
            b1.add(j);
        }
        if (r.nextBoolean()) {
            b2.add(j);
        }
        RoaringBitmap b3 = new RoaringBitmap();
        RoaringAggregation.or(b3, b1, b2);
    }
    System.out.println("---- regular ----");
    System.out.println((System.currentTimeMillis() - start) + " ms");
            
    start = System.currentTimeMillis();
    MutableRoaringBitmap m1 = new MutableRoaringBitmap();
    MutableRoaringBitmap m2 = new MutableRoaringBitmap();
    r = new Random(1234);
    for (int j = 0; j < 100_000; j++) {
        if (r.nextBoolean()) {
            m1.add(j);
        }
        if (r.nextBoolean()) {
            m2.add(j);
        }
        MutableRoaringBitmap m3 = BufferFastAggregation.or(m1, m2);
    }
    System.out.println("---- buffers ----");
    System.out.println((System.currentTimeMillis() - start) + " ms");
            
    }*/
}

From source file:com.minestein.novauniverse.util.bungee.ServerConnection.java

public static void connect(Player playerToSend, String serverName) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF("Connect");
    out.writeUTF(serverName);/*  w  ww.  j  a v  a 2 s .  co m*/
    playerToSend.sendPluginMessage(Main.plugin, "BungeeCord", out.toByteArray());
}

From source file:com.minestein.novacore.util.general.ServerConnection.java

/**
 * Connects the toSend player to the server via BungeeCord.
 *
 * @param toSend The player to send./*from  w w  w  .  j  av  a 2s  .c  o  m*/
 * @param server The server's display name to send the player to.
 */
public static void connect(Player toSend, String server) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF("Connect");
    out.writeUTF(server);
    toSend.sendPluginMessage(Core.plugin, "BungeeCord", out.toByteArray());
}

From source file:org.opendaylight.controller.cluster.datastore.persisted.AbortTransactionPayload.java

public static AbortTransactionPayload create(final TransactionIdentifier transactionId) throws IOException {
    final ByteArrayDataOutput out = ByteStreams.newDataOutput();
    transactionId.writeTo(out);//from  ww  w  . ja  v  a 2  s.c o  m
    return new AbortTransactionPayload(transactionId, out.toByteArray());
}

From source file:tk.playerforcehd.networklib.bungee.packets.pluginmessage.MSG_sendCommand.java

/**
 * Let's a server execute a command in his console
 *
 * @param server  the server who executes it
 * @param command the command which get executed
 *//*from  w  w  w  . j a  va  2  s.  c  o  m*/
public static void sendCommandToServer(ServerInfo server, String command) {
    ByteArrayDataOutput stream = ByteStreams.newDataOutput();
    stream.writeUTF("executeCommand");
    stream.writeUTF("Server:" + command);
    server.sendData("BungeeCord", stream.toByteArray());
}

From source file:info.minestein.compassnav.util.ServerSender.java

public static void sendToServer(Player player, String server) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();

    out.writeUTF("Connect");
    out.writeUTF(server);// w w  w  .j a va2s .c o  m

    player.sendPluginMessage(Core.plugin, "BungeeCord", out.toByteArray());
}

From source file:tk.playerforcehd.networklib.bungee.packets.pluginmessage.MSG_sendCommand.java

/**
 * Let's a player execute a command on his subserver
 *
 * @param player  the player who execute it
 * @param command the command which get executed
 *///from  ww w  .j av  a 2 s. com
public static void sendCommandToPlayer(ProxiedPlayer player, String command) {
    ByteArrayDataOutput stream = ByteStreams.newDataOutput();
    stream.writeUTF("executeCommand");
    stream.writeUTF(player.getName() + ":" + command);
    player.sendData("BungeeCord", stream.toByteArray());
}

From source file:co.cask.tigon.data.transaction.queue.hbase.DequeueScanAttributes.java

private static byte[] toBytes(Transaction tx) throws IOException {
    ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
    write(dataOutput, tx);/*from w  w w  . j  av  a  2 s  .com*/
    return dataOutput.toByteArray();
}

From source file:org.locationtech.geogig.storage.postgresql.PGId.java

public static PGId valueOf(final int h1, final long h2, final long h3) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeInt(h1);//from w  ww.  j  a va2  s  .c  o m
    out.writeLong(h2);
    out.writeLong(h3);
    byte[] raw = out.toByteArray();
    return new PGId(raw);
}

From source file:com.spleefleague.core.utils.PlayerUtil.java

public static void sendToServer(Player player, String server) {
    Bukkit.getScheduler().runTaskAsynchronously(SpleefLeague.getInstance(), () -> {
        CorePlugin.syncSaveAll(player);//from   w w w .j  a v  a  2  s.  c om
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Connect");
        out.writeUTF(server);
        player.sendPluginMessage(SpleefLeague.getInstance(), "BungeeCord", out.toByteArray());
    });
}