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:me.dobrakmato.plugins.pexel.PexelCore.actions.TeleportAction.java

@Override
public void execute(final Player player) {
    if (this.server.isLocalServer()) {
        // Just teleport player to target location.
        player.teleport(this.location);
    } else {/*  ww  w.  j a  v  a2s .  c  o m*/
        // TODO: Add teleport to location. Perform server-wide teleport

        // Teleport to other server using bungee
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Connect");
        out.writeUTF(this.server.getBungeeName());
        player.sendPluginMessage(Pexel.getCore(), "BungeeCord", out.toByteArray());
    }
}

From source file:org.elasticsoftware.elasticactors.cassandra2.serialization.CompressingSerializer.java

@Override
public ByteBuffer serialize(I object) throws IOException {
    byte[] serializedObject = delegate.serialize(object);
    if (serializedObject.length > compressionThreshold) {
        byte[] compressedBytes = lz4Compressor.compress(serializedObject);
        ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(compressedBytes.length + 8);
        dataOutput.write(MAGIC_HEADER);//from   www  .ja va  2 s.c om
        dataOutput.writeInt(serializedObject.length);
        dataOutput.write(compressedBytes);
        return ByteBuffer.wrap(dataOutput.toByteArray());
    } else {
        return ByteBuffer.wrap(serializedObject);
    }
}

From source file:org.lambda3.indra.util.VectorIterator.java

private void parseHeadline(LittleEndianDataInputStream input) throws IOException {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    byte c;/*from  w w  w . ja  v  a  2 s  . c om*/

    while ((c = input.readByte()) != '\n') {
        out.writeByte(c);
    }

    String[] headline = new String(out.toByteArray(), StandardCharsets.UTF_8).split(" ");
    this.numberOfVectors = Integer.parseInt(headline[0]);
    this.dimensions = Integer.parseInt(headline[1]);
}

From source file:de.bl4ckskull666.mu1ti1ingu41.listener.PlayerJoin.java

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerJoin(PlayerJoinEvent e) {
    if (!(Mu1ti1ingu41.getPlugin().getConfig().getBoolean("use-bungeecord", false)
            && Bukkit.getVersion().toLowerCase().contains("spigot"))) {
        if (!UUIDLanguages._players.containsKey(e.getPlayer().getUniqueId())) {
            Language.setPlayerLanguage(e.getPlayer().getUniqueId());
            e.getPlayer().sendMessage(Language.getText(Mu1ti1ingu41.getPlugin(), e.getPlayer().getUniqueId(),
                    "auto-language", "Set your language to %language%", new String[] { "%language%" },
                    new String[] {
                            getLanguageName(UUIDLanguages.getPlayerLanguage(e.getPlayer().getUniqueId())) }));
        }//from ww  w . j a  v  a 2s  .co  m
    } else {
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Mu1ti1ingu41");
        out.writeUTF(e.getPlayer().getUniqueId().toString());
        Mu1ti1ingu41.getPlugin().getServer().sendPluginMessage(Mu1ti1ingu41.getPlugin(), "BungeeCord",
                out.toByteArray());
    }
}

From source file:org.lambda3.indra.util.VectorIterator.java

private void setCurrentContent() throws IOException {
    if (numberOfVectors > 0) {
        numberOfVectors--;//from  w w  w . j a v  a 2  s.  c  o  m

        ByteArrayDataOutput out = ByteStreams.newDataOutput();

        byte b;
        while ((b = input.readByte()) != ' ') {
            out.writeByte(b);
        }

        String word = new String(out.toByteArray(), StandardCharsets.UTF_8);
        if (this.sparse) {
            this.currentVector = new TermVector(true, word, readSparseVector(this.dimensions));
        } else {
            this.currentVector = new TermVector(false, word, readDenseVector(this.dimensions));
        }

    } else {
        this.currentVector = null;
    }
}

From source file:org.apache.eagle.log.entity.filter.TypedByteArrayComparator.java

/**
 * For hbase 0.98//from  www .jav a  2 s.  c  o  m
 *
 * @return serialized byte array
 */
@Override
public byte[] toByteArray() {
    ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput();
    try {
        this.write(byteArrayDataOutput);
        return byteArrayDataOutput.toByteArray();
    } catch (IOException e) {
        LOG.error("Failed to serialize due to: " + e.getMessage(), e);
        throw new RuntimeException(e);
    }
}

From source file:com.galois.qrstream.qrpipe.DecodedMessage.java

/**
 * Returns the whole transmitted message whenever it is available, otherwise
 * it returns an empty message to indicate only partial message received.
 *///  w w  w.  java 2 s  . c o  m
public byte[] getEntireMessage() {
    if (receivedData.isEmpty() || (decodeState.getState() != State.Final)) {
        return new byte[0];
    }

    // Assemble message in order, we assume key are sorted
    ByteArrayDataOutput bstream = ByteStreams.newDataOutput();
    for (Entry<Integer, PartialMessage> entry : receivedData.entrySet()) {
        bstream.write(entry.getValue().getPayload());
    }
    return bstream.toByteArray();
}

From source file:org.xdi.oxauth.service.fido.u2f.RawRegistrationService.java

private byte[] packBytesToSign(byte[] appIdHash, byte[] clientDataHash, byte[] keyHandle,
        byte[] userPublicKey) {
    ByteArrayDataOutput encoded = ByteStreams.newDataOutput();
    encoded.write(REGISTRATION_SIGNED_RESERVED_BYTE_VALUE);
    encoded.write(appIdHash);//from   w ww.ja v  a  2  s  .c  om
    encoded.write(clientDataHash);
    encoded.write(keyHandle);
    encoded.write(userPublicKey);

    return encoded.toByteArray();
}

From source file:org.locationtech.geogig.model.internal.RocksdbDAGStore.java

private byte[] encode(DAG bucketDAG) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    try {/*from   ww w . java2s. co m*/
        DAG.serialize(bucketDAG, out);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    return out.toByteArray();
}

From source file:net.nifheim.beelzebu.coins.bukkit.utils.bungee.PluginMessage.java

public void sendToBungeeCord(String channel, String message) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF(channel);//from w  ww .ja va  2s  . c  o m
    out.writeUTF(message);
    Player p = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
    if (p != null) {
        p.sendPluginMessage(Main.getInstance(), "Coins", out.toByteArray());
    }
}